aboutsummaryrefslogtreecommitdiff
path: root/migrations/auth/20250609_01_LB60X-add-batch-edit-privileges.py
blob: 73a48807bc3398c2898a011656ffa3c06a8cc726 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Add Batch Edit privileges
"""

import contextlib

from yoyo import step

__depends__ = {'20250328_01_72EFk-add-admin-ui-privilege-to-system-administrator-role'}

def add_batch_edit_privilege_and_role(conn):
    with contextlib.closing(conn.cursor()) as cursor:
        # Create batch edit privilege
        cursor.execute(
            "INSERT INTO privileges (privilege_id, privilege_description) "
            "VALUES(?, ?)",
            ("system:data:batch-edit", "Batch Edit"))

        # Create batch editor role
        cursor.execute(
            "INSERT INTO roles (role_id, role_name, user_editable) "
            "VALUES(?, ?, ?)",
            ("0f391910-5225-476a-bb8d-9c0adc9d81cc", "Batch Editors", 0))

        # Link role/privilege
        cursor.execute(
            "INSERT INTO role_privileges (role_id, privilege_id) "
            "VALUES(?, ?)",
            ("0f391910-5225-476a-bb8d-9c0adc9d81cc", "system:data:batch-edit")
        )

def remove_batch_edit_privilege_and_role(conn):
    with contextlib.closing(conn.cursor()) as cursor:
        # Remove batch edit role/privilege link
        cursor.execute(
            "DELETE FROM role_privileges WHERE privilege_id='system:data:batch-edit'")
        
        # Remove Batch Editor role
        cursor.execute(
            "DELETE FROM roles WHERE role_id='0f391910-5225-476a-bb8d-9c0adc9d81cc'")

        # Remove Batch Edit privilege
        cursor.execute(
            "DELETE FROM privileges WHERE privilege_id='system:data:batch-edit'")


steps = [
    step(add_batch_edit_privilege_and_role, remove_batch_edit_privilege_and_role)
]