MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / delete_role

Function delete_role

web/pgadmin/tools/user_management/__init__.py:393–425  ·  view source on GitHub ↗
(rid)

Source from the content-addressed store, hash-verified

391
392
393def delete_role(rid):
394 r = Role.query.get(rid)
395
396 if not r:
397 return ajax_response(
398 response=_('Role not found'),
399 status=404
400 )
401
402 users = User.query.all()
403
404 for u in users:
405 if u.has_role(r):
406 return make_json_response(
407 success=0,
408 status=400,
409 errormsg=_(
410 'To proceed, ensure that all users assigned '
411 'the \'{0}\' role have been reassigned.'.format(r.name))
412 )
413
414 try:
415 # Finally delete user
416 db.session.delete(r)
417 db.session.commit()
418
419 return ajax_response(
420 status=200
421 )
422 except Exception as e:
423 db.session.rollback()
424 current_app.logger.exception(e)
425 return internal_server_error(str(e))
426
427
428@blueprint.route(

Callers 1

role_saveFunction · 0.70

Calls 4

make_json_responseFunction · 0.90
internal_server_errorFunction · 0.90
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected