From e91f2de0dc248ac80f771a32945813fdd93d0f6e Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 29 Oct 2020 23:26:28 +0100 Subject: [PATCH] Move 'label' migration to migrate_legacy_permission_settings in legacy.py, because the previous code could led to some inconsistencies when restoring apps backuped before the migration --- .../0019_extends_permissions_features_1.py | 13 +++---------- src/yunohost/utils/legacy.py | 4 +++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/yunohost/data_migrations/0019_extends_permissions_features_1.py b/src/yunohost/data_migrations/0019_extends_permissions_features_1.py index 6eba67f26..1be7532d3 100644 --- a/src/yunohost/data_migrations/0019_extends_permissions_features_1.py +++ b/src/yunohost/data_migrations/0019_extends_permissions_features_1.py @@ -6,7 +6,6 @@ from yunohost.utils.error import YunohostError from moulinette.utils.log import getActionLogger from yunohost.tools import Migration -from yunohost.app import app_setting, _installed_apps from yunohost.permission import user_permission_list from yunohost.utils.legacy import migrate_legacy_permission_settings @@ -39,11 +38,6 @@ class MyMigration(Migration): ldap = _get_ldap_interface() permission_list = user_permission_list(full=True)["permissions"] - labels = {} - for app in _installed_apps(): - labels[app] = app_setting(app, 'label') or permission_list[app + ".main"].get("label") or app - app_setting(app, 'label', delete=True) - for permission in permission_list: if permission.split('.')[0] == 'mail': ldap.update('cn=%s,ou=permission' % permission, { @@ -74,19 +68,18 @@ class MyMigration(Migration): 'isProtected': ["TRUE"], }) else: - label = labels[permission.split('.')[0]].title() - + app, subperm_name = permission.split('.') if permission.endswith(".main"): ldap.update('cn=%s,ou=permission' % permission, { 'authHeader': ["TRUE"], - 'label': [label], + 'label': [app], # Note that this is later re-changed during the call to migrate_legacy_permission_settings() if a 'label' setting exists 'showTile': ["TRUE"], 'isProtected': ["FALSE"] }) else: ldap.update('cn=%s,ou=permission' % permission, { 'authHeader': ["TRUE"], - 'label': [permission.split('.')[1]], + 'label': [subperm_name.title()], 'showTile': ["FALSE"], 'isProtected': ["TRUE"] }) diff --git a/src/yunohost/utils/legacy.py b/src/yunohost/utils/legacy.py index 7c5d60264..fb5893a1b 100644 --- a/src/yunohost/utils/legacy.py +++ b/src/yunohost/utils/legacy.py @@ -162,6 +162,9 @@ def migrate_legacy_permission_settings(app=None): for app in apps: settings = _get_app_settings(app) or {} + if settings.get("label"): + user_permission_update(app + ".main", label=settings["label"], sync_perm=False) + del settings["label"] def _setting(name): s = settings.get(name) @@ -203,4 +206,3 @@ def migrate_legacy_permission_settings(app=None): _set_app_settings(app, settings) permission_sync_to_user() -