Skip to content

Commit

Permalink
Added update user details API
Browse files Browse the repository at this point in the history
  • Loading branch information
manojp3 committed Jul 12, 2024
1 parent dc867fc commit 02b662b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from openedx.core.djangoapps.password_policy.forms import PasswordPolicyAwareAdminAuthForm
from openedx.core import toggles as core_toggles

from common.djangoapps.student.views.management import extras_course_enroll_user
from common.djangoapps.student.views.management import extras_course_enroll_user, extras_update_user_details
from cms.djangoapps.contentstore.views.course import extras_create_course
from cms.djangoapps.contentstore.views.course import extras_get_moodle_login_url

Expand Down Expand Up @@ -194,6 +194,7 @@

re_path(r'^extras/create_course', extras_create_course, name = 'extras_create_course'),
re_path(r'^extras/course_enroll_user', extras_course_enroll_user, name = 'extras_course_enroll_user'),
re_path(r'^extras/update_user_details', extras_update_user_details, name = 'extras_update_user_details'),
re_path(r'^extras/get_moodle_login_url', extras_get_moodle_login_url, name = 'extras_get_moodle_login_url'),

path('api/val/v0/', include('edxval.urls')),
Expand Down
31 changes: 30 additions & 1 deletion common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,4 +1354,33 @@ def _get_active_inactive_courses(user):
user_active_inactive_courses.update({user_course["course_details"]["course_id"] : "Active"})
else:
user_active_inactive_courses.update({user_course["course_details"]["course_id"] : "Dropped"})
return user_active_inactive_courses
return user_active_inactive_courses

@csrf_exempt
def extras_update_user_details(request):
data = json.loads(request.body)
log.info(data)
try:
oldEmail = data["other"]["email"]
firstName = data["other"]["firstname"]
lastName = data["other"]["lastname"]
newEmail = data["other"]["newemail"]
old_user = User.objects.get(email = oldEmail)

except ObjectDoesNotExist:
return HttpResponse("User doesn't exists")
if newEmail and newEmail != oldEmail:
try:
new_user = User.objects.get(email = newEmail)
if new_user:
return HttpResponse("User already exists with new email.")
except ObjectDoesNotExist:
old_user.email = newEmail

#update firstname lastname if email not passed
if firstName is not None:
old_user.first_name = firstName
if lastName is not None:
old_user.last_name = lastName
old_user.save()
return HttpResponse("Saved")

0 comments on commit 02b662b

Please sign in to comment.