@@ -213,7 +213,6 @@ class RoleCRUD(object):
213
213
214
214
@staticmethod
215
215
def search (q , app_id , page = 1 , page_size = None , user_role = True , is_all = False , user_only = False ):
216
-
217
216
if user_only : # only user role
218
217
query = db .session .query (Role ).filter (Role .deleted .is_ (False )).filter (Role .uid .isnot (None ))
219
218
@@ -271,6 +270,13 @@ def update_role(rid, **kwargs):
271
270
RoleCache .clean (rid )
272
271
273
272
role = role .update (** kwargs )
273
+
274
+ if origin ['uid' ] and kwargs .get ('name' ) and kwargs .get ('name' ) != origin ['name' ]:
275
+ from api .models .acl import User
276
+ user = User .get_by (uid = origin ['uid' ], first = True , to_dict = False )
277
+ if user :
278
+ user .update (username = kwargs ['name' ])
279
+
274
280
AuditCRUD .add_role_log (role .app_id , AuditOperateType .update ,
275
281
AuditScope .role , role .id , origin , role .to_dict (), {},
276
282
)
@@ -289,12 +295,11 @@ def delete_role(cls, rid, force=False):
289
295
from api .lib .perm .acl .acl import is_admin
290
296
291
297
role = Role .get_by_id (rid ) or abort (404 , ErrFormat .role_not_found .format ("rid={}" .format (rid )))
292
-
293
- not force and role .uid and abort (400 , ErrFormat .user_role_delete_invalid )
294
-
295
298
if not role .app_id and not is_admin ():
296
299
return abort (403 , ErrFormat .admin_required )
297
300
301
+ not force and role .uid and abort (400 , ErrFormat .user_role_delete_invalid )
302
+
298
303
origin = role .to_dict ()
299
304
300
305
child_ids = []
@@ -303,20 +308,18 @@ def delete_role(cls, rid, force=False):
303
308
304
309
for i in RoleRelation .get_by (parent_id = rid , to_dict = False ):
305
310
child_ids .append (i .child_id )
306
- i .soft_delete (commit = False )
311
+ i .soft_delete ()
307
312
308
313
for i in RoleRelation .get_by (child_id = rid , to_dict = False ):
309
314
parent_ids .append (i .parent_id )
310
- i .soft_delete (commit = False )
315
+ i .soft_delete ()
311
316
312
317
role_permissions = []
313
318
for i in RolePermission .get_by (rid = rid , to_dict = False ):
314
319
role_permissions .append (i .to_dict ())
315
- i .soft_delete (commit = False )
316
-
317
- role .soft_delete (commit = False )
320
+ i .soft_delete ()
318
321
319
- db . session . commit ()
322
+ role . soft_delete ()
320
323
321
324
role_rebuild .apply_async (args = (recursive_child_ids , role .app_id ), queue = ACL_QUEUE )
322
325
0 commit comments