Skip to content

Commit

Permalink
fix: Manage unexistent user access configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
angonz committed Jun 11, 2024
1 parent d14644f commit 1bcf56c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ Change Log
This project adheres to Semantic Versioning (https://semver.org/).

.. There should always be an "Version 16.0.3 (2024-06-05)" section for changes pending release.
.. There should always be an "Unreleased (2024-06-05)" section for changes pending release.
Unreleased
**********

* Manage nonexistent user access configuration

Version 16.0.8 (2024-06-11)
**********
Expand Down
27 changes: 17 additions & 10 deletions panorama_openedx_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,37 @@ def get_user_role(user: User) -> str:
In DEMO mode, the backend may not be initialized so superusers have READ access.
"""
if panorama_mode() in ['DEMO', 'FREE']:
return "READER" if user.is_superuser else None
role = "READER" if user.is_superuser else None
else:
user_access_configuration = UserAccessConfiguration.objects.get(user=user)
try:
user_access_configuration = UserAccessConfiguration.objects.get(user=user)
role = user_access_configuration.role
except UserAccessConfiguration.DoesNotExist:
role = "READER" if user.is_superuser else "STUDENT"

if user_access_configuration:
return user_access_configuration.role
else:
return "READER" if user.is_superuser else "STUDENT"
return role


def get_user_arn(user: User) -> str:
"""
Get the AWS user ARN mapping to this user.
"""
user_access_configuration = UserAccessConfiguration.objects.get(user=user)

return user_access_configuration.arn or settings["PANORAMA_DEFAULT_USER_ARN"]
try:
user_access_configuration = UserAccessConfiguration.objects.get(user=user)
return user_access_configuration.arn
except UserAccessConfiguration.DoesNotExist:
settings["PANORAMA_DEFAULT_USER_ARN"]


def get_user_dashboards(user: User) -> list:
"""
Get the list of user dashboards to import from the Django admin configuration.
"""
user_access_configuration = UserAccessConfiguration.objects.get(user=user)
try:
user_access_configuration = UserAccessConfiguration.objects.get(user=user)
except UserAccessConfiguration.DoesNotExist:
return []

dashboard_type = user_access_configuration.dashboard_type

dashboard_list = []
Expand Down

0 comments on commit 1bcf56c

Please sign in to comment.