def default_sharing(self, id): """Change a user's default sharing. .. :quickref: User; Change default sharing When used on another user account, requires the `manage_users` permission. :param id: user id. :>json User user: modified user. """ self.ensure_permission(id) user = User(get_or_404(User.get_collection(), _id=id)) groups = request.form.get('groups', '').split(',') for group in groups: if group in user['groups']: break else: flash('You have to at least keep one of your groups.', 'danger') return redirect(request.referrer) user.update_value('default_sharing', groups) return redirect({'user': clean_users(user)}, request.referrer)
def disable(self, id): """Disable a user. .. :quickref: User; Disable a user Requires the `manage_users` permission. :param id: user id. :>json User user: modified user. """ user = User(get_or_404(User.get_collection(), _id=id)) user.update_value('enabled', False) return redirect({'user': clean_users(user)}, url_for('UsersView:index'))
def reset_api(self, id): """Reset a user's API key. .. :quickref: User; Reset API key When used on another user account, requires the `manage_users` permission. :param id: user id. :>json User user: modified user. """ self.ensure_permission(id) user = User(get_or_404(User.get_collection(), _id=id)) user.update_value('api_key', User.generate_api_key()) return redirect({'user': clean_users(user)}, request.referrer)