-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't query ObjectPermission table when user has access_all_objects c…
…apability (#783) Co-authored-by: Paweł Srokosz <[email protected]>
- Loading branch information
Showing
8 changed files
with
86 additions
and
34 deletions.
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
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 |
---|---|---|
|
@@ -24,13 +24,6 @@ def _initialize(admin_password): | |
) | ||
db.session.add(public_group) | ||
|
||
everything_group = Group( | ||
name=Group.DEFAULT_EVERYTHING_GROUP_NAME, | ||
capabilities=[Capabilities.access_all_objects], | ||
workspace=False, | ||
) | ||
db.session.add(everything_group) | ||
|
||
registered_group = Group( | ||
name=Group.DEFAULT_REGISTERED_GROUP_NAME, | ||
capabilities=[ | ||
|
@@ -52,7 +45,7 @@ def _initialize(admin_password): | |
login=app_config.mwdb.admin_login, | ||
email="[email protected]", | ||
additional_info="MWDB built-in administrator account", | ||
groups=[admin_group, everything_group, public_group, registered_group], | ||
groups=[admin_group, public_group, registered_group], | ||
) | ||
admin_user.reset_sessions() | ||
admin_user.set_password(admin_password) | ||
|
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
65 changes: 65 additions & 0 deletions
65
mwdb/model/migrations/versions/6a7aefae72d3_rolling_back_objectpermissions_from_.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,65 @@ | ||
"""Rolling back ObjectPermissions from access_all_objects | ||
Revision ID: 6a7aefae72d3 | ||
Revises: f02c42a17695 | ||
Create Date: 2023-06-22 14:19:34.730831 | ||
""" | ||
import logging | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects.postgresql.array import ARRAY | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "6a7aefae72d3" | ||
down_revision = "f02c42a17695" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
group_helper = sa.Table( | ||
"group", | ||
sa.MetaData(), | ||
sa.Column("id", sa.Integer()), | ||
sa.Column("name", sa.String(32)), | ||
sa.Column("capabilities", ARRAY(sa.Text())), | ||
sa.Column("private", sa.Boolean()), | ||
sa.Column("default", sa.Boolean()), | ||
sa.Column("workspace", sa.Boolean()), | ||
) | ||
|
||
object_perm_helper = sa.Table( | ||
"permission", | ||
sa.MetaData(), | ||
sa.Column("object_id", sa.Integer()), | ||
sa.Column("group_id", sa.Integer()), | ||
sa.Column("reason_type", sa.String(32)), | ||
) | ||
|
||
logger = logging.getLogger("alembic") | ||
|
||
|
||
def upgrade(): | ||
connection = op.get_bind() | ||
access_all_objects_groups = connection.execute( | ||
group_helper.select().where( | ||
group_helper.c.capabilities.any("access_all_objects") | ||
) | ||
) | ||
for group in access_all_objects_groups: | ||
logger.info(f"Removing unnecessary rows access_all_objects group: {group.name}") | ||
rowcount = connection.execute( | ||
object_perm_helper.delete( | ||
sa.and_( | ||
object_perm_helper.c.group_id == group.id, | ||
object_perm_helper.c.reason_type == "shared", | ||
) | ||
) | ||
).rowcount | ||
logger.info(f"{rowcount} rows removed") | ||
logger.info("Running analyze...") | ||
connection.execute("ANALYZE") | ||
|
||
|
||
def downgrade(): | ||
raise NotImplementedError("This migration is not downgradable") |
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
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
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
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