From 0e8ea0d2ee552ac2870510a6fb40b1d6a3b3be98 Mon Sep 17 00:00:00 2001 From: Kload Date: Sun, 3 Mar 2013 17:45:31 +0100 Subject: [PATCH] app_removeaccess() --- action_map.yml | 4 ++-- yunohost.py | 1 + yunohost_app.py | 47 ++++++++++++++++++++++++++++++++++++++++++++-- yunohost_domain.py | 1 - 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/action_map.yml b/action_map.yml index cba685e1..2c6b0f7d 100644 --- a/action_map.yml +++ b/action_map.yml @@ -316,10 +316,10 @@ app: removeaccess: action_help: Revoke access right to users (everyone by default) arguments: - app: + apps: nargs: "+" -u: - full: --user + full: --users nargs: "+" diff --git a/yunohost.py b/yunohost.py index d4bae087..215776f3 100644 --- a/yunohost.py +++ b/yunohost.py @@ -208,6 +208,7 @@ def lemon_configuration(conf_dict): lemon_conf.write(conf_line + '\n') if os.system('/usr/share/lemonldap-ng/bin/lmYnhMoulinette') == 0: + os.system('service apache2 reload') win_msg(_("LemonLDAP configured")) else: raise YunoHostError(1, _("An error occured during LemonLDAP configuration")) diff --git a/yunohost_app.py b/yunohost_app.py index e3f1dfa6..d7a27ff2 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -419,14 +419,57 @@ def app_addaccess(apps, users): for allowed_user in users: if allowed_user not in new_users.split(' '): + # TODO: check if user exists new_users = new_users +' '+ allowed_user - app_settings['allowed_users'] = new_users + app_settings['allowed_users'] = new_users.strip() with open(apps_setting_path + installed_app +'/app_settings.yml', 'w') as f: yaml.safe_dump(app_settings, f, default_flow_style=False) win_msg(_("App setting file updated")) - lemon_conf_lines[('locationRules', app_settings['domain'], '(?#'+ installed_app +'Z)^'+ app_settings['path'] )] = 'grep( /^$uid$/, qw('+ new_users +'))' + lemon_conf_lines[('locationRules', app_settings['domain'], '(?#'+ installed_app +'Z)^'+ app_settings['path'] )] = 'grep( /^$uid$/, qw('+ new_users.strip() +'))' + + lemon_configuration(lemon_conf_lines) + + +def app_removeaccess(apps, users): + """ + Revoke access to a private app to a user + + Keyword arguments: + apps -- List of app to revoke access to + users -- Users to revoke 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: + new_users = '' + 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: + for allowed_user in app_settings['allowed_users'].split(' '): + if allowed_user not in users: + new_users = new_users +' '+ allowed_user + + app_settings['allowed_users'] = new_users.strip() + with open(apps_setting_path + installed_app +'/app_settings.yml', 'w') as f: + yaml.safe_dump(app_settings, f, default_flow_style=False) + win_msg(_("App setting file updated")) + + lemon_conf_lines[('locationRules', app_settings['domain'], '(?#'+ installed_app +'Z)^'+ app_settings['path'] )] = 'grep( /^$uid$/, qw('+ new_users.strip() +'))' lemon_configuration(lemon_conf_lines) diff --git a/yunohost_domain.py b/yunohost_domain.py index a6a385ff..3a0bdeb4 100644 --- a/yunohost_domain.py +++ b/yunohost_domain.py @@ -80,7 +80,6 @@ def domain_add(domains, web=False): ('vhostOptions', domain, 'vhostPort'): -1, ('vhostOptions', domain, 'vhostHttps'): -1, ('locationRules', domain, 'default'): 'accept', - ('locationRules', domain, '(?#logout)^/logout'): 'logout_app_sso https://'+ domain +'/' }) _apache_config(domain)