From ceec6ce5f47868d3a0f6426469dd4f12701b4738 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 10 Sep 2018 19:32:56 +0200 Subject: [PATCH 1/7] add --regular-user flag to registration script --- scripts/register_new_matrix_user | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/register_new_matrix_user b/scripts/register_new_matrix_user index 8c3d429351c4..ebda158fb192 100755 --- a/scripts/register_new_matrix_user +++ b/scripts/register_new_matrix_user @@ -133,7 +133,7 @@ def register_new_user(user, password, server_location, shared_secret, admin): print "Passwords do not match" sys.exit(1) - if not admin: + if admin is None: admin = raw_input("Make admin [no]: ") if admin in ("y", "yes", "true"): admin = True @@ -163,7 +163,12 @@ if __name__ == "__main__": parser.add_argument( "-a", "--admin", action="store_true", - help="Register new user as an admin. Will prompt if omitted.", + help="Register new user as an admin. Will prompt if --regular-user is not set.", + ) + parser.add_argument( + "--regular-user", + action="store_true", + help="Register new user as a regular user.", ) group = parser.add_mutually_exclusive_group(required=True) @@ -197,4 +202,10 @@ if __name__ == "__main__": else: secret = args.shared_secret - register_new_user(args.user, args.password, args.server_url, secret, args.admin) + if args.admin and args.regular_user: + print "Both --admin and --regular-user are set, choose either." + sys.exit(1) + + admin = True if args.admin else False if args.regular_user else None + + register_new_user(args.user, args.password, args.server_url, secret, admin) From 4311f861a35d2f958cd9729f9e067d36466a36b7 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 19 Sep 2018 12:30:32 +0200 Subject: [PATCH 2/7] fix PR review --- scripts/register_new_matrix_user | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/scripts/register_new_matrix_user b/scripts/register_new_matrix_user index ebda158fb192..b2cf5aeadfe7 100755 --- a/scripts/register_new_matrix_user +++ b/scripts/register_new_matrix_user @@ -160,14 +160,15 @@ if __name__ == "__main__": default=None, help="New password for user. Will prompt if omitted.", ) - parser.add_argument( + admin_group = parser.add_mutually_exclusive_group() + admin_group.add_argument( "-a", "--admin", action="store_true", - help="Register new user as an admin. Will prompt if --regular-user is not set.", + help="Register new user as an admin. Will prompt if --no-admin is not set.", ) - parser.add_argument( - "--regular-user", - action="store_true", + admin_group.add_argument( + "--no-admin", + action="store_false", help="Register new user as a regular user.", ) @@ -202,10 +203,6 @@ if __name__ == "__main__": else: secret = args.shared_secret - if args.admin and args.regular_user: - print "Both --admin and --regular-user are set, choose either." - sys.exit(1) - - admin = True if args.admin else False if args.regular_user else None + admin = args.admin or not args.no_admin or None register_new_user(args.user, args.password, args.server_url, secret, admin) From d4c389f0e42ac91ab92cfa19e43ed67a77836756 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 19 Sep 2018 13:22:19 +0200 Subject: [PATCH 3/7] remove not as the flags is set to false --- scripts/register_new_matrix_user | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/register_new_matrix_user b/scripts/register_new_matrix_user index b2cf5aeadfe7..166c03b000ee 100755 --- a/scripts/register_new_matrix_user +++ b/scripts/register_new_matrix_user @@ -203,6 +203,6 @@ if __name__ == "__main__": else: secret = args.shared_secret - admin = args.admin or not args.no_admin or None + admin = args.admin or args.no_admin or None register_new_user(args.user, args.password, args.server_url, secret, admin) From 81b56f807848784ebf62175b064ee2f472b1dbbe Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 19 Sep 2018 18:18:08 +0200 Subject: [PATCH 4/7] make clear in help text when will be prompted --- scripts/register_new_matrix_user | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/register_new_matrix_user b/scripts/register_new_matrix_user index 166c03b000ee..21cec7f36767 100755 --- a/scripts/register_new_matrix_user +++ b/scripts/register_new_matrix_user @@ -164,12 +164,12 @@ if __name__ == "__main__": admin_group.add_argument( "-a", "--admin", action="store_true", - help="Register new user as an admin. Will prompt if --no-admin is not set.", + help="Register new user as an admin. Will prompt if --no-admin is not set either.", ) admin_group.add_argument( "--no-admin", action="store_false", - help="Register new user as a regular user.", + help="Register new user as a regular user. Will prompt if --admin is not set either.", ) group = parser.add_mutually_exclusive_group(required=True) From bd37c4a444e000e19b13e58b3d6b57cf64bab038 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 19 Sep 2018 20:55:26 +0200 Subject: [PATCH 5/7] fix logic, store_true/false doesn't set None by default but opposite bool --- scripts/register_new_matrix_user | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/register_new_matrix_user b/scripts/register_new_matrix_user index 21cec7f36767..3b4254197bfa 100755 --- a/scripts/register_new_matrix_user +++ b/scripts/register_new_matrix_user @@ -133,6 +133,7 @@ def register_new_user(user, password, server_location, shared_secret, admin): print "Passwords do not match" sys.exit(1) + print admin if admin is None: admin = raw_input("Make admin [no]: ") if admin in ("y", "yes", "true"): @@ -168,7 +169,7 @@ if __name__ == "__main__": ) admin_group.add_argument( "--no-admin", - action="store_false", + action="store_true", help="Register new user as a regular user. Will prompt if --admin is not set either.", ) @@ -203,6 +204,8 @@ if __name__ == "__main__": else: secret = args.shared_secret - admin = args.admin or args.no_admin or None + admin = None + if args.admin or args.no_admin: + admin = args.admin register_new_user(args.user, args.password, args.server_url, secret, admin) From 48957d2c8c666c581da9a1e1c66c31a91b9ccde5 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 19 Sep 2018 20:57:00 +0200 Subject: [PATCH 6/7] didnt mean to commit this, obviously --- scripts/register_new_matrix_user | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/register_new_matrix_user b/scripts/register_new_matrix_user index 3b4254197bfa..91bdb3a25bd8 100755 --- a/scripts/register_new_matrix_user +++ b/scripts/register_new_matrix_user @@ -133,7 +133,6 @@ def register_new_user(user, password, server_location, shared_secret, admin): print "Passwords do not match" sys.exit(1) - print admin if admin is None: admin = raw_input("Make admin [no]: ") if admin in ("y", "yes", "true"): From a776ccd8f58e39dfdf145495d4ec082bb36df075 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 21 Sep 2018 12:51:55 +0200 Subject: [PATCH 7/7] add changelog --- changelog.d/3836.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/3836.bugfix diff --git a/changelog.d/3836.bugfix b/changelog.d/3836.bugfix new file mode 100644 index 000000000000..add49fbec0d5 --- /dev/null +++ b/changelog.d/3836.bugfix @@ -0,0 +1 @@ +support registering regular users non-interactively with register_new_matrix_user script \ No newline at end of file