From 756237c051ffd042ce75036fe2ea55cb07c2eb32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Thu, 2 Apr 2020 16:58:24 +0200 Subject: [PATCH] Fix and improve migration --- locales/en.json | 2 ++ src/yunohost/app.py | 4 ---- .../0015_extends_permissions_features_1.py | 22 +++++-------------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/locales/en.json b/locales/en.json index 418a7d7f2..30ede23a8 100644 --- a/locales/en.json +++ b/locales/en.json @@ -428,6 +428,8 @@ "migration_0011_update_LDAP_database": "Updating LDAP database…", "migration_0011_update_LDAP_schema": "Updating LDAP schema…", "migration_0011_failed_to_remove_stale_object": "Could not remove stale object {dn}: {error}", + "migration_0015_add_new_attributes_in_ldap": "Add new attributes for permissions in LDAP database", + "migration_0015_migrate_old_app_settings": "Migrate old apps settings 'skipped_uris', 'unprotected_uris', 'protected_uris' in permissions system.", "migrations_already_ran": "Those migrations are already done: {ids}", "migrations_cant_reach_migration_file": "Could not access migrations files at the path '%s'", "migrations_dependencies_not_satisfied": "Run these migrations: '{dependencies_id}', before migration {id}.", diff --git a/src/yunohost/app.py b/src/yunohost/app.py index d72e439bb..afb40d8ed 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1208,10 +1208,6 @@ def app_ssowatconf(): redirected_regex = {main_domain + '/yunohost[\/]?$': 'https://' + main_domain + '/yunohost/sso/'} redirected_urls = {} - def _get_setting(settings, name): - s = settings.get(name, None) - return s.split(',') if s else [] - for app in _installed_apps(): app_settings = read_yaml(APPS_SETTING_PATH + app + '/settings.yml') diff --git a/src/yunohost/data_migrations/0015_extends_permissions_features_1.py b/src/yunohost/data_migrations/0015_extends_permissions_features_1.py index 433bf94da..83222fd0a 100644 --- a/src/yunohost/data_migrations/0015_extends_permissions_features_1.py +++ b/src/yunohost/data_migrations/0015_extends_permissions_features_1.py @@ -6,8 +6,8 @@ from yunohost.utils.error import YunohostError from moulinette.utils.log import getActionLogger from yunohost.tools import Migration -from yunohost.app import app_setting, app_ssowatconf -from yunohost.permission import user_permission_list, SYSTEM_PERMS +from yunohost.app import app_setting, app_ssowatconf, _installed_apps +from yunohost.permission import user_permission_list, SYSTEM_PERMS, permission_sync_to_user logger = getActionLogger('yunohost.migration') @@ -29,10 +29,12 @@ class MyMigration(Migration): if ldap_regen_conf_status and ldap_regen_conf_status['slapd']['pending']: logger.warning(m18n.n("migration_0011_slapd_config_will_be_overwritten", conf_backup_folder=BACKUP_CONF_DIR)) + # Update LDAP schema restart slapd + logger.info(m18n.n("migration_0011_update_LDAP_schema")) regen_conf(names=['slapd'], force=True) + logger.info(m18n.n("migration_0015_add_new_attributes_in_ldap")) ldap = _get_ldap_interface() - permission_list = user_permission_list(short=True)["permissions"] for permission in permission_list: @@ -62,18 +64,13 @@ class MyMigration(Migration): }) app_setting(permission.split('.')[0], 'label', delete=True) + def run(self): # FIXME : what do we really want to do here ... # Imho we should just force-regen the conf in all case, and maybe # just display a warning if we detect that the conf was manually modified - # Check if the migration can be processed - ldap_regen_conf_status = regen_conf(names=['slapd'], dry_run=True) - # By this we check if the have been customized - if ldap_regen_conf_status and ldap_regen_conf_status['slapd']['pending']: - logger.warning(m18n.n("migration_0011_slapd_config_will_be_overwritten", conf_backup_folder=BACKUP_CONF_DIR)) - # Backup LDAP and the apps settings before to do the migration logger.info(m18n.n("migration_0011_backup_before_migration")) try: @@ -89,10 +86,6 @@ class MyMigration(Migration): os.system("systemctl start slapd") try: - # Update LDAP schema restart slapd - logger.info(m18n.n("migration_0011_update_LDAP_schema")) - regen_conf(names=['slapd'], force=True) - # Update LDAP database self.add_new_ldap_attributes() @@ -111,6 +104,3 @@ class MyMigration(Migration): raise else: os.system("rm -r " + backup_folder) - - logger.info(m18n.n("migration_0011_done")) -