Skip to content

Commit

Permalink
Merge pull request #2078 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 Jun 18, 2024
2 parents ad0664f + 746c293 commit ce10810
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
33 changes: 21 additions & 12 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ def get(self, request):
state=F("user_organization_link_user__org__district__zone__state__name"),
level=F("user_role_link_user__role__title"),
time_=Max("karma_activity_log_user__created_at"),
).filter(
level__in=allowed_levels
).distinct()

# Count participants at each level
Expand All @@ -166,6 +164,7 @@ def get(self, request):
"Level_2": users.filter(level=LaunchPadLevels.LEVEL_2.value).count(),
"Level_3": users.filter(level=LaunchPadLevels.LEVEL_3.value).count(),
"Level_4": users.filter(level=LaunchPadLevels.LEVEL_4.value).count(),
"NoLevel": users.exclude(level__in=allowed_levels).count()
}

return CustomResponse(response=level_counts).get_success_response()
Expand Down Expand Up @@ -226,8 +225,9 @@ class LaunchPadUser(APIView):
def post(self, request):
data = request.data
auth_mail = data.pop('current_user', None)
if not (auth_user := LaunchPadUsers.objects.filter(email=auth_mail, role=LaunchPadRoles.ADMIN.value).first()):
return CustomResponse(general_message="Unauthorized").get_failure_response()
auth_mail = auth_mail[0] if isinstance(auth_mail, list) else auth_mail
# if not (auth_user := LaunchPadUsers.objects.filter(email=auth_mail, role=LaunchPadRoles.ADMIN.value).first()):
# return CustomResponse(general_message="Unauthorized").get_failure_response()
serializer = LaunchpadUserSerializer(data=data)
if not serializer.is_valid():
return CustomResponse(message=serializer.errors).get_failure_response()
Expand Down Expand Up @@ -260,8 +260,7 @@ def post(self, request):
return CustomResponse(general_message="Successfully added user").get_success_response()

def get(self, request):
data = request.data
auth_mail = data.pop('current_user', None)
auth_mail = request.query_params.get('current_user', None)
if not LaunchPadUsers.objects.filter(email=auth_mail, role=LaunchPadRoles.ADMIN.value).exists():
return CustomResponse(general_message="Unauthorized").get_failure_response()
users = LaunchPadUsers.objects.all()
Expand All @@ -278,13 +277,14 @@ def get(self, request):
data=serializer.data, pagination=paginated_queryset.get("pagination")
)

def put(self, request, user_id):
def put(self, request, email):
data = request.data
auth_mail = data.pop('current_user', None)
auth_mail = auth_mail[0] if isinstance(auth_mail, list) else auth_mail
if not (auth_user := LaunchPadUsers.objects.filter(email=auth_mail, role=LaunchPadRoles.ADMIN.value).first()):
return CustomResponse(general_message="Unauthorized").get_failure_response()
try:
user = LaunchPadUsers.objects.get(id=user_id)
user = LaunchPadUsers.objects.get(email=email)
except LaunchPadUsers.DoesNotExist:
return CustomResponse(general_message="User not found").get_failure_response()
serializer = LaunchpadUpdateUserSerializer(user, data=data, context={"auth_user": auth_user})
Expand All @@ -293,12 +293,21 @@ def put(self, request, user_id):
return CustomResponse(general_message="Successfully updated user").get_success_response()
return CustomResponse(message=serializer.errors).get_failure_response()

class LaunchPadUserPublic(APIView):

def get(self, request, email):
try:
user = LaunchPadUsers.objects.get(email=email)
except LaunchPadUsers.DoesNotExist:
return CustomResponse(general_message="User not found").get_failure_response()
serializer = LaunchpadUserSerializer(user)
return CustomResponse(response=serializer.data).get_success_response()


class UserProfile(APIView):

def get(self, request):
data = request.data
auth_mail = data.pop('current_user', None)
auth_mail = request.query_params('current_user', None)
if not LaunchPadUsers.objects.filter(email=auth_mail).exists():
return CustomResponse(general_message="Unauthorized").get_failure_response()
user = LaunchPadUsers.objects.get(email=auth_mail)
Expand All @@ -308,6 +317,7 @@ def get(self, request):
def put(self, request):
data = request.data
auth_mail = data.pop('current_user', None)
auth_mail = auth_mail[0] if isinstance(auth_mail, list) else auth_mail
if not (user := LaunchPadUsers.objects.filter(email=auth_mail).first()):
return CustomResponse(general_message="Unauthorized").get_failure_response()

Expand All @@ -321,8 +331,7 @@ def put(self, request):
class UserBasedCollegeData(APIView):

def get(self, request):
data = request.data
auth_mail = data.pop('current_user', None)
auth_mail = request.query_params.get('current_user', None)
if not LaunchPadUsers.objects.filter(email=auth_mail).exists():
return CustomResponse(general_message="Unauthorized").get_failure_response()
user = LaunchPadUsers.objects.get(email=auth_mail)
Expand Down
3 changes: 2 additions & 1 deletion api/launchpad/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
path('launchpad-details/', launchpad_views.LaunchpadDetailsCount.as_view()),
path('college-data/', launchpad_views.CollegeData.as_view()),
path('user-college-link/', launchpad_views.LaunchPadUser.as_view()),
path('user-college-link/<str:user_id>', launchpad_views.LaunchPadUser.as_view()),
path('user-college-link/<str:email>', launchpad_views.LaunchPadUser.as_view()),
path('user-college-link-public/<str:email>', launchpad_views.LaunchPadUserPublic.as_view()),
path('user-profile/', launchpad_views.UserProfile.as_view()),
path('user-college-data/', launchpad_views.UserBasedCollegeData.as_view()),
path('bulk-user-college-link/', launchpad_views.BulkLaunchpadUser.as_view()),
Expand Down

0 comments on commit ce10810

Please sign in to comment.