def api_user_id_delete(id=None, auth_user=None, api_core=None, request=None): u"""Delete a user.""" user = api_core.get_user(spec={u'_id': id}) if not user: raise IndexError(to_bytes(u'No user with id {0}.'.format(id))) api_core.delete_user(user) return ok_200(u'The user "{0}" has been deleted.'.format(user.name), include_properties=False)
def api_user_id_patch(id=None, auth_user=None, api_core=None, request=None): u""" Update an user. User's admin_platform attribute can only be modified by root or any authenticated user with admin_platform attribute set. """ user = api_core.get_user(spec={u'_id': id}) data = get_request_data(request, qs_only_first_value=True) if not user: raise IndexError(to_bytes(u'No user with id {0}.'.format(id))) old_name = user.name if u'first_name' in data: user.first_name = data[u'first_name'] if u'last_name' in data: user.last_name = data[u'last_name'] if u'mail' in data: user.mail = data[u'mail'] if u'secret' in data: user.secret = data[u'secret'] if auth_user.admin_platform and u'admin_platform' in data: user.admin_platform = data[u'admin_platform'] api_core.save_user(user, hash_secret=True) return ok_200(u'The user "{0}" has been updated.'.format(old_name), include_properties=False)
def api_user_id_get(id=None, auth_user=None, api_core=None, request=None): u"""Return a user serialized to JSON (without ``secret`` field).""" user = api_core.get_user(spec={u'_id': id}, fields={u'secret': 0}) if not user: raise IndexError(to_bytes(u'No user with id {0}.'.format(id))) return ok_200(user, include_properties=True)