diff --git a/action_map.yml b/action_map.yml index 3d4098bf..d2e9a97e 100644 --- a/action_map.yml +++ b/action_map.yml @@ -306,10 +306,10 @@ app: addaccess: action_help: Grant access right to users (everyone by default) arguments: - app: + apps: nargs: "+" -u: - full: --user + full: --users nargs: "+" ### app_removeaccess() TODO: Write help diff --git a/yunohost_app.py b/yunohost_app.py index f796606f..f9e213b3 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -386,6 +386,44 @@ def app_install(app, domain, path='/', label=None, mode='private'): win_msg(_("Installation complete")) +def app_addaccess(apps, users): + """ + Grant access to a private app to a user + + Keyword arguments: + apps -- List of app to grant access to + users -- Users to grant access for + + """ + if not isinstance(users, list): users = [users] + if not isinstance(apps, list): apps = [apps] + + installed_apps = os.listdir(apps_setting_path) + + lemon_conf_lines = {} + + for installed_app in installed_apps: + for app in apps: + if '__' not in app: + app = app + '__1' + + if app == installed_app: + with open(apps_setting_path + installed_app +'/app_settings.yml') as f: + app_settings = yaml.load(f) + + if app_settings['mode'] == 'private': + if 'allowed_users' in app_settings: + new_users = app_settings['allowed_users'] + else: + new_users = '' + + for allowed_user in users: + new_users = new_users +' '+ allowed_user + + lemon_conf_lines[('locationRules', app_settings['domain'], '(?#'+ installed_app +'Z)^'+ app_settings['path'] )] = '$uid ~~ qw('+ new_users +')' + + lemon_configuration(lemon_conf_lines) + def _extract_app_from_file(path): """