forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permissions.py
37 lines (26 loc) · 1.31 KB
/
permissions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from django.utils.translation import gettext_lazy as _
from authorization.permissions import Permission, ObjectVisibleBasePermission
from .models import MenuItem, LTIService, LTI1p3Service
class MenuVisiblePermission(ObjectVisibleBasePermission):
message = _('MENU_VISIBILTY_PERMISSION_DENIED_MSG')
model = MenuItem
obj_var = 'menu_item'
def is_object_visible(self, request, view, menu_item): # pylint: disable=arguments-renamed
if (not menu_item.enabled
or (menu_item.service and not menu_item.service.enabled)):
return False
if menu_item.access >= MenuItem.ACCESS.TEACHER:
if not view.is_teacher:
self.error_msg(_('MENU_VISIBILITY_ERROR_ONLY_TEACHERS'))
return False
elif menu_item.access >= MenuItem.ACCESS.ASSISTANT:
if not view.is_course_staff:
self.error_msg(_('MENU_VISIBILITY_ERROR_ONLY_COURSE_STAFF'))
return False
return True
class LTIServicePermission(Permission):
message = _('NOT_LTI_SERVICE')
def has_permission(self, request, view):
return self.has_object_permission(request, view, view.menu_item)
def has_object_permission(self, request, view, obj):
return obj.service and isinstance(obj.service, (LTIService, LTI1p3Service))