Skip to content

Commit

Permalink
Avoid import time problems
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Sep 16, 2023
1 parent 7098e7c commit 6112d09
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions authlib/permissions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from fnmatch import fnmatch
from functools import partial

from django import forms
from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.db import models
from django.utils.module_loading import import_string
from django.utils.translation import gettext_lazy as _


Expand All @@ -21,15 +21,17 @@ def allow_deny_globs(user, perm, obj, allow=(), deny=()):
},
"deny_admin": {
"title": _("deny accounts"),
"callback": partial(
allow_deny_globs,
allow=["*"],
deny=[
"auth.*",
"admin_sso.*",
"accounts.*",
"little_auth.*",
],
"callback": (
"authlib.permissions.allow_deny_globs",
{
"allow": ["*"],
"deny": [
"auth.*",
"admin_sso.*",
"accounts.*",
"little_auth.*",
],
},
),
},
}
Expand Down Expand Up @@ -59,5 +61,6 @@ class Meta:
abstract = True

def _role_has_perm(self, *, perm, obj):
if callback := AUTHLIB_ROLES[self.role].get("callback"):
return self.is_active and callback(user=self, perm=perm, obj=obj)
if cb := AUTHLIB_ROLES[self.role].get("callback"):
callback = import_string(cb[0])
return self.is_active and callback(user=self, perm=perm, obj=obj, **cb[1])

0 comments on commit 6112d09

Please sign in to comment.