Skip to content
Snippets Groups Projects
Commit dba1125d authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge remote-tracking branch 'gitlab.com/f-convenient-admin' into dev

parents 024c09b3 b85730f5
No related branches found
No related tags found
2 merge requests!33MAINT: change arguments of create_user,!17F convenient admin
Pipeline #11321 canceled
...@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### ### Changed ###
- It is possible now to supply a password for caosdb_admin on the command line and also activate the user directly using "-c".
### Deprecated ### ### Deprecated ###
* `id_query(ids)` in apiutils * `id_query(ids)` in apiutils
......
...@@ -116,13 +116,15 @@ def _promt_for_pw(): ...@@ -116,13 +116,15 @@ def _promt_for_pw():
def do_create_user(args): def do_create_user(args):
password = None password = args.user_password
if args.ask_password is True: if args.ask_password is True:
password = _promt_for_pw() password = _promt_for_pw()
try: try:
admin._insert_user(name=args.user_name, admin._insert_user(name=args.user_name,
email=args.user_email, password=password) email=args.user_email, password=password)
if args.activate_user:
do_activate_user(args)
except HTTPClientError as e: except HTTPClientError as e:
print(e.msg) print(e.msg)
...@@ -136,7 +138,10 @@ def do_deactivate_user(args): ...@@ -136,7 +138,10 @@ def do_deactivate_user(args):
def do_set_user_password(args): def do_set_user_password(args):
password = _promt_for_pw() if args.user_password is None:
password = _promt_for_pw()
else:
password = args.user_password
admin._update_user(name=args.user_name, password=password) admin._update_user(name=args.user_name, password=password)
...@@ -305,6 +310,8 @@ USAGE ...@@ -305,6 +310,8 @@ USAGE
subparser.set_defaults(call=do_create_user) subparser.set_defaults(call=do_create_user)
subparser.add_argument("-a", "--ask-password", subparser.add_argument("-a", "--ask-password",
help="Prompt for a password.", action="store_true") help="Prompt for a password.", action="store_true")
subparser.add_argument("-c", "--activate-user",
help="Activate the user after creation.", action="store_true")
subparser.add_argument( subparser.add_argument(
metavar='USERNAME', metavar='USERNAME',
dest="user_name", dest="user_name",
...@@ -314,6 +321,12 @@ USAGE ...@@ -314,6 +321,12 @@ USAGE
nargs='?', nargs='?',
dest="user_email", dest="user_email",
help="The email address of the new user.") help="The email address of the new user.")
subparser.add_argument(
metavar='PASSWORD',
nargs="?",
dest="user_password",
default=None,
help="The new user's password. This is overwritten by the -a option.")
subparser = subparsers.add_parser( subparser = subparsers.add_parser(
"activate_user", help="(Re-)activate an inactive (but existing) user.") "activate_user", help="(Re-)activate an inactive (but existing) user.")
...@@ -331,12 +344,18 @@ USAGE ...@@ -331,12 +344,18 @@ USAGE
subparser = subparsers.add_parser( subparser = subparsers.add_parser(
"set_user_password", "set_user_password",
help="Set a new password for a user. The password is not to be given on the command line for security reasons. You will be prompted for the password.") help="Set a new password for a user. You will be prompted for the password if PASSWORD is not given.")
subparser.set_defaults(call=do_set_user_password) subparser.set_defaults(call=do_set_user_password)
subparser.add_argument( subparser.add_argument(
metavar='USERNAME', metavar='USERNAME',
dest="user_name", dest="user_name",
help="The name of the user who's password is to be set.") help="The name of the user who's password is to be set.")
subparser.add_argument(
metavar='PASSWORD',
nargs="?",
dest="user_password",
default=None,
help="The user's new password.")
subparser = subparsers.add_parser( subparser = subparsers.add_parser(
"set_user_entity", "set_user_entity",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment