Skip to content

Commit 3ab9d35

Browse files
committed
Added custom "change" action to the profile view
This allows learners who did not put their name on their Github profile to provide us with their first and last name before accessing the LP main dashboard
1 parent b8c6c3d commit 3ab9d35

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

LearningAPI/views/cohort_info.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from django.db.models import Count, Q
2-
from django.db import IntegrityError
1+
"""View module for handling requests about cohort info"""
32
from django.http import HttpResponseServerError
43
from rest_framework import serializers, status
5-
from rest_framework import permissions
6-
from rest_framework.decorators import action
74
from rest_framework.response import Response
85
from rest_framework.viewsets import ViewSet
9-
from LearningAPI.models.people import Cohort, NssUser, CohortInfo
6+
from LearningAPI.models.people import Cohort, CohortInfo
107

118

129
class CohortInfoViewSet(ViewSet):

LearningAPI/views/profile.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""View module for handling requests about park areas"""
22
import logging
3+
from rest_framework.decorators import action
34
from rest_framework import serializers, status
45
from rest_framework.viewsets import ViewSet
56
from rest_framework.response import Response
@@ -8,19 +9,39 @@
89
from LearningAPI.utils import GithubRequest
910
from LearningAPI.models.people import Cohort, NssUserCohort, NssUser
1011
from LearningAPI.models.coursework import StudentProject
11-
from LearningAPI.models.people.student_personality import StudentPersonality
1212

1313

1414
class Profile(ViewSet):
1515
"""Person can see profile information"""
1616

17+
@action(detail=False, methods=['put'])
18+
def change(self, request):
19+
"""Handle PUT requests to profile resource
20+
21+
Returns:
22+
Response -- None
23+
"""
24+
first = request.data.get("firstName", None)
25+
last = request.data.get("lastName", None)
26+
27+
if first is not None and last is not None:
28+
request.auth.user.first_name = first
29+
request.auth.user.last_name = last
30+
31+
request.auth.user.save()
32+
33+
return Response(None, status=status.HTTP_204_NO_CONTENT)
34+
35+
return Response({'message': 'You must provide a \'firstName\' and \'lastName\' in the request body'}, status=status.HTTP_400_BAD_REQUEST)
36+
37+
38+
1739
def list(self, request):
1840
"""Handle GET requests to profile resource
1941
2042
Returns:
2143
Response -- JSON representation of user info
2244
"""
23-
personality = {}
2445
cohort = self.request.query_params.get('cohort', None)
2546
mimic = self.request.query_params.get('mimic', None)
2647

@@ -74,7 +95,9 @@ def list(self, request):
7495

7596

7697
if not request.auth.user.is_staff or mimic:
98+
# Check to see if the learner has accepted the invitation to join the cohort Github organization
7799
student_cohort = nss_user.assigned_cohorts.first()
100+
78101
if not student_cohort.is_github_org_member:
79102
# Send a request to the Github API to check the membership status of the user for the cohort Github organization
80103
gh_request = GithubRequest()
@@ -90,7 +113,13 @@ def list(self, request):
90113
github_org_membership_status = "active"
91114

92115

93-
serializer = ProfileSerializer(nss_user, context={'request': request, 'github_status': github_org_membership_status})
116+
serializer = ProfileSerializer(
117+
nss_user,
118+
context={
119+
'request': request,
120+
'github_status': github_org_membership_status
121+
}
122+
)
94123
return Response(serializer.data, status=status.HTTP_200_OK)
95124
else:
96125
# Create custom JSON response for instructors

learopsdev.session.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ select * from pg_catalog.pg_tables;
44

55

66
select * from "auth_user" order by id desc;
7+
select * from "socialaccount_socialaccount" order by id desc;
78
select * from "authtoken_token" where user_id = 470;
9+
select * from "LearningAPI_nssuser" where user_id = 470;
10+
select * from "LearningAPI_nssusercohort" where nss_user_id = 468;
11+
update "LearningAPI_nssusercohort"
12+
set is_github_org_member = FALSE
13+
where nss_user_id = 468;
14+
815

916
-- Drop all tables
1017
DO $$ DECLARE

0 commit comments

Comments
 (0)