code: def update(
      self,
      context: AuthedServiceContext,
      uid: UID,
      user_update: UserUpdate,
  ) -> Union[UserView, SyftError]:
      updates_role = user_update.role is not Empty
  
      if (
          updates_role
          and ServiceRoleCapability.CAN_EDIT_ROLES
          not in context.capabilities()
      ):
          return SyftError(
              message=f"{context.role} is not allowed to edit roles"
          )
  
      # Get user to be updated by its UID
      result = self.stash.get_by_uid(
          credentials=context.credentials, uid=uid
      )
  
      # check if the email already exists (with root's key)
      if user_update.email is not Empty:
          user_with_email_exists: bool = self.stash.email_exists(
              email=user_update.email
          )
          if user_with_email_exists:
              raise UserAlreadyExistsException.raise_with_context(
                  context=context
              )
  
      if result.is_err():
          error_msg = f"Failed to find user with UID: {uid}. Error: {str(result.err())}"
          return SyftError(message=error_msg)
  
      user = result.ok()
  
      if user is None:
          return SyftError(
              message=f"No user exists for given UID: {uid}"
          )
  
      if updates_role:
          if context.role == ServiceRole.ADMIN:
              # do anything
              pass
          elif (
              context.role == ServiceRole.DATA_OWNER
              and context.role > user.role
              and context.role > user_update.role
          ):
              # as a data owner, only update lower roles to < data owner
              pass
          else:
              return SyftError(
                  message=f"As a {context.role}, you are not allowed to edit {user.role} to {user_update.role}"
              )
  
      edits_non_role_attrs = any(
          getattr(user_update, attr) is not Empty
          for attr in user_update.dict()
          if attr != "role"
      )
  
      if (
          edits_non_role_attrs
          and user.verify_key != context.credentials
          and ServiceRoleCapability.CAN_MANAGE_USERS
          not in context.capabilities()
      ):
          return SyftError(
              message=f"As a {context.role}, you are not allowed to edit users"
          )
  
      # Fill User Update fields that will not be changed by replacing it
      # for the current values found in user obj.
      for name, value in user_update.to_dict(
          exclude_empty=True
      ).items():
          if name == "password" and value:
              salt, hashed = salt_and_hash_password(value, 12)
              user.hashed_password = hashed
              user.salt = salt
          elif not name.startswith("__") and value is not None:
              setattr(user, name, value)
  
      result = self.stash.update(
          credentials=context.credentials,
          user=user,
          has_permission=True,
      )
  
      if result.is_err():
          error_msg = f"Failed to update user with UID: {uid}. Error: {str(result.err())}"
          return SyftError(message=error_msg)
  
      user = result.ok()
      if user.role == ServiceRole.ADMIN:
          settings_stash = SettingsStash(store=self.store)
          settings = settings_stash.get_all(context.credentials)
          if settings.is_ok() and len(settings.ok()) > 0:
              settings_data = settings.ok()[0]
              settings_data.admin_email = user.email
              settings_stash.update(
                  credentials=context.credentials,
                  settings=settings_data,
              )
  
      return user.to(UserView)
  
imports: from typing import List
  from typing import Optional
  from typing import Tuple
  from typing import Union
  from ...abstract_node import NodeType
  from ...exceptions.user import UserAlreadyExistsException
  from ...node.credentials import SyftSigningKey
  from ...node.credentials import SyftVerifyKey
  from ...node.credentials import UserLoginCredentials
  from ...serde.serializable import serializable
  from ...store.document_store import DocumentStore
  from ...types.syft_metaclass import Empty
  from ...types.uid import UID
  from ...util.telemetry import instrument
  from ..action.action_permissions import ActionObjectPermission
  from ..action.action_permissions import ActionPermission
  from ..context import AuthedServiceContext
  from ..context import NodeServiceContext
  from ..context import UnauthedServiceContext
  from ..response import SyftError
  from ..response import SyftSuccess
  from ..service import AbstractService
  from ..service import SERVICE_TO_TYPES
  from ..service import TYPE_TO_SERVICE
  from ..service import service_method
  from ..settings.settings_stash import SettingsStash
  from .user import User
  from .user import UserCreate
  from .user import UserPrivateKey
  from .user import UserSearch
  from .user import UserUpdate
  from .user import UserView
  from .user import UserViewPage
  from .user import check_pwd
  from .user import salt_and_hash_password
  from .user_roles import DATA_OWNER_ROLE_LEVEL
  from .user_roles import GUEST_ROLE_LEVEL
  from .user_roles import ServiceRole
  from .user_roles import ServiceRoleCapability
  from .user_stash import UserStash
label_desc: Use image node_id 8 for calling the UserService obj's underlying member method code with example usage: obj.update(context, uid, user_update) and returns: user, SyftError, SyftError, SyftError, SyftError, SyftError, SyftError