Show More
@@ -187,7 +187,18 b' OUTPUT::' | |||
|
187 | 187 | |
|
188 | 188 | result: { |
|
189 | 189 | "id" : "<new_user_id>", |
|
190 | "msg" : "created new user <username>" | |
|
190 | "msg" : "created new user <username>", | |
|
191 | "user": { | |
|
192 | "id" : "<id>", | |
|
193 | "username" : "<username>", | |
|
194 | "firstname": "<firstname>", | |
|
195 | "lastname" : "<lastname>", | |
|
196 | "email" : "<email>", | |
|
197 | "active" : "<bool>", | |
|
198 | "admin" :Β "<bool>", | |
|
199 | "ldap_dn" : "<ldap_dn>", | |
|
200 | "last_login": "<last_login>", | |
|
201 | }, | |
|
191 | 202 | } |
|
192 | 203 | error: null |
|
193 | 204 | |
@@ -195,7 +206,7 b' OUTPUT::' | |||
|
195 | 206 | update_user |
|
196 | 207 | ----------- |
|
197 | 208 | |
|
198 |
updates |
|
|
209 | updates given user if such user exists. This command can | |
|
199 | 210 | be executed only using api_key belonging to user with admin rights. |
|
200 | 211 | |
|
201 | 212 | |
@@ -220,7 +231,33 b' OUTPUT::' | |||
|
220 | 231 | |
|
221 | 232 | result: { |
|
222 | 233 | "id" : "<edited_user_id>", |
|
223 | "msg" : "updated user <username>" | |
|
234 | "msg" : "updated user ID:<userid> <username>" | |
|
235 | } | |
|
236 | error: null | |
|
237 | ||
|
238 | ||
|
239 | delete_user | |
|
240 | ----------- | |
|
241 | ||
|
242 | ||
|
243 | deletes givenuser if such user exists. This command can | |
|
244 | be executed only using api_key belonging to user with admin rights. | |
|
245 | ||
|
246 | ||
|
247 | INPUT:: | |
|
248 | ||
|
249 | id : <id_for_response> | |
|
250 | api_key : "<api_key>" | |
|
251 | method : "delete_user" | |
|
252 | args : { | |
|
253 | "userid" : "<user_id or username>", | |
|
254 | } | |
|
255 | ||
|
256 | OUTPUT:: | |
|
257 | ||
|
258 | result: { | |
|
259 | "id" : "<edited_user_id>", | |
|
260 | "msg" : "deleted user ID:<userid> <username>" | |
|
224 | 261 | } |
|
225 | 262 | error: null |
|
226 | 263 |
@@ -156,14 +156,25 b' class ApiController(JSONRPCController):' | |||
|
156 | 156 | password = PasswordGenerator().gen_password(length=8) |
|
157 | 157 | |
|
158 | 158 | try: |
|
159 | usr = UserModel().create_or_update( | |
|
159 | user = UserModel().create_or_update( | |
|
160 | 160 | username, password, email, firstname, |
|
161 | 161 | lastname, active, admin, ldap_dn |
|
162 | 162 | ) |
|
163 | 163 | Session.commit() |
|
164 | 164 | return dict( |
|
165 | id=usr.user_id, | |
|
166 | msg='created new user %s' % username | |
|
165 | id=user.user_id, | |
|
166 | msg='created new user %s' % username, | |
|
167 | user=dict( | |
|
168 | id=user.user_id, | |
|
169 | username=user.username, | |
|
170 | firstname=user.name, | |
|
171 | lastname=user.lastname, | |
|
172 | email=user.email, | |
|
173 | active=user.active, | |
|
174 | admin=user.admin, | |
|
175 | ldap_dn=user.ldap_dn, | |
|
176 | last_login=user.last_login, | |
|
177 | ) | |
|
167 | 178 | ) |
|
168 | 179 | except Exception: |
|
169 | 180 | log.error(traceback.format_exc()) |
@@ -185,8 +196,9 b' class ApiController(JSONRPCController):' | |||
|
185 | 196 | :param admin: |
|
186 | 197 | :param ldap_dn: |
|
187 | 198 | """ |
|
188 |
|
|
|
189 | raise JSONRPCError("user %s does not exist" % username) | |
|
199 | usr = UserModel().get_user(userid) | |
|
200 | if not usr: | |
|
201 | raise JSONRPCError("user ID:%s does not exist" % userid) | |
|
190 | 202 | |
|
191 | 203 | try: |
|
192 | 204 | usr = UserModel().create_or_update( |
@@ -196,11 +208,34 b' class ApiController(JSONRPCController):' | |||
|
196 | 208 | Session.commit() |
|
197 | 209 | return dict( |
|
198 | 210 | id=usr.user_id, |
|
199 | msg='updated user %s' % username | |
|
211 | msg='updated user ID:%s %s' % (usr.user_id, usr.username) | |
|
200 | 212 | ) |
|
201 | 213 | except Exception: |
|
202 | 214 | log.error(traceback.format_exc()) |
|
203 |
raise JSONRPCError('failed to update user %s' % user |
|
|
215 | raise JSONRPCError('failed to update user %s' % userid) | |
|
216 | ||
|
217 | @HasPermissionAllDecorator('hg.admin') | |
|
218 | def delete_user(self, apiuser, userid): | |
|
219 | """" | |
|
220 | Deletes an user | |
|
221 | ||
|
222 | :param apiuser: | |
|
223 | """ | |
|
224 | usr = UserModel().get_user(userid) | |
|
225 | if not usr: | |
|
226 | raise JSONRPCError("user ID:%s does not exist" % userid) | |
|
227 | ||
|
228 | try: | |
|
229 | UserModel().delete(userid) | |
|
230 | Session.commit() | |
|
231 | return dict( | |
|
232 | id=usr.user_id, | |
|
233 | msg='deleted user ID:%s %s' % (usr.user_id, usr.username) | |
|
234 | ) | |
|
235 | except Exception: | |
|
236 | log.error(traceback.format_exc()) | |
|
237 | raise JSONRPCError('failed to delete ID:%s %s' % (usr.user_id, | |
|
238 | usr.username)) | |
|
204 | 239 | |
|
205 | 240 | @HasPermissionAllDecorator('hg.admin') |
|
206 | 241 | def get_users_group(self, apiuser, group_name): |
General Comments 0
You need to be logged in to leave comments.
Login now