def app_addaccess(auth, apps, users): """ Grant access right to users (everyone by default) Keyword argument: users apps """ from yunohost.user import user_list, user_info from yunohost.hook import hook_callback if not users: users = [] for user in user_list(auth)['users']: users.append(user['username']) if not isinstance(users, list): users = [users] if not isinstance(apps, list): apps = [apps] for app in apps: if not _is_installed(app): 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 'mode' not in app_settings: app_setting(app, 'mode', 'private') app_settings['mode'] = 'private' 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: if allowed_user not in new_users.split(','): try: user_info(auth, allowed_user) except MoulinetteError: continue if new_users == '': new_users = allowed_user else: new_users = new_users + ',' + allowed_user app_setting(app, 'allowed_users', new_users.strip()) hook_callback('post_app_addaccess', [app, new_users]) app_ssowatconf(auth) return {'allowed_users': new_users.split(',')}
def app_addaccess(auth, apps, users): """ Grant access right to users (everyone by default) Keyword argument: users apps """ from yunohost.user import user_list, user_info from yunohost.hook import hook_callback if not users: users = [] for user in user_list(auth)['users']: users.append(user['username']) if not isinstance(users, list): users = [users] if not isinstance(apps, list): apps = [apps] for app in apps: if not _is_installed(app): 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 'mode' not in app_settings: app_setting(app, 'mode', 'private') app_settings['mode'] = 'private' 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: if allowed_user not in new_users.split(','): try: user_info(auth, allowed_user) except MoulinetteError: continue if new_users == '': new_users = allowed_user else: new_users = new_users +','+ allowed_user app_setting(app, 'allowed_users', new_users.strip()) hook_callback('post_app_addaccess', args=[app, new_users]) app_ssowatconf(auth) return { 'allowed_users': new_users.split(',') }
def test_update_user(mocker): with message(mocker, "user_updated"): user_update("alice", firstname="NewName", lastname="NewLast") info = user_info("alice") assert info["firstname"] == "NewName" assert info["lastname"] == "NewLast"