Skip to content

Commit

Permalink
Merge pull request #2220 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
Merge dev to dev-server
  • Loading branch information
jelanmathewjames authored Aug 30, 2024
2 parents cb6e88a + 3351130 commit b4242c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
4 changes: 1 addition & 3 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,14 @@ def create_karma_activity_log(task_hashtag, karma_value):
return super().update(instance, validated_data)

class UserTermSerializer(serializers.ModelSerializer):
is_userterms_approved = serializers.SerializerMethodField()


class Meta:
model = UserSettings
fields =[
"is_userterms_approved",
"user",
]
def get_userterm(self, instance, validated_data):
def update(self, instance, validated_data):
instance.is_userterms_approved = validated_data.get('is_userterms_approved', instance.is_userterms_approved)
instance.save()
return instance
46 changes: 28 additions & 18 deletions api/dashboard/profile/profile_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,16 @@ def get(self, request, muid):
).get_failure_response()

class UsertermAPI(APIView):
def post(self, request,muid):
user = User.objects.get(muid=muid)
def post(self, request, muid):
try:
user = User.objects.get(muid=muid)
except User.DoesNotExist:
return CustomResponse(response="The user does not exist").get_failure_response()

try:
settings = UserSettings.objects.get(user=user)
except UserSettings.DoesNotExist:
return CustomResponse(response="The user setting doesn't exists").get_failure_response()
return CustomResponse(response="The user settings don't exist").get_failure_response()

serializer = UserTermSerializer(settings, data={"is_userterms_approved": True}, partial=True)
if serializer.is_valid():
Expand All @@ -453,18 +457,24 @@ def post(self, request,muid):
response_data = {"message": "User terms have been successfully approved."}
return CustomResponse(response=response_data).get_success_response()
else:
return CustomResponse(response="The given muid seems to be invalid").get_failure_response()
return CustomResponse(response="Invalid data provided.").get_failure_response()

def get(self,request,muid):
user = User.objects.get(muid=muid)
try:
settings = UserSettings.objects.get(user=user)
except UserSettings.DoesNotExist:
return CustomResponse(response="The user settings doesn't exists").get_failure_response()
if settings.is_userterms_approved:
response_data = {"message": "User terms are approved."}
return CustomResponse(response=response_data).get_success_response()
else:
response_data = {"message": "User terms are not approved."}
return CustomResponse(response=response_data).get_failure_response()
response_data = {"message": "The user terms have not been successfully approved."}
return CustomResponse(response=response_data).get_failure_response()
return CustomResponse(response="Invalid data provided").get_failure_response()

def get(self, request, muid):
try:
user = User.objects.get(muid=muid)
except User.DoesNotExist:
return CustomResponse(response="The user does not exist").get_failure_response()

try:
settings = UserSettings.objects.get(user=user)
except UserSettings.DoesNotExist:
return CustomResponse(response="The user settings don't exist").get_failure_response()

if settings.is_userterms_approved:
response_data = {"message": "User terms are approved."}
return CustomResponse(response=response_data).get_success_response()
else:
response_data = {"message": "User terms are not approved."}
return CustomResponse(response=response_data).get_failure_response()

0 comments on commit b4242c8

Please sign in to comment.