forked from bluesky/tiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to add 'write:prinicipals' to default admin role.
- Loading branch information
1 parent
367fdb7
commit 447ec73
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tiled/authn_database/migrations/versions/769180ce732e_add_write_principals_scope_to_admin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Add 'write:principals' scope to admin | ||
Revision ID: 769180ce732e | ||
Revises: c7bd2573716d | ||
Create Date: 2023-12-12 17:57:56.388145 | ||
""" | ||
from alembic import op | ||
from sqlalchemy.orm.session import Session | ||
|
||
from tiled.authn_database.orm import Role | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "769180ce732e" | ||
down_revision = "c7bd2573716d" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
SCOPE = "write:principals" | ||
|
||
|
||
def upgrade(): | ||
""" | ||
Add 'write:principal' scope to default 'admin' Role. | ||
""" | ||
connection = op.get_bind() | ||
with Session(bind=connection) as db: | ||
role = db.query(Role).filter(Role.name == "admin").first() | ||
scopes = role.scopes.copy() | ||
scopes.append(SCOPE) | ||
role.scopes = scopes | ||
db.commit() | ||
|
||
|
||
def downgrade(): | ||
""" | ||
Remove new scopes from Roles, if present. | ||
""" | ||
connection = op.get_bind() | ||
with Session(bind=connection) as db: | ||
role = db.query(Role).filter(Role.name == "admin").first() | ||
scopes = role.scopes.copy() | ||
if SCOPE in scopes: | ||
scopes.remove(SCOPE) | ||
role.scopes = scopes | ||
db.commit() |