You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To clean up deprecated permissions after upgrading Apache Superset from version 1.5.2 to 4.0.2, you can use the cleanup_permissions function provided in the scripts/permissions_cleanup.py script. This function handles the cleanup of duplicate permissions, permissions with None values, and empty roles.
Here is the relevant code snippet for cleaning up permissions:
fromcollectionsimportdefaultdictfromsupersetimportsecurity_managerfromsuperset.utils.decoratorsimporttransaction@transaction()defcleanup_permissions() ->None:
# 1. Clean up duplicates.pvms=security_manager.get_session.query(
security_manager.permissionview_model
).all()
print(f"# of permission view menus is: {len(pvms)}")
pvms_dict=defaultdict(list)
forpvminpvms:
pvms_dict[(pvm.permission, pvm.view_menu)].append(pvm)
duplicates= [vforvinpvms_dict.values() iflen(v) >1]
forpvm_listinduplicates:
first_prm=pvm_list[0]
roles=set(first_prm.role)
forpvminpvm_list[1:]:
roles=roles.union(pvm.role)
security_manager.get_session.delete(pvm)
first_prm.roles=list(roles)
pvms=security_manager.get_session.query(
security_manager.permissionview_model
).all()
print(f"Stage 1: # of permission view menus is: {len(pvms)}")
# 2. Clean up None permissions or view menuspvms=security_manager.get_session.query(
security_manager.permissionview_model
).all()
forpvminpvms:
ifnot (pvm.view_menuandpvm.permission):
security_manager.get_session.delete(pvm)
pvms=security_manager.get_session.query(
security_manager.permissionview_model
).all()
print(f"Stage 2: # of permission view menus is: {len(pvms)}")
# 3. Delete empty permission view menus from rolesroles=security_manager.get_session.query(security_manager.role_model).all()
forroleinroles:
role.permissions= [pforpinrole.permissionsifp]
# 4. Delete empty roles from permission view menuspvms=security_manager.get_session.query(
security_manager.permissionview_model
).all()
forpvminpvms:
pvm.role= [rforrinpvm.roleifr]
cleanup_permissions()
To use this function, simply run the cleanup_permissions function. This will handle the deletion of duplicate permissions, permissions with None values, and empty roles, ensuring that your permissions are properly cleaned up after the upgrade [1].
Bug description
Hello
after upgrade, deprecated permissions are not deleted.
It's maybe normal (a downgrade is possible) but how clean deprecated permissions ?
How to reproduce the bug
'can select star on Superset' is a deprecated permission.
I install an old version (1.5.2)
I create a role with 'can select star on Superset' permission
I create an user with the role
I stop my superset (I work with docker compose)
I upgrade to 4.0.2
I run superset db upgrade
I run superset db init
I restart superset
The upgrade is done
The role have the deprecated permission
It's possible to create a new role with the deprecated permission
I count the permission in the 'ab_permission' table :
Best regards
Screenshots/recordings
No response
Superset version
master / latest-dev
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
Checklist
The text was updated successfully, but these errors were encountered: