Skip to content

Commit

Permalink
get sub_org from request if not found (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
marslanabdulrauf authored Dec 7, 2022
1 parent e119586 commit dae7e3c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions openedx/features/edly/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ def get_enabled_organizations(request):
return studio_site_edx_organizations.values()


def get_edly_sub_org_from_request(request):
"""
Helper method to get edly sub organization from request object.
Returns:
EdlySubOrg: edly_sub_org object
"""
try:
edly_sub_org = request.site.edly_sub_org_for_lms
except EdlySubOrganization.DoesNotExist:
edly_sub_org = request.site.edly_sub_org_for_studio

return edly_sub_org

def create_user_link_with_edly_sub_organization(request, user):
"""
Create edly user profile link with edly sub organization.
Expand All @@ -173,10 +187,7 @@ def create_user_link_with_edly_sub_organization(request, user):
object: EdlyUserProfile object.
"""
try:
edly_sub_org = request.site.edly_sub_org_for_lms
except EdlySubOrganization.DoesNotExist:
edly_sub_org = request.site.edly_sub_org_for_studio
edly_sub_org = get_edly_sub_org_from_request(request)
edly_user_profile, __ = EdlyUserProfile.objects.get_or_create(user=user)
edly_user_profile.edly_sub_organizations.add(edly_sub_org)
edly_user_profile.save()
Expand Down Expand Up @@ -225,6 +236,10 @@ def set_global_course_creator_status(request, user, set_global_creator):
edly_user_info_cookie = request.COOKIES.get(settings.EDLY_USER_INFO_COOKIE_NAME, None)
edx_orgs = get_edx_org_from_cookie(edly_user_info_cookie)

if not edx_orgs:
edx_orgs = get_edly_sub_org_from_request(request)
edx_orgs = [edx_orgs.slug]

for edx_org in edx_orgs:
if set_global_creator:
GlobalCourseCreatorRole(edx_org).add_users(user)
Expand Down

0 comments on commit dae7e3c

Please sign in to comment.