Skip to content

Commit 0b0309a

Browse files
committed
fix: AdminSite permission bug
1 parent e938b8f commit 0b0309a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

easy/permissions/adminsite.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,22 @@ def has_permission(
2424
model: models.Model = cast(models.Model, getattr(controller, "model", None))
2525
if model:
2626
app: str = model._meta.app_label
27+
model_name = model.__name__.lower()
2728
if request.method in ("GET", "OPTIONS"):
28-
has_perm = user.has_perm(f"{app}.view{model.__name__}") # type: ignore
29+
has_perm = user.has_perm(f"{app}.view_{model_name}") # type: ignore
30+
2931
elif request.method in ("PUT", "POST"):
30-
has_perm = user.has_perm(f"{app}.add_{model.__name__}") # type: ignore
32+
has_perm = user.has_perm(f"{app}.add_{model_name}") # type: ignore
33+
3134
elif request.method in ("PUT", "PATCH", "POST"):
32-
has_perm = user.has_perm(f"{app}.change_{model.__name__}") # type: ignore
35+
has_perm = user.has_perm(f"{app}.change_{model_name}") # type: ignore
36+
3337
elif request.method in ("DELETE",):
34-
has_perm = user.has_perm(f"{app}.delete_{model.__name__}") # type: ignore
38+
has_perm = user.has_perm(f"{app}.delete_{model_name}") # type: ignore
39+
3540
if user.is_superuser: # type: ignore
3641
has_perm = True
42+
3743
return bool(
3844
user
3945
and user.is_authenticated

0 commit comments

Comments
 (0)