org.user, web.client: user update on zitadel working

This commit is contained in:
Helmut Merz 2025-08-04 18:39:18 +02:00
parent 7427370b5c
commit 3e43c25d84
2 changed files with 44 additions and 9 deletions

View file

@ -50,12 +50,38 @@ class ExtUser:
),
organization=dict(orgId=params['organization_id']),
)
if self.user.hashedPassword:
data['hashedPassword'] = self.user.hashedPassword
return data
def send(self):
def create(self, updateIfExits=False):
clt = client.ApiClient(config.oidc_provider)
data = self.asDict()
res = clt.post(self.endpoints['users_human'], data)
if self.user.hashedPassword:
data['hashedPassword'] = self.user.hashedPassword
status, res = clt.post(self.endpoints['users_human'], data)
if status > 201:
if updateIfExits:
return self.update()
else:
return status, res
if self.user.grants:
return self.createGrants()
def update(self, createIfMissing=False):
clt = client.ApiClient(config.oidc_provider)
data = self.asDict()
if self.user.hashedPassword:
data['password'] = dict(hashedPassword=self.user.hashedPassword)
status, res = clt.put(self.endpoints['users_human'], self.userId, data)
if status > 200:
if createIfMissing:
return self.create()
else:
return status, res
if self.user.grants:
return self.updateGrants()
def createGrants(self):
pass
def updateGrants(self):
pass

View file

@ -24,12 +24,21 @@ class ApiClient:
def post(self, endpoint, data):
headers = self.authentication()
headers['Content-Type'] = 'application/json'
# self.makeUrl(endpoint)
url = '/'.join((self.baseUrl, endpoint))
resp = requests.post(url, json=data, headers=headers)
if resp.status_code != 200:
logger.error('post %s: %s', url, resp.text)
return resp.text
data = resp.json()
return data
if resp.status_code >= 400:
logger.error('post %s: %s %s', url, resp.status_code, resp.text)
return resp.status_code, resp.json()
def put(self, endpoint, objId, data):
headers = self.authentication()
headers['Content-Type'] = 'application/json'
# self.makeUrl(endpoint)
url = '/'.join((self.baseUrl, endpoint, objId))
resp = requests.put(url, json=data, headers=headers)
if resp.status_code >= 400:
logger.error('post %s: %s %s', url, resp.status_code, resp.text)
return resp.status_code, resp.json()