Skip to content

Commit

Permalink
Merge branch 'randomz' into 'development'
Browse files Browse the repository at this point in the history
feat: randomz

Closes #41

See merge request nofusscomputing/projects/django_template!16
  • Loading branch information
jon-nfc committed Jun 1, 2024
2 parents 776c5db + f41282d commit 64f4c8f
Show file tree
Hide file tree
Showing 22 changed files with 2,354 additions and 220 deletions.
28 changes: 19 additions & 9 deletions app/access/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.core.exceptions import PermissionDenied
from django.utils.functional import cached_property



from .models import Team


Expand All @@ -20,15 +22,19 @@ def object_organization(self) -> int:

try:

self.get_queryset()
if hasattr(self, 'get_queryset'):
self.get_queryset()


self.get_object()
if hasattr(self, 'get_object'):
self.get_object()

id = self.get_object().get_organization().id
id = self.get_object().get_organization().id

if self.get_object().is_global:
if self.get_object().is_global:

id = 0

id = 0

except AttributeError:

Expand Down Expand Up @@ -117,11 +123,15 @@ def user_organizations(self) -> list():


# ToDo: Ensure that the group has access to item
def has_permission(self) -> bool:
def has_organization_permission(self, organization=None) -> bool:

has_permission = False

if self.is_member(self.object_organization()) or self.object_organization() == 0:
if not organization:

organization = self.object_organization()

if self.is_member(organization) or organization == 0:

groups = Group.objects.filter(pk__in=self.user_groups)

Expand All @@ -134,7 +144,7 @@ def has_permission(self) -> bool:

assembled_permission = str(permission["content_type__app_label"]) + '.' + str(permission["codename"])

if assembled_permission in self.get_permission_required() and (team['organization_id'] == self.object_organization() or self.object_organization() == 0):
if assembled_permission in self.get_permission_required() and (team['organization_id'] == organization or organization == 0):

return True

Expand All @@ -154,7 +164,7 @@ def dispatch(self, request, *args, **kwargs):

if hasattr(self, 'get_object'):

if not self.has_permission() and not request.user.is_superuser:
if not self.has_organization_permission() and not request.user.is_superuser:
raise PermissionDenied('You are not part of this organization')

return super().dispatch(self.request, *args, **kwargs)
Loading

0 comments on commit 64f4c8f

Please sign in to comment.