MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / update_user

Method update_user

web/setup.py:399–451  ·  view source on GitHub ↗

Update internal user.

(email: str,
                    password: Optional[str] = None,
                    admin: Annotated[Optional[bool], typer.Option(
                        "--admin")] = False,
                    role: Optional[str] = None,
                    active: Annotated[Optional[bool],
                                      typer.Option("--active/--inactive"
                                                   )] = None,
                    console: Optional[bool] = True,
                    json: Optional[bool] = False,
                    sqlite_path: Optional[str] = None,
                    )

Source from the content-addressed store, hash-verified

397 @app.command()
398 @update_sqlite_path
399 def update_user(email: str,
400 password: Optional[str] = None,
401 admin: Annotated[Optional[bool], typer.Option(
402 "--admin")] = False,
403 role: Optional[str] = None,
404 active: Annotated[Optional[bool],
405 typer.Option("--active/--inactive"
406 )] = None,
407 console: Optional[bool] = True,
408 json: Optional[bool] = False,
409 sqlite_path: Optional[str] = None,
410 ):
411 """Update internal user."""
412
413 data = dict()
414 if password:
415 if len(password) < 6:
416 print("Password must be at least 6 characters long.")
417 exit()
418 # validate_password relies on the new password being present as
419 # `newPassword` and `confirmPassword` in the data
420 data['newPassword'] = password
421 data['confirmPassword'] = password
422
423 if role is not None:
424 data['role'] = role
425 if admin:
426 data['role'] = 'Administrator'
427 if active is not None:
428 data['active'] = active
429
430 app = create_app(config.APP_NAME + '-cli')
431 with app.test_request_context():
432 rid = ManageRoles.get_role(data['role'])
433 if rid is None:
434 print("Role '{0}' does not exists.".format(data['role']))
435 exit()
436
437 data['role'] = rid
438
439 uid = ManageUsers.get_user(username=email,
440 auth_source=INTERNAL)
441 if not uid:
442 print(USER_NOT_FOUND_STR)
443 else:
444 status, msg = user_management_update_user(uid, data)
445 if status:
446 _user = ManageUsers.get_users_from_db(username=email,
447 auth_source=INTERNAL,
448 console=False)
449 ManageUsers.display_user(_user[0], console, json)
450 else:
451 print(SOMETHING_WENT_WRONG + str(msg))
452
453 @app.command()
454 @update_sqlite_path

Callers

nothing calls this directly

Calls 5

create_appFunction · 0.90
get_roleMethod · 0.80
get_users_from_dbMethod · 0.80
display_userMethod · 0.80
get_userMethod · 0.45

Tested by

no test coverage detected