File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments