Skip to content

Commit

Permalink
add submodule permission command for occtax
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Aug 14, 2023
1 parent d4b667b commit b7c3ac5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
5 changes: 4 additions & 1 deletion contrib/occtax/backend/occtax/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down
42 changes: 42 additions & 0 deletions contrib/occtax/backend/occtax/commands.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit b7c3ac5

Please sign in to comment.