Skip to content

Commit

Permalink
quality format solved
Browse files Browse the repository at this point in the history
  • Loading branch information
lkatsikaris committed Apr 29, 2024
1 parent da7726d commit c959b95
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 36 deletions.
2 changes: 1 addition & 1 deletion panorama_openedx_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django app that implements backend functions for Panorama MFE
Django app that implements backend functions for Panorama MFE.
"""

__version__ = '0.1.0'
4 changes: 4 additions & 0 deletions panorama_openedx_backend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@


class DashboardAdmin(admin.ModelAdmin):
"""
Dashboard admin class.
"""

list_display = [
"priority",
"dashboard_id",
Expand Down
46 changes: 30 additions & 16 deletions panorama_openedx_backend/api/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from django.conf import settings
import json
"""
panorama_openedx_backend Django application views.
"""

import boto3
from panorama_openedx_backend.utils import has_access_to_panorama, get_user_dashboards, get_user_arn, get_user_role
from django.conf import settings
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView

from panorama_openedx_backend.utils import get_user_arn, get_user_dashboards, get_user_role, has_access_to_panorama


class GetDashboardEmbedUrl(APIView):
"""
get dashboard embed url class
"""
permission_classes = (IsAuthenticated,)

def get(self, request):
"""
get dashboard embed url function
"""
session = boto3.Session(
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY
Expand All @@ -22,29 +33,25 @@ def get(self, request):

user = request.user

user_meta = json.loads(user.profile.meta)

# user_meta = json.loads(user.profile.meta)

# CHECKING IF USER HAS A ARN SET
quicksightARN = get_user_arn(user)
if not quicksightARN:
raise ValueError('Error 403 - Forbidden')


# CHECKING IF USER HAS A DASHBOARD TYPE SET
dashboards_of_user = get_user_dashboards(user)
if not dashboards_of_user:
raise ValueError('Error 404 - Dashboard not assigned')


# CHECKING IF USER HAS A ROLE SET
user_role = get_user_role(user)
if not user_role:
raise ValueError('Error 404 - User role not assigned')

dashboard_function = request.GET.get("dashboard_function")


for dashboard in dashboards_of_user:

# SETTING EXPERIENCE CONFIG ACCORDING TO USER ROLE
Expand All @@ -66,15 +73,16 @@ def get(self, request):
},
}
}

if dashboard_function == "AI_AUTHOR":
experience_config = {
'QSearchBar': {
'QSearchBar': {
'InitialTopicId': "CVomHyE9Wf06YnPHcaFom4IFRSV2eAVv"
},
}

response = quicksight.generate_embed_url_for_registered_user(
AllowedDomains=[f"*.{settings.LMS_BASE}"],
AwsAccountId=settings.PANORAMA_AWS_ACCOUNT_ID,
SessionLifetimeInMinutes=123,
UserArn=quicksightARN,
Expand All @@ -89,7 +97,9 @@ def get(self, request):


class GetUserAccess(APIView):

"""
get user access class
"""
permission_classes = (IsAuthenticated,)

def get(self, request):
Expand All @@ -99,13 +109,17 @@ def get(self, request):
'body': has_access_to_panorama(request.user)
})


class GetUserRole(APIView):
"""
get user role class
"""

permission_classes = (IsAuthenticated,)

def get(self, request):

return Response({
'statusCode': 200,
'body': get_user_role(request.user)
})
'body': get_user_role(request.user),
})
4 changes: 3 additions & 1 deletion panorama_openedx_backend/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
panorama_openedx_backend Django application initialization.
"""

from django.apps import AppConfig
import logging

from django.apps import AppConfig

logger = logging.getLogger(__name__)


class PanoramaOpenedxBackendConfig(AppConfig):
"""
Configuration for the panorama_openedx_backend Django application.
Expand Down
10 changes: 5 additions & 5 deletions panorama_openedx_backend/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Database models for panorama_openedx_backend.
"""
from django.db import models
from model_utils.models import TimeStampedModel
from django.contrib.auth import get_user_model
from django.db import models
from django.utils.translation import gettext as _
from model_utils.models import TimeStampedModel

User = get_user_model()

Expand All @@ -17,7 +17,7 @@

class Dashboard(TimeStampedModel):
"""
.. no_pii:
.. no_pii:.
"""

dashboard_id = models.CharField(
Expand Down Expand Up @@ -62,7 +62,7 @@ def __str__(self):

class DashboardType(TimeStampedModel):
"""
.. no_pii:
.. no_pii:.
"""

name = models.CharField(
Expand All @@ -85,7 +85,7 @@ def __str__(self):

class UserAccessConfiguration(TimeStampedModel):
"""
.. no_pii:
.. no_pii:.
"""

user = models.OneToOneField(
Expand Down
5 changes: 2 additions & 3 deletions panorama_openedx_backend/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def plugin_settings(settings):
"""
Inject local settings into django settings.
"""

print(settings)
# settings.EXAMPLE = value
pass

# pass
2 changes: 1 addition & 1 deletion panorama_openedx_backend/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
URLs for panorama_openedx_backend.
"""
from django.urls import re_path # pylint: disable=unused-import
from django.urls import re_path

from panorama_openedx_backend.api.views import GetDashboardEmbedUrl, GetUserAccess, GetUserRole

Expand Down
22 changes: 13 additions & 9 deletions panorama_openedx_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,49 @@
"""

from django.contrib.auth import get_user_model

from .models import UserAccessConfiguration

User = get_user_model()


def has_access_to_panorama(user: User) -> bool:
"""
Returns true if the user can access Panorama, i.e., if there is a record in the
user access configuration model.
"""
Has access to panorama function.
Return true if the user can access Panorama, i.e., if there is a record in the user access configuration model.
"""
return UserAccessConfiguration.objects.filter(user=user).exists()


def get_user_role(user: User) -> str:
"""
Get the Panorama user role
"""
Get user role function.
Get the Panorama user role.
"""
user_access_configuration = UserAccessConfiguration.objects.get(user=user)

return user_access_configuration.role


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

return user_access_configuration.arn


def get_user_dashboards(user: User) -> list:
"""
Get the list of user dashboards to import
"""
Get user dashboards function.
Get the list of user dashboards to import.
"""
user_access_configuration = UserAccessConfiguration.objects.get(user=user)
dashboard_type = user_access_configuration.dashboard_type

Expand Down
107 changes: 107 additions & 0 deletions pii_report/2024-29-04-08-40-27.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
.annotation_safe_list.yml:
- annotation_data: This model has no PII
annotation_token: '.. no_pii:'
extra:
full_comment: '{''.. no_pii:'': ''This model has no PII''}'
object_id: contenttypes.ContentType
filename: .annotation_safe_list.yml
found_by: safelist
line_number: 0
report_group_id: 1
- annotation_data: This model has no PII
annotation_token: '.. no_pii:'
extra:
full_comment: '{''.. no_pii:'': ''This model has no PII''}'
object_id: auth.Group
filename: .annotation_safe_list.yml
found_by: safelist
line_number: 0
report_group_id: 2
- annotation_data: This model has no PII
annotation_token: '.. no_pii:'
extra:
full_comment: '{''.. no_pii:'': ''This model has no PII''}'
object_id: auth.Permission
filename: .annotation_safe_list.yml
found_by: safelist
line_number: 0
report_group_id: 3
- annotation_data: This model has no PII
annotation_token: '.. no_pii:'
extra:
full_comment: '{''.. no_pii:'': ''This model has no PII''}'
object_id: admin.LogEntry
filename: .annotation_safe_list.yml
found_by: safelist
line_number: 0
report_group_id: 4
- annotation_data: This model minimally contains a username, password, and email
annotation_token: .. pii
extra:
full_comment: '{''.. pii'': ''This model minimally contains a username, password,
and email'', ''.. pii_types'': ''username, email_address, password'', ''.. pii_retirement'':
''consumer_api''}'
object_id: auth.User
filename: .annotation_safe_list.yml
found_by: safelist
line_number: 0
report_group_id: 5
- annotation_data: username, email_address, password
annotation_token: .. pii_types
extra:
full_comment: '{''.. pii'': ''This model minimally contains a username, password,
and email'', ''.. pii_types'': ''username, email_address, password'', ''.. pii_retirement'':
''consumer_api''}'
object_id: auth.User
filename: .annotation_safe_list.yml
found_by: safelist
line_number: 0
report_group_id: 5
- annotation_data: consumer_api
annotation_token: .. pii_retirement
extra:
full_comment: '{''.. pii'': ''This model minimally contains a username, password,
and email'', ''.. pii_types'': ''username, email_address, password'', ''.. pii_retirement'':
''consumer_api''}'
object_id: auth.User
filename: .annotation_safe_list.yml
found_by: safelist
line_number: 0
report_group_id: 5
- annotation_data: This model has no PII
annotation_token: '.. no_pii:'
extra:
full_comment: '{''.. no_pii:'': ''This model has no PII''}'
object_id: sessions.Session
filename: .annotation_safe_list.yml
found_by: safelist
line_number: 0
report_group_id: 6
/home/leonelkatsikaris/Workspace/panorama-openedx-backend/panorama_openedx_backend/models.py:
- annotation_data: .
annotation_token: '.. no_pii:'
extra:
full_comment: .. no_pii:.
object_id: panorama_openedx_backend.DashboardType
filename: /home/leonelkatsikaris/Workspace/panorama-openedx-backend/panorama_openedx_backend/models.py
found_by: django
line_number: 63
report_group_id: 7
- annotation_data: .
annotation_token: '.. no_pii:'
extra:
full_comment: .. no_pii:.
object_id: panorama_openedx_backend.UserAccessConfiguration
filename: /home/leonelkatsikaris/Workspace/panorama-openedx-backend/panorama_openedx_backend/models.py
found_by: django
line_number: 86
report_group_id: 8
- annotation_data: .
annotation_token: '.. no_pii:'
extra:
full_comment: .. no_pii:.
object_id: panorama_openedx_backend.Dashboard
filename: /home/leonelkatsikaris/Workspace/panorama-openedx-backend/panorama_openedx_backend/models.py
found_by: django
line_number: 18
report_group_id: 9
Empty file removed tests/__init__.py
Empty file.

0 comments on commit c959b95

Please sign in to comment.