Skip to content

Commit

Permalink
refactor(access): cache app settings during perm check
Browse files Browse the repository at this point in the history
ref: #469 #471
  • Loading branch information
jon-nfc committed Jan 16, 2025
1 parent fefde28 commit 7f16a06
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/access/mixins/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def has_permission(self, request, view):
return False


_app_settings: any = None

def has_object_permission(self, request, view, obj):

Expand All @@ -276,19 +277,23 @@ def has_object_permission(self, request, view, obj):

object_organization: int = getattr(view.get_obj_organization( obj = obj ), 'id', None)

from settings.models.app_settings import AppSettings
if not self._app_settings:

app_settings = AppSettings.objects.get(
owner_organization = None
)
from settings.models.app_settings import AppSettings

app_settings = AppSettings.objects.get(
owner_organization = None
)

self._app_settings = app_settings

if object_organization:

if(
object_organization
in view.get_permission_organizations( view.get_permission_required() )
or request.user.is_superuser
or getattr(app_settings.global_organization, 'id', 0) == int(object_organization)
or getattr(self._app_settings.global_organization, 'id', 0) == int(object_organization)
):

return True
Expand Down

0 comments on commit 7f16a06

Please sign in to comment.