From ed0016ed66b8574e181f34619f97979f843f0b8f Mon Sep 17 00:00:00 2001 From: kload Date: Mon, 3 Mar 2014 13:58:41 +0100 Subject: [PATCH] App clearaccess --- action_map.yml | 7 +++++++ yunohost_app.py | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/action_map.yml b/action_map.yml index c973bdbb..42568c7a 100644 --- a/action_map.yml +++ b/action_map.yml @@ -432,6 +432,13 @@ app: full: --users nargs: "+" + ### app_clearaccess() + clearaccess: + action_help: Reset access rights for the app + api: POST /app/access + arguments: + apps: + nargs: "+" ############################# # Backup # diff --git a/yunohost_app.py b/yunohost_app.py index 525e4043..36074183 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -618,6 +618,33 @@ def app_removeaccess(apps, users): return { 'allowed_users': new_users.split(',') } + +def app_clearaccess(apps): + """ + Reset access rights for the app + + Keyword argument: + apps + + """ + if not isinstance(apps, list): apps = [apps] + + for app in apps: + if not _is_installed(app): + raise YunoHostError(22, _("App is not installed")) + + with open(apps_setting_path + app +'/settings.yml') as f: + app_settings = yaml.load(f) + + if 'mode' in app_settings: + app_setting(app, 'mode', delete=True) + + if 'allowed_users' in app_settings: + app_setting(app, 'allowed_users', delete=True) + + app_ssowatconf() + + def app_setting(app, key, value=None, delete=False): """ Set or get an app setting value