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

Conversation

bwindels
Copy link
Contributor

As the title says, I would like this option to be able to register non-admin users without interaction for the riot-web end-to-end tests, and thought it was a good way for a first synapse PR :)

Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

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

Woo, thanks, just a few nits

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.

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

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
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)

@richvdh
Copy link
Member

richvdh commented Sep 18, 2018

Fixes #2310

@spantaleev
Copy link
Contributor

Instead of having 2 different flags (--admin and --regular-user) and trying to detect conflicts, why not just:

  • drop the current --admin argument
  • introduce a new --type=admin|user argument, which defaults to 'user'.. Or defaults to None and asks interactively

It's backward-incompatible, but at least it does things cleanly.

@bwindels
Copy link
Contributor Author

Instead of having 2 different flags (--admin and --regular-user) and trying to detect conflicts, why not just:

* drop the current `--admin` argument

* introduce a new `--type=admin|user` argument, which defaults to `'user'`.. Or defaults to `None` and asks interactively

It's backward-incompatible, but at least it does things cleanly.

Opted for --no-admin because it's backwards compatible as you mentioned.

@bwindels
Copy link
Contributor Author

Not sure why the tests are failing though ...

@richvdh
Copy link
Member

richvdh commented Sep 19, 2018

Not sure why the tests are failing though ...

try merging latest develop; if nothing else, it will make circleci tell us why the tests are failing.

@spantaleev
Copy link
Contributor

As it is now:

  • case 1: if only --admin is passed, admin = True. This is ok. ✔️

  • case 2: if only --no-admin is passed, args.admin would be False and args.no_admin would be False (?!), which makes admin = False or False or None, which yields admin = None. This is wrong.. And the conditional is also very weird. ❌

  • case 3: if neither --admin, nor --no-admin is passed, args.admin would be False and args.no_admin would be True (?!), which makes admin = True. This is wrong. ❌

So it seems like it's generally wrong now and also backward-incompatible (see case 3).

@bwindels
Copy link
Contributor Author

Travis says:

Looking at these files:
----
1. /home/travis/build/matrix-org/synapse/scripts/register_new_matrix_user
----
No new newsfragments found on this branch.
ERROR: InvocationError for command '/home/travis/build/matrix-org/synapse/.tox/check-newsfragment/bin/python -m towncrier.check --compare-with=origin/develop' (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   check-newsfragment: commands failed
The command "tox -e $TOX_ENV" exited with 1.

@richvdh
Copy link
Member

richvdh commented Sep 20, 2018

No new newsfragments found on this branch.

In other words: "Please add a changelog fragment as per CONTRIBUTING.rst"

@bwindels
Copy link
Contributor Author

Not sure why the tests are failing, but trying if merging in develop helps ...

@bwindels bwindels changed the title add --regular-user flag to registration script add --no-admin flag to registration script Sep 27, 2018
@bwindels
Copy link
Contributor Author

Tests on Travis seem to have passed, but they're still appearing as pending here for some reason ...

@richvdh richvdh self-requested a review September 28, 2018 10:31
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm

@richvdh
Copy link
Member

richvdh commented Sep 28, 2018

Tests on Travis seem to have passed, but they're still appearing as pending here for some reason ...

this happens occasionally if there is a problem when Travis comes to send the memo to github that the builds completed. I've restarted them.

@richvdh
Copy link
Member

richvdh commented Sep 28, 2018

(thanks for bearing with us on this, @bwindels!)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants