Skip to content

Commit

Permalink
improve taxhub integration
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Aug 3, 2023
1 parent 3036c5f commit 0544155
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 8 deletions.
3 changes: 0 additions & 3 deletions backend/geonature/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ def set_sentry_context():
with app.app_context():
# taxhub
from apptax import taxhub_routes
from apptax.admin.admin import taxhub_admin_addview

taxhub_admin_addview(app, admin, "TaxHub")

for blueprint_path, url_prefix in taxhub_routes:
module_name, blueprint_name = blueprint_path.split(":")
Expand Down
64 changes: 64 additions & 0 deletions backend/geonature/core/admin/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from flask import g
from werkzeug.exceptions import Unauthorized
from flask_admin import Admin, AdminIndexView, expose
Expand Down Expand Up @@ -28,6 +30,16 @@
TNomenclaturesAdmin,
)

from apptax.admin.admin import adresses
from apptax.taxonomie.models import Taxref, BibListes, TMedias, BibAttributs, BibThemes

from geonature.core.taxonomie.admin import (
CruvedProtectedBibListesView,
CruvedProtectedTaxrefView,
CruvedProtectedTMediasView,
CruvedProtectedBibAttributsView,
CruvedProtectedBibThemes,
)
from .utils import CruvedProtectedMixin


Expand Down Expand Up @@ -152,4 +164,56 @@ class ProtectedTNomenclaturesAdmin(
)
)

static_folder = os.path.join(adresses.root_path, "static")

admin.add_view(
CruvedProtectedTaxrefView(
Taxref,
db.session,
name="Taxref",
endpoint="taxons",
category="TaxHub",
static_folder=static_folder,
)
)
admin.add_view(
CruvedProtectedBibListesView(
BibListes,
db.session,
name="Listes",
category="TaxHub",
static_folder=static_folder,
)
)


admin.add_view(
CruvedProtectedBibAttributsView(
BibAttributs,
db.session,
name="Attributs",
category="TaxHub",
static_folder=static_folder,
)
)
admin.add_view(
CruvedProtectedBibThemes(
BibThemes,
db.session,
name="Thèmes",
category="TaxHub",
static_folder=static_folder,
)
)

admin.add_view(
CruvedProtectedTMediasView(
TMedias,
db.session,
name="Médias",
category="TaxHub",
static_folder=static_folder,
)
)

flask_admin = admin # for retro-compatibility, usefull for export module for instance
34 changes: 34 additions & 0 deletions backend/geonature/core/taxonomie/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from apptax.admin.admin_view import (
BibListesView,
TaxrefView,
TMediasView,
BibAttributsView,
BibThemesView,
)
from geonature.core.admin.utils import CruvedProtectedMixin


class CruvedProtectedBibListesView(CruvedProtectedMixin, BibListesView):
module_code = "TAXHUB"
object_code = "LISTE"
extra_actions_perm = {".import_cd_nom_view": "C"}


class CruvedProtectedTaxrefView(CruvedProtectedMixin, TaxrefView):
module_code = "TAXHUB"
object_code = "TAXON"


class CruvedProtectedTMediasView(CruvedProtectedMixin, TMediasView):
module_code = "TAXHUB"
object_code = "TAXON"


class CruvedProtectedBibAttributsView(CruvedProtectedMixin, BibAttributsView):
module_code = "TAXHUB"
object_code = "ATTRIBUT"


class CruvedProtectedBibThemes(CruvedProtectedMixin, BibThemesView):
module_code = "TAXHUB"
object_code = "THEME"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""declare taxhub TAXHUB
"""declare module TAXHUB
Revision ID: ebbe0f7ed866
Revises: f1dd984bff97
Expand Down Expand Up @@ -28,7 +28,6 @@ def upgrade():
VALUES
('TAXON', 'Gestion des taxons dans TaxHub'),
('THEME', 'Gestion des thêmes d''attribut dans TaxHub'),
('MEDIA', 'Gestion des médias dans TaxHub'),
('LISTE', 'Gestion des listes dans TaxHub'),
('ATTRIBUT', 'Gestion des types d''attributs dans TaxHub')
;
Expand Down Expand Up @@ -56,9 +55,6 @@ def upgrade():
,('TAXHUB', 'THEME', 'R', False, 'Voir les thêmes')
,('TAXHUB', 'THEME', 'U', False, 'Modifier les thêmes')
,('TAXHUB', 'THEME', 'D', False, 'Supprimer des thêmes')
,('TAXHUB', 'MEDIA', 'R', False, 'Voir les médias')
,('TAXHUB', 'MEDIA', 'U', False, 'Modifier les médias')
,('TAXHUB', 'MEDIA', 'D', False, 'Supprimer les médias')
,('TAXHUB', 'LISTE', 'C', False, 'Creer des listes')
,('TAXHUB', 'LISTE', 'R', False, 'Voir les listes')
,('TAXHUB', 'LISTE', 'U', False, 'Modifier les listes')
Expand All @@ -77,6 +73,38 @@ def upgrade():
WHERE m.module_code = 'TAXHUB'
"""
)
# rappatriement des permissions de l'application TaxHub

op.execute(
"""
INSERT INTO gn_permissions.t_permissions
(id_role, id_action, id_module, id_object)
select crap.id_role, t.id_action, t.id_module, t.id_object
from ( values ('TH', 'TAXHUB')) as v (code_appli, code_module)
join gn_commons.t_modules m ON m.module_code = v.code_module
join gn_permissions.t_permissions_available t on t.id_module = m.id_module
join utilisateurs.t_applications app on app.code_application = v.code_appli
join utilisateurs.cor_role_app_profil crap on crap.id_application = app.id_application
where m.module_code = 'TAXHUB' and app.code_application = 'TH' and crap.id_profil = 6;
INSERT INTO gn_permissions.t_permissions
(id_role, id_action, id_module, id_object)
select crap.id_role, t.id_action, t.id_module, t.id_object
from ( values ('TH', 'TAXHUB')) as v (code_appli, code_module)
join gn_commons.t_modules m ON m.module_code = v.code_module
join gn_permissions.t_permissions_available t on t.id_module = m.id_module
join gn_permissions.t_objects obj on t.id_object = obj.id_object
join utilisateurs.t_applications app on app.code_application = v.code_appli
join utilisateurs.cor_role_app_profil crap on crap.id_application = app.id_application
where m.module_code = 'TAXHUB' and app.code_application = 'TH' and crap.id_profil in (1,2,3,4,5) and obj.code_object = 'TAXON';
"""
)

op.execute(
"""
delete from utilisateurs.t_applications where code_application = 'TH'
"""
)


def downgrade():
Expand Down
6 changes: 6 additions & 0 deletions docs/admin-manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,12 @@ Le champs "Attribut additionnels" permet d'ajouter des éléments de configurati
- Ajouter un sous-titre descriptif : `{"help" : "mon sous titre"}`
- Ajouter des valeurs min/max pour un input `number` : `{"min": 1, "max": 10}`

TaxHub
""""""

Backoffice de gestion des taxons (basé sur TaxHub) permettant de faire des liste de taxons ainsi que d'ajouter des attributs etdes médias aux taxons.
Voir la documentation de TaxHub : https://taxhub.readthedocs.io/fr/latest/

Module OCCHAB
-------------

Expand Down

0 comments on commit 0544155

Please sign in to comment.