-
Notifications
You must be signed in to change notification settings - Fork 175
fix(BA-5309): Add migration to convert global-scoped permissions to domain-scoped #10342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+46
−0
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| Add migration to convert deprecated global-scoped permissions to domain-scoped equivalents, fixing `RBACTypeConversionError` in `adminPermissions` GraphQL query. |
72 changes: 72 additions & 0 deletions
72
...kend/manager/models/alembic/versions/5a4e677aea42_convert_global_permissions_to_domain.py
This file contains hidden or 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,72 @@ | ||
| """convert global-scoped permissions to domain-scoped | ||
|
|
||
| Revision ID: 5a4e677aea42 | ||
| Revises: ffcf0ed13a26 | ||
| Create Date: 2026-03-20 00:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "5a4e677aea42" | ||
| down_revision = "ffcf0ed13a26" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| conn = op.get_bind() | ||
|
|
||
| # (a) Query all active domain names | ||
| domain_rows = conn.execute(sa.text("SELECT name FROM domains ORDER BY name")).fetchall() | ||
|
fregataa marked this conversation as resolved.
Outdated
|
||
| domain_names = [row[0] for row in domain_rows] | ||
|
|
||
| if not domain_names: | ||
| # No domains exist; just delete global rows since there's nowhere to convert them | ||
| conn.execute(sa.text("DELETE FROM permissions WHERE scope_type = 'global'")) | ||
| return | ||
|
|
||
| # (b) Query all permission rows where scope_type='global' | ||
| global_perms = conn.execute( | ||
| sa.text( | ||
| "SELECT id, role_id, entity_type, operation" | ||
| " FROM permissions" | ||
| " WHERE scope_type = 'global'" | ||
| ) | ||
| ).fetchall() | ||
|
fregataa marked this conversation as resolved.
Outdated
|
||
|
|
||
| if not global_perms: | ||
| return | ||
|
|
||
| # (c) For each global permission × each domain, insert a domain-scoped row | ||
| # ON CONFLICT DO NOTHING handles the unique constraint | ||
| # (role_id, scope_type, scope_id, entity_type, operation) | ||
| insert_stmt = sa.text( | ||
| "INSERT INTO permissions (id, role_id, scope_type, scope_id, entity_type, operation)" | ||
| " VALUES (uuid_generate_v4(), :role_id, 'domain', :scope_id, :entity_type, :operation)" | ||
| " ON CONFLICT ON CONSTRAINT uq_permissions_role_scope_entity_op DO NOTHING" | ||
| ) | ||
|
|
||
| for perm in global_perms: | ||
| for domain_name in domain_names: | ||
| conn.execute( | ||
| insert_stmt, | ||
| { | ||
| "role_id": str(perm[1]), | ||
|
fregataa marked this conversation as resolved.
Outdated
|
||
| "scope_id": domain_name, | ||
| "entity_type": perm[2], | ||
| "operation": perm[3], | ||
| }, | ||
| ) | ||
|
|
||
| # (d) Delete all global-scoped permission rows | ||
|
fregataa marked this conversation as resolved.
Outdated
|
||
| conn.execute(sa.text("DELETE FROM permissions WHERE scope_type = 'global'")) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| # Global scope is deprecated and has no corresponding RBACElementType. | ||
| # The conversion to domain-scoped permissions is not reversible because | ||
| # we cannot determine which domain-scoped rows were originally global. | ||
| pass | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.