Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

add --no-admin flag to registration script #3836

Merged
merged 9 commits into from
Sep 28, 2018
17 changes: 14 additions & 3 deletions scripts/register_new_matrix_user
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traditionally this would probably be called --no-admin, to make it clearer that its the opposite of --admin.

action="store_true",
help="Register new user as a regular user.",
)

group = parser.add_mutually_exclusive_group(required=True)
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than doing this manually, we should probably use the inbuilt argparse conflict functionality: https://docs.python.org/2/howto/argparse.html#conflicting-options


admin = True if args.admin else False if args.regular_user else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly can't remember how multiple if statements like this work, can we write split it out into actual if statements please?

(You can also write this as args.admin or args.regular_user or None, but that's a bit special too)


register_new_user(args.user, args.password, args.server_url, secret, admin)