mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Some improvements and fixes to actions related to app access
This commit is contained in:
parent
da2b3691c7
commit
6a64386127
1 changed files with 47 additions and 49 deletions
|
@ -571,47 +571,50 @@ def app_addaccess(auth, apps, users=[]):
|
||||||
from yunohost.user import user_list, user_info
|
from yunohost.user import user_list, user_info
|
||||||
from yunohost.hook import hook_callback
|
from yunohost.hook import hook_callback
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
|
||||||
if not users:
|
if not users:
|
||||||
users = user_list(auth)['users'].keys()
|
users = user_list(auth)['users'].keys()
|
||||||
|
elif not isinstance(users, list):
|
||||||
if not isinstance(users, list): users = [users]
|
users = [users,]
|
||||||
if not isinstance(apps, list): apps = [apps]
|
if not isinstance(apps, list):
|
||||||
|
apps = [apps,]
|
||||||
|
|
||||||
for app in apps:
|
for app in apps:
|
||||||
if not _is_installed(app):
|
app_settings = _get_app_settings(app)
|
||||||
raise MoulinetteError(errno.EINVAL,
|
if not app_settings:
|
||||||
m18n.n('app_not_installed', app))
|
continue
|
||||||
|
|
||||||
with open(apps_setting_path + app +'/settings.yml') as f:
|
|
||||||
app_settings = yaml.load(f)
|
|
||||||
|
|
||||||
if 'mode' not in app_settings:
|
if 'mode' not in app_settings:
|
||||||
app_setting(app, 'mode', 'private')
|
app_setting(app, 'mode', 'private')
|
||||||
app_settings['mode'] = 'private'
|
app_settings['mode'] = 'private'
|
||||||
|
|
||||||
if app_settings['mode'] == 'private':
|
if app_settings['mode'] == 'private':
|
||||||
|
allowed_users = set()
|
||||||
if 'allowed_users' in app_settings:
|
if 'allowed_users' in app_settings:
|
||||||
new_users = app_settings['allowed_users']
|
allowed_users = set(app_settings['allowed_users'].split(','))
|
||||||
else:
|
|
||||||
new_users = ''
|
|
||||||
|
|
||||||
for allowed_user in users:
|
for allowed_user in users:
|
||||||
if allowed_user not in new_users.split(','):
|
if allowed_user not in allowed_users:
|
||||||
try:
|
try:
|
||||||
user_info(auth, allowed_user)
|
user_info(auth, allowed_user)
|
||||||
except MoulinetteError:
|
except MoulinetteError:
|
||||||
|
# FIXME: Add username keyword in user_unknown
|
||||||
|
logger.warning('{0}{1}'.format(
|
||||||
|
m18n.g('colon', m18n.n('user_unknown')),
|
||||||
|
allowed_user))
|
||||||
continue
|
continue
|
||||||
if new_users == '':
|
allowed_users.add(allowed_user)
|
||||||
new_users = allowed_user
|
|
||||||
else:
|
|
||||||
new_users = new_users +','+ allowed_user
|
|
||||||
|
|
||||||
app_setting(app, 'allowed_users', new_users.strip())
|
new_users = ','.join(allowed_users)
|
||||||
|
app_setting(app, 'allowed_users', new_users)
|
||||||
hook_callback('post_app_addaccess', args=[app, new_users])
|
hook_callback('post_app_addaccess', args=[app, new_users])
|
||||||
|
|
||||||
|
result[app] = allowed_users
|
||||||
|
|
||||||
app_ssowatconf(auth)
|
app_ssowatconf(auth)
|
||||||
|
|
||||||
return { 'allowed_users': new_users.split(',') }
|
return { 'allowed_users': result }
|
||||||
|
|
||||||
|
|
||||||
def app_removeaccess(auth, apps, users=[]):
|
def app_removeaccess(auth, apps, users=[]):
|
||||||
|
@ -626,45 +629,43 @@ def app_removeaccess(auth, apps, users=[]):
|
||||||
from yunohost.user import user_list
|
from yunohost.user import user_list
|
||||||
from yunohost.hook import hook_callback
|
from yunohost.hook import hook_callback
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
|
||||||
remove_all = False
|
remove_all = False
|
||||||
if not users:
|
if not users:
|
||||||
remove_all = True
|
remove_all = True
|
||||||
if not isinstance(users, list): users = [users]
|
elif not isinstance(users, list):
|
||||||
if not isinstance(apps, list): apps = [apps]
|
users = [users,]
|
||||||
|
if not isinstance(apps, list):
|
||||||
|
apps = [apps,]
|
||||||
|
|
||||||
for app in apps:
|
for app in apps:
|
||||||
new_users = ''
|
app_settings = _get_app_settings(app)
|
||||||
|
if not app_settings:
|
||||||
|
continue
|
||||||
|
allowed_users = set()
|
||||||
|
|
||||||
if not _is_installed(app):
|
if app_settings.get('skipped_uris', '') != '/':
|
||||||
raise MoulinetteError(errno.EINVAL,
|
|
||||||
m18n.n('app_not_installed', app))
|
|
||||||
|
|
||||||
with open(apps_setting_path + app +'/settings.yml') as f:
|
|
||||||
app_settings = yaml.load(f)
|
|
||||||
|
|
||||||
if 'skipped_uris' not in app_settings or app_settings['skipped_uris'] != '/':
|
|
||||||
if remove_all:
|
if remove_all:
|
||||||
new_users = ''
|
pass
|
||||||
elif 'allowed_users' in app_settings:
|
elif 'allowed_users' in app_settings:
|
||||||
for allowed_user in app_settings['allowed_users'].split(','):
|
for allowed_user in app_settings['allowed_users'].split(','):
|
||||||
if allowed_user not in users:
|
if allowed_user not in users:
|
||||||
if new_users == '':
|
allowed_users.add(allowed_user)
|
||||||
new_users = allowed_user
|
|
||||||
else:
|
|
||||||
new_users = new_users +','+ allowed_user
|
|
||||||
else:
|
else:
|
||||||
new_users = ''
|
for allowed_user in user_list(auth)['users'].keys():
|
||||||
for username in user_list(auth)['users'].keys():
|
if allowed_user not in users:
|
||||||
if username not in users:
|
allowed_users.add(allowed_user)
|
||||||
if new_users == '':
|
|
||||||
new_users = username
|
|
||||||
new_users += ',' + username
|
|
||||||
|
|
||||||
app_setting(app, 'allowed_users', new_users.strip())
|
new_users = ','.join(allowed_users)
|
||||||
|
app_setting(app, 'allowed_users', new_users)
|
||||||
hook_callback('post_app_removeaccess', args=[app, new_users])
|
hook_callback('post_app_removeaccess', args=[app, new_users])
|
||||||
|
|
||||||
|
result[app] = allowed_users
|
||||||
|
|
||||||
app_ssowatconf(auth)
|
app_ssowatconf(auth)
|
||||||
|
|
||||||
return { 'allowed_users': new_users.split(',') }
|
return { 'allowed_users': result }
|
||||||
|
|
||||||
|
|
||||||
def app_clearaccess(auth, apps):
|
def app_clearaccess(auth, apps):
|
||||||
|
@ -680,12 +681,9 @@ def app_clearaccess(auth, apps):
|
||||||
if not isinstance(apps, list): apps = [apps]
|
if not isinstance(apps, list): apps = [apps]
|
||||||
|
|
||||||
for app in apps:
|
for app in apps:
|
||||||
if not _is_installed(app):
|
app_settings = _get_app_settings(app)
|
||||||
raise MoulinetteError(errno.EINVAL,
|
if not app_settings:
|
||||||
m18n.n('app_not_installed', app))
|
continue
|
||||||
|
|
||||||
with open(apps_setting_path + app +'/settings.yml') as f:
|
|
||||||
app_settings = yaml.load(f)
|
|
||||||
|
|
||||||
if 'mode' in app_settings:
|
if 'mode' in app_settings:
|
||||||
app_setting(app, 'mode', delete=True)
|
app_setting(app, 'mode', delete=True)
|
||||||
|
|
Loading…
Add table
Reference in a new issue