From db14d73e118deed17d8fd98e756bbd2d44a3c83d Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 30 Oct 2020 00:11:40 +0100 Subject: [PATCH] Simplify(?) migration code --- .../0019_extend_permissions_features.py | 45 +++++++------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/src/yunohost/data_migrations/0019_extend_permissions_features.py b/src/yunohost/data_migrations/0019_extend_permissions_features.py index e9118ffb1..b20b92e62 100644 --- a/src/yunohost/data_migrations/0019_extend_permissions_features.py +++ b/src/yunohost/data_migrations/0019_extend_permissions_features.py @@ -39,50 +39,37 @@ class MyMigration(Migration): permission_list = user_permission_list(full=True)["permissions"] for permission in permission_list: - if permission.split('.')[0] == 'mail': - ldap.update('cn=%s,ou=permission' % permission, { + system_perms = { + "mail": "E-mail", + "xmpp": "XMPP", + "ssh": "SSH", + "sftp": "STFP" + } + if permission.split('.')[0] in system_perms: + update = { 'authHeader': ["FALSE"], - 'label': ['E-mail'], + 'label': [system_perms[permission.split('.')[0]]], 'showTile': ["FALSE"], 'isProtected': ["TRUE"], - }) - elif permission.split('.')[0] == 'xmpp': - ldap.update('cn=%s,ou=permission' % permission, { - 'authHeader': ["FALSE"], - 'label': ['XMPP'], - 'showTile': ["FALSE"], - 'isProtected': ["TRUE"], - }) - elif permission.split('.')[0] == 'ssh': - ldap.update('cn=%s,ou=permission' % permission, { - 'authHeader': ["FALSE"], - 'label': ['SSH'], - 'showTile': ["FALSE"], - 'isProtected': ["TRUE"], - }) - elif permission.split('.')[0] == 'sftp': - ldap.update('cn=%s,ou=permission' % permission, { - 'authHeader': ["FALSE"], - 'label': ['SFTP'], - 'showTile': ["FALSE"], - 'isProtected': ["TRUE"], - }) + } else: app, subperm_name = permission.split('.') if permission.endswith(".main"): - ldap.update('cn=%s,ou=permission' % permission, { + update = { 'authHeader': ["TRUE"], '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, { + update = { 'authHeader': ["TRUE"], 'label': [subperm_name.title()], 'showTile': ["FALSE"], 'isProtected': ["TRUE"] - }) + } + + ldap.update('cn=%s,ou=permission' % permission, update) def run(self):