def update_user(user_id, company_id, data: dict) -> Tuple[int, dict]: """ Update user. :param user_id: user ID to update :param company_id: ID of company user belongs to :param data: mapping to update user by :return: (updated fields count, updated fields) pair """ update_fields = { k: v for k, v in create_fields.items() if k in User.user_set_allowed() } partial_update_dict = parse_from_call(data, update_fields, User.get_fields()) with translate_errors_context("updating user"): return User.safe_update(company_id, user_id, partial_update_dict)
def get_current_user(call: APICall, company_id, _): with translate_errors_context("retrieving users"): projection = ({"company.name"}.union(User.get_fields()).difference( User.get_exclude_fields())) res = User.get_many_with_join( query=Q(id=call.identity.user), company=company_id, override_projection=projection, ) if not res: raise errors.bad_request.InvalidUser("failed loading user") user = res[0] user["role"] = call.identity.role resp = {"user": user} call.result.data = resp