Skip to content

Commit

Permalink
feat: add base and learner portal bff handler (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 authored Nov 6, 2024
1 parent 173fc9a commit 2ee4466
Show file tree
Hide file tree
Showing 4 changed files with 592 additions and 32 deletions.
21 changes: 21 additions & 0 deletions enterprise_access/apps/bffs/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __init__(self, request):
self.enterprise_customer_uuid = None
self.lms_user_id = None

# Set common context attributes
self.initialize_common_context_data()

@property
def request(self):
return self._request
Expand All @@ -40,6 +43,24 @@ def request(self):
def user(self):
return self._request.user

def initialize_common_context_data(self):
"""
Initialize commonly used context attributes, such as enterprise customer UUID and LMS user ID.
"""
enterprise_uuid_query_param = self.request.query_params.get('enterprise_customer_uuid')
enterprise_uuid_post_param = None
if self.request.method == 'POST':
enterprise_uuid_post_param = self.request.data.get('enterprise_customer_uuid')

enterprise_customer_uuid = enterprise_uuid_query_param or enterprise_uuid_post_param
if enterprise_customer_uuid:
self.enterprise_customer_uuid = enterprise_customer_uuid
else:
raise ValueError("enterprise_customer_uuid is required for this request.")

# Set lms_user_id from the authenticated user object in the request
self.lms_user_id = getattr(self.user, 'lms_user_id', None)

def add_error(self, **kwargs):
"""
Adds an error to the context.
Expand Down
Loading

0 comments on commit 2ee4466

Please sign in to comment.