Skip to content

Commit

Permalink
feat: add base and learner portal bff handler
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Nov 1, 2024
1 parent 2e90854 commit b0a595d
Show file tree
Hide file tree
Showing 4 changed files with 539 additions and 20 deletions.
20 changes: 20 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,23 @@ 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_customer_uuid = (
self.request.query_params.get('enterprise_customer_uuid', {}) or
self.request.data.get('enterprise_customer_uuid', {})
)
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
if hasattr(self.user, 'lms_user_id'):
self.lms_user_id = self.user.lms_user_id

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

0 comments on commit b0a595d

Please sign in to comment.