User.update - Python API

Both regular and super-users can update information about their own accounts using self.sso.user.update_current_user, which accepts current session's UST on input.

Further, super-users may update other users by their ID with self.sso.user.update_user_by_id.

When sending input 'data' dictionary, there is a distinction between sending a key with a value of None and not sending it altogether. If None is sent, a given attribute will be set to NULL on SQL level whereas not sending a particular key will not update it at all and any current value will be left as it is.

Passwords can be changed using a separate call.

self.sso.user.update_current_user

update_current_user(self, cid, data, current_ust, current_app, remote_addr)

Updates information about user using this person's current session.

  • cid: Correlation ID used by audit log
  • data: A dictionary of values to update the account with.
  • current_ust: Current user's UST
  • current_app: Name of application the current user is issuing the call from
  • remote_addr: User's remote address
  • Returns: (None)

Regular users may send the following keys in the 'data' dictionary:

  • email
  • display_name
  • first_name
  • middle_name
  • last_name
  • is_totp_enabled
  • totp_key
  • totp_label

Super-users may additionally send:

  • is_locked
  • password_expiry
  • password_must_change
  • sign_up_status
  • approval_status
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class UpdateCurrentUser(Service):
    def handle(self):

        # Request metadata
        current_ust = 'gAAAAABamSuDF8-TOEjl43GxoMSS86RD_cquqEr...'
        current_app = 'CRM'
        remote_addr = '127.0.0.1'

        # New data to update the user with
        data = {
            'display_name': 'New Display Name',
            'email': 'myuser@example.com'
        }

        self.sso.user.update_current_user(
            self.cid, data, current_ust, current_app, remote_addr)

self.sso.user.update_user_by_id

update_user_by_id(self, cid, user_id, data, current_ust, current_app, remote_addr)

Updates an account by that user's ID.

  • cid: Correlation ID used by audit log
  • user_id: User ID (another person or possibly current user)
  • data: A dictionary of values to update the account with. Consult update_user_by_id `method above for usage details.
  • current_ust: Current user's UST - must belong to a super-user
  • current_app: Name of application current user is issuing the call from
  • remote_addr: Current user's remote address
  • Returns: (None)
# -*- coding: utf-8 -*-

# stdlib
from datetime import datetime, timedelta

# Zato
from zato.server.service import Service

class UpdateUserByID(Service):
    def handle(self):

        # Request metadata
        current_ust = 'gAAAAABamSuDF8-TOEjl43GxoMSS86RD_cquqEr...'
        current_app = 'CRM'
        remote_addr = '127.0.0.1'

        # User to change
        user_id = 'zusr4q51jwtsdh9s298315h4at6t1n'

        # New data to update the user with
        data = {
            'display_name': 'My Display Name',
            'is_locked': False,
            'password_expiry': datetime.utcnow() + timedelta(days=90)
        }

        self.sso.user.update_user_by_id(
            self.cid, user_id, data, current_ust, current_app, remote_addr)