Skip to content

Commit

Permalink
permissions: add flask-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier committed Apr 14, 2023
1 parent 581e29c commit 106a2cc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/geonature/core/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import geonature.core.gn_permissions.admin
57 changes: 57 additions & 0 deletions backend/geonature/core/gn_permissions/admin.py
Original file line number Diff line number Diff line change
@@ -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 = "PERMISSION"

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 = "PERMISSION"

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",
)
)
6 changes: 6 additions & 0 deletions backend/geonature/core/gn_permissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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",
Expand Down

0 comments on commit 106a2cc

Please sign in to comment.