From b7c3ac5c82fd9fccf95687be54d91eadf7358fda Mon Sep 17 00:00:00 2001 From: TheoLechemia Date: Mon, 14 Aug 2023 10:36:45 +0200 Subject: [PATCH] add submodule permission command for occtax --- contrib/occtax/backend/occtax/blueprint.py | 5 ++- contrib/occtax/backend/occtax/commands.py | 42 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 contrib/occtax/backend/occtax/commands.py diff --git a/contrib/occtax/backend/occtax/blueprint.py b/contrib/occtax/backend/occtax/blueprint.py index dbe36d9166..3e97744f9b 100644 --- a/contrib/occtax/backend/occtax/blueprint.py +++ b/contrib/occtax/backend/occtax/blueprint.py @@ -51,8 +51,11 @@ from utils_flask_sqla_geo.utilsgeometry import remove_third_dimension from utils_flask_sqla.response import to_csv_resp, to_json_resp, json_resp +from occtax.commands import add_submodule_permissions + +blueprint = Blueprint("pr_occtax", __name__, cli_group="occtax") +blueprint.cli.add_command(add_submodule_permissions) -blueprint = Blueprint("pr_occtax", __name__) log = logging.getLogger(__name__) diff --git a/contrib/occtax/backend/occtax/commands.py b/contrib/occtax/backend/occtax/commands.py new file mode 100644 index 0000000000..6a3bc688c8 --- /dev/null +++ b/contrib/occtax/backend/occtax/commands.py @@ -0,0 +1,42 @@ +import click + +from geonature.utils.env import db + + +@click.command() +@click.argument("module_code", required=True) +def add_submodule_permissions(module_code): + q = """ + INSERT INTO + gn_permissions.t_permissions_available ( + id_module, + id_object, + id_action, + label, + scope_filter + ) + SELECT + m.id_module, + o.id_object, + a.id_action, + v.label, + v.scope_filter + FROM + ( + VALUES + (:module_code, 'ALL', 'C', True, 'Créer des relevés') + ,(:module_code, 'ALL', 'R', True, 'Voir les relevés') + ,(:module_code, 'ALL', 'U', True, 'Modifier les relevés') + ,(:module_code, 'ALL', 'E', True, 'Exporter les relevés') + ,(:module_code, 'ALL', 'D', True, 'Supprimer des relevés') + ) AS v (module_code, object_code, action_code, scope_filter, label) + JOIN + gn_commons.t_modules m ON m.module_code = v.module_code + JOIN + gn_permissions.t_objects o ON o.code_object = v.object_code + JOIN + gn_permissions.bib_actions a ON a.code_action = v.action_code + """ + db.session.execute(q, {"module_code": module_code}) + db.session.commit() + click.secho("DONE", fg="green")