-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
chore(security): Clean up session/commit logic #29381
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1017,9 +1017,9 @@ def clean_perms(self) -> None: | |
== None, # noqa: E711 | ||
) | ||
) | ||
self.get_session.commit() | ||
if deleted_count := pvms.delete(): | ||
logger.info("Deleted %i faulty permissions", deleted_count) | ||
self.get_session.commit() | ||
|
||
def sync_role_definitions(self) -> None: | ||
""" | ||
|
@@ -1047,9 +1047,6 @@ def sync_role_definitions(self) -> None: | |
) | ||
|
||
self.create_missing_perms() | ||
|
||
# commit role and view menu updates | ||
self.get_session.commit() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
self.clean_perms() | ||
|
||
def _get_all_pvms(self) -> list[PermissionView]: | ||
|
@@ -2446,31 +2443,26 @@ def get_rls_filters(self, table: "BaseDatasource") -> list[SqlaQuery]: | |
|
||
user_roles = [role.id for role in self.get_user_roles(g.user)] | ||
regular_filter_roles = ( | ||
self.get_session() | ||
.query(RLSFilterRoles.c.rls_filter_id) | ||
self.get_session.query(RLSFilterRoles.c.rls_filter_id) | ||
.join(RowLevelSecurityFilter) | ||
.filter( | ||
RowLevelSecurityFilter.filter_type == RowLevelSecurityFilterType.REGULAR | ||
) | ||
.filter(RLSFilterRoles.c.role_id.in_(user_roles)) | ||
) | ||
base_filter_roles = ( | ||
self.get_session() | ||
.query(RLSFilterRoles.c.rls_filter_id) | ||
self.get_session.query(RLSFilterRoles.c.rls_filter_id) | ||
.join(RowLevelSecurityFilter) | ||
.filter( | ||
RowLevelSecurityFilter.filter_type == RowLevelSecurityFilterType.BASE | ||
) | ||
.filter(RLSFilterRoles.c.role_id.in_(user_roles)) | ||
) | ||
filter_tables = ( | ||
self.get_session() | ||
.query(RLSFilterTables.c.rls_filter_id) | ||
.filter(RLSFilterTables.c.table_id == table.id) | ||
filter_tables = self.get_session.query(RLSFilterTables.c.rls_filter_id).filter( | ||
RLSFilterTables.c.table_id == table.id | ||
) | ||
query = ( | ||
self.get_session() | ||
.query( | ||
self.get_session.query( | ||
RowLevelSecurityFilter.id, | ||
RowLevelSecurityFilter.group_key, | ||
RowLevelSecurityFilter.clause, | ||
|
@@ -2673,12 +2665,9 @@ def raise_for_ownership(self, resource: Model) -> None: | |
:raises SupersetSecurityException: If the current user is not an owner | ||
""" | ||
|
||
# pylint: disable=import-outside-toplevel | ||
from superset import db | ||
|
||
if self.is_admin(): | ||
return | ||
orig_resource = db.session.query(resource.__class__).get(resource.id) | ||
orig_resource = self.get_session.query(resource.__class__).get(resource.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use the Flask-AppBuilder session everywhere for consistency. Note that |
||
owners = orig_resource.owners if hasattr(orig_resource, "owners") else [] | ||
|
||
if g.user.is_anonymous or g.user not in owners: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure what's going on here. The commit was after a
SELECT
as opposed to theDELETE
.