org.user, web.client: user update on zitadel working
This commit is contained in:
		
							parent
							
								
									7427370b5c
								
							
						
					
					
						commit
						3e43c25d84
					
				
					 2 changed files with 44 additions and 9 deletions
				
			
		|  | @ -50,12 +50,38 @@ class ExtUser: | ||||||
|             ), |             ), | ||||||
|             organization=dict(orgId=params['organization_id']), |             organization=dict(orgId=params['organization_id']), | ||||||
|         ) |         ) | ||||||
|         if self.user.hashedPassword: |  | ||||||
|             data['hashedPassword'] = self.user.hashedPassword |  | ||||||
|         return data |         return data | ||||||
| 
 | 
 | ||||||
|     def send(self): |     def create(self, updateIfExits=False): | ||||||
|         clt = client.ApiClient(config.oidc_provider) |         clt = client.ApiClient(config.oidc_provider) | ||||||
|         data = self.asDict() |         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 | ||||||
|  |  | ||||||
|  | @ -24,12 +24,21 @@ class ApiClient: | ||||||
| 
 | 
 | ||||||
|     def post(self, endpoint, data): |     def post(self, endpoint, data): | ||||||
|         headers = self.authentication() |         headers = self.authentication() | ||||||
|  |         headers['Content-Type'] = 'application/json' | ||||||
|         # self.makeUrl(endpoint) |         # self.makeUrl(endpoint) | ||||||
|         url = '/'.join((self.baseUrl, endpoint)) |         url = '/'.join((self.baseUrl, endpoint)) | ||||||
|         resp = requests.post(url, json=data, headers=headers) |         resp = requests.post(url, json=data, headers=headers) | ||||||
|         if resp.status_code != 200: |         if resp.status_code >= 400: | ||||||
|             logger.error('post %s: %s', url, resp.text) |             logger.error('post %s: %s %s', url, resp.status_code, resp.text) | ||||||
|             return resp.text |         return resp.status_code, resp.json() | ||||||
|         data = resp.json() | 
 | ||||||
|         return data |     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() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue