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,
)
| 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 |
nothing calls this directly
no test coverage detected