mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix: dataset update permission out of sync (#25043)
This commit is contained in:
committed by
Michael S. Molina
parent
0caaad7b0a
commit
7d5cd72e43
@@ -1323,7 +1323,7 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
|
||||
mapper, connection, "datasource_access", dataset_vm_name
|
||||
)
|
||||
|
||||
def dataset_after_update(
|
||||
def dataset_before_update(
|
||||
self,
|
||||
mapper: Mapper,
|
||||
connection: Connection,
|
||||
@@ -1343,14 +1343,20 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
|
||||
:param target: The changed dataset object
|
||||
:return:
|
||||
"""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from superset.connectors.sqla.models import SqlaTable
|
||||
|
||||
# Check if watched fields have changed
|
||||
state = inspect(target)
|
||||
history_database = state.get_history("database_id", True)
|
||||
history_table_name = state.get_history("table_name", True)
|
||||
history_schema = state.get_history("schema", True)
|
||||
table = SqlaTable.__table__
|
||||
current_dataset = connection.execute(
|
||||
table.select().where(table.c.id == target.id)
|
||||
).one()
|
||||
current_db_id = current_dataset.database_id
|
||||
current_schema = current_dataset.schema
|
||||
current_table_name = current_dataset.table_name
|
||||
|
||||
# When database name changes
|
||||
if history_database.has_changes() and history_database.deleted:
|
||||
if current_db_id != target.database_id:
|
||||
new_dataset_vm_name = self.get_dataset_perm(
|
||||
target.id, target.table_name, target.database.database_name
|
||||
)
|
||||
@@ -1370,20 +1376,19 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
|
||||
)
|
||||
|
||||
# When table name changes
|
||||
if history_table_name.has_changes() and history_table_name.deleted:
|
||||
old_dataset_name = history_table_name.deleted[0]
|
||||
if current_table_name != target.table_name:
|
||||
new_dataset_vm_name = self.get_dataset_perm(
|
||||
target.id, target.table_name, target.database.database_name
|
||||
)
|
||||
old_dataset_vm_name = self.get_dataset_perm(
|
||||
target.id, old_dataset_name, target.database.database_name
|
||||
target.id, current_table_name, target.database.database_name
|
||||
)
|
||||
self._update_dataset_perm(
|
||||
mapper, connection, old_dataset_vm_name, new_dataset_vm_name, target
|
||||
)
|
||||
|
||||
# When schema changes
|
||||
if history_schema.has_changes() and history_schema.deleted:
|
||||
if current_schema != target.schema:
|
||||
new_dataset_schema_name = self.get_schema_perm(
|
||||
target.database.database_name, target.schema
|
||||
)
|
||||
@@ -1414,6 +1419,7 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
|
||||
:param target: Dataset that was updated
|
||||
:return:
|
||||
"""
|
||||
logger.info("Updating schema perm, new: %s", new_schema_permission_name)
|
||||
from superset.connectors.sqla.models import ( # pylint: disable=import-outside-toplevel
|
||||
SqlaTable,
|
||||
)
|
||||
@@ -1467,6 +1473,11 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
|
||||
:param target:
|
||||
:return:
|
||||
"""
|
||||
logger.info(
|
||||
"Updating dataset perm, old: %s, new: %s",
|
||||
old_permission_name,
|
||||
new_permission_name,
|
||||
)
|
||||
from superset.connectors.sqla.models import ( # pylint: disable=import-outside-toplevel
|
||||
SqlaTable,
|
||||
)
|
||||
@@ -1481,6 +1492,15 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
|
||||
new_dataset_view_menu = self.find_view_menu(new_permission_name)
|
||||
if new_dataset_view_menu:
|
||||
return
|
||||
old_dataset_view_menu = self.find_view_menu(old_permission_name)
|
||||
if not old_dataset_view_menu:
|
||||
logger.warning(
|
||||
"Could not find previous dataset permission %s", old_permission_name
|
||||
)
|
||||
self._insert_pvm_on_sqla_event(
|
||||
mapper, connection, "datasource_access", new_permission_name
|
||||
)
|
||||
return
|
||||
# Update VM
|
||||
connection.execute(
|
||||
view_menu_table.update()
|
||||
|
||||
Reference in New Issue
Block a user