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.

API

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.

Parameters:
  • cid (string) – Correlation ID used by audit log
  • data (dict) –

    A dictionary of values to update the account with.

    Regular users may send:

    • email
    • display_name
    • first_name
    • middle_name
    • last_name

    Super-users may send additionally:

    • is_approved
    • is_locked
    • password_expiry
    • password_must_change
    • sign_up_status
  • current_ust (string) – Current user’s UST
  • current_app (string) – Name of application the current user is issuing the call from
  • remote_addr (string) – User’s remote address
Return type:

(None)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

# 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.

Parameters:
  • cid (string) – Correlation ID used by audit log
  • user_id (string) – User ID (another person or possibly current user)
  • data (dict) – A dictionary of values to update the account with. Consult update_user_by_id method above for usage details.
  • current_ust (string) – Current user’s UST - must belong to a super-user
  • current_app (string) – Name of application current user is issuing the call from
  • remote_addr (string) – Current user’s remote address
Return type:

(None)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

# 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)