diff --git a/backend/geonature/core/admin/__init__.py b/backend/geonature/core/admin/__init__.py index e69de29bb2..c31328c68b 100644 --- a/backend/geonature/core/admin/__init__.py +++ b/backend/geonature/core/admin/__init__.py @@ -0,0 +1 @@ +import geonature.core.gn_permissions.admin diff --git a/backend/geonature/core/gn_permissions/admin.py b/backend/geonature/core/gn_permissions/admin.py new file mode 100644 index 0000000000..01f19b80a5 --- /dev/null +++ b/backend/geonature/core/gn_permissions/admin.py @@ -0,0 +1,57 @@ +from flask_admin.contrib.sqla import ModelView + +from geonature.utils.env import db +from geonature.core.admin.admin import admin +from geonature.core.admin.utils import CruvedProtectedMixin +from geonature.core.gn_permissions.models import PermObject, Permission + + +class ObjectAdmin(CruvedProtectedMixin, ModelView): + module_code = "ADMIN" + object_code = "PERMISSIONS" + + column_list = ("code_object", "description_object", "modules") + column_labels = { + "code_object": "Code", + "description_object": "Description", + } + + can_create = False + can_edit = False + can_delete = False + + +class PermissionAdmin(CruvedProtectedMixin, ModelView): + module_code = "ADMIN" + object_code = "PERMISSIONS" + + column_list = ("role", "module", "object", "action", "scope") + column_labels = { + "role": "Rôle", + "scope": "Porté", + "object": "Objet", + } + column_formatters = { + "module": lambda v, c, m, p: m.module.module_code, + "object": lambda v, c, m, p: m.object.code_object, + } + + +admin.add_view( + ObjectAdmin( + PermObject, + db.session, + name="Objets", + category="Permissions", + ) +) + + +admin.add_view( + PermissionAdmin( + Permission, + db.session, + name="Permissions", + category="Permissions", + ) +) diff --git a/backend/geonature/core/gn_permissions/models.py b/backend/geonature/core/gn_permissions/models.py index 393961d398..67a14e942d 100644 --- a/backend/geonature/core/gn_permissions/models.py +++ b/backend/geonature/core/gn_permissions/models.py @@ -29,6 +29,9 @@ class PermScope(db.Model): label = db.Column(db.Unicode) description = db.Column(db.Unicode) + def __str__(self): + return self.description + @serializable class PermAction(db.Model): @@ -38,6 +41,9 @@ class PermAction(db.Model): code_action = db.Column(db.Unicode) description_action = db.Column(db.Unicode) + def __str__(self): + return self.description_action + cor_object_module = db.Table( "cor_object_module",