Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
7b4dd6b4
Commit
7b4dd6b4
authored
Mar 28, 2018
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migration: add privileges and policies on nodes_nodes table
parent
d73f94d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
492ab1373f8d_add_privileges_on_nodes_nodes_table.py
...sions/492ab1373f8d_add_privileges_on_nodes_nodes_table.py
+57
-0
No files found.
alembic/versions/492ab1373f8d_add_privileges_on_nodes_nodes_table.py
0 → 100644
View file @
7b4dd6b4
"""Add privileges on nodes_nodes table
Revision ID: 492ab1373f8d
Revises: cceddcb46e27
Create Date: 2018-03-28 19:41:26.148413
"""
from
alembic
import
op
import
sqlalchemy
as
sa
from
gargantext.util.alembic
import
ReplaceableObject
# revision identifiers, used by Alembic.
revision
=
'492ab1373f8d'
down_revision
=
'cceddcb46e27'
branch_labels
=
None
depends_on
=
None
grants
=
[
# Basic privileges for gargantext role
(
'SELECT ON nodes_nodes'
,
'gargantext'
),
(
'UPDATE (node1_id, node2_id) ON nodes_nodes'
,
'gargantext'
),
(
'INSERT ON nodes_nodes'
,
'gargantext'
),
(
'DELETE ON nodes_nodes'
,
'gargantext'
),
]
is_owner
=
"COALESCE(current_user_id() = (SELECT user_id FROM nodes n WHERE n.id = nodes_nodes.node1_id), FALSE)"
owner_related_select_policy
=
ReplaceableObject
(
"owner_related_select"
,
"nodes_nodes"
,
"FOR SELECT USING (
%
s)"
%
is_owner
)
owner_related_update_policy
=
ReplaceableObject
(
"owner_related_update"
,
"nodes_nodes"
,
"FOR UPDATE USING (
%
s)"
%
is_owner
)
owner_related_insert_policy
=
ReplaceableObject
(
"owner_related_insert"
,
"nodes_nodes"
,
"FOR INSERT WITH CHECK (
%
s)"
%
is_owner
)
owner_related_delete_policy
=
ReplaceableObject
(
"owner_related_delete"
,
"nodes_nodes"
,
"FOR DELETE USING (
%
s)"
%
is_owner
)
policies
=
[
owner_related_select_policy
,
owner_related_update_policy
,
owner_related_insert_policy
,
owner_related_delete_policy
]
def
upgrade
():
for
grant
in
grants
:
op
.
execute
(
'GRANT {} TO {}'
.
format
(
*
grant
))
op
.
execute
(
"ALTER TABLE nodes_nodes ENABLE ROW LEVEL SECURITY"
)
for
policy
in
policies
:
op
.
create_policy
(
policy
)
def
downgrade
():
for
policy
in
policies
:
op
.
drop_policy
(
policy
)
op
.
execute
(
"ALTER TABLE nodes_nodes DISABLE ROW LEVEL SECURITY"
)
for
grant
in
grants
:
op
.
execute
(
'REVOKE {} FROM {}'
.
format
(
*
grant
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment