Skip to content

Conversation

@abhishekkumar2718
Copy link
Contributor

api.register now uses auth_body, kind and **kwargs.
Closes #213

@non-Jedi
Copy link
Collaborator

Thanks for the patch. Signoff please (Haven't yet reviewed).

@abhishekkumar2718
Copy link
Contributor Author

Signed-off-by: Abhishek Kumar abhishekkumar2718@gmail.com

Copy link
Collaborator

@non-Jedi non-Jedi left a comment

Choose a reason for hiding this comment

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

Other than small change, this looks good! Thanks for contributing. :)

self.validate_cert = valid

def register(self, content=None, kind='user'):
def register(self, auth_body, kind, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's explicitly list all the possible kwargs here. bind_email, username, password device_id, and initial_device_display_name.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if it was clear before. I want the following listed in the function signature; not just the docstring. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't that defeat the point of using kwargs ?
I think you mean a function signature like register(self, auth_body, bind_email=None, ...)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep. I think this method would be better without kwargs with each possible top-level key listed explicitly. Just like you showed, yes.

Copy link
Collaborator

@non-Jedi non-Jedi left a comment

Choose a reason for hiding this comment

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

Getting a lot closer. :)

auth_body (dict): Authentication Params.
kind (str): Specify kind of account to register.
bind_email (bool): Whether to use email in registration and authenication
username (str): The localpart of an Matrix ID.
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be "a Matrix ID" not "an"

if content is None:
auth_body (dict): Authentication Params.
kind (str): Specify kind of account to register.
bind_email (bool): Whether to use email in registration and authenication
Copy link
Collaborator

Choose a reason for hiding this comment

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

spelling: "authentication"

"""
if content is None:
auth_body (dict): Authentication Params.
kind (str): Specify kind of account to register.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to note that this is one of "guest" or "user".

"inhibit_login": inhibit_login,
"bind_email": bind_email,
}
if username:
Copy link
Collaborator

Choose a reason for hiding this comment

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

If no auth_body is given, content won't exist yet. Need to instantiate content before any of these if statements.

initial_device_display_name (str): Display name to be assigned.
"""
if auth_body:
content = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should just be if auth_body: content["auth"] = auth_body

def register(self, content=None, kind='user'):
def register(self, auth_body=None, kind="user", bind_email=False,
username=None, password=None, device_id=None,
initial_device_display_name=None, inhibit_login=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please set bind_email and inhibit_login to None default values. If user doesn't explicitly set them, body of JSON sent shouldn't include those keys.

content["device_id"] = device_id
if initial_device_display_name:
content["initial_device_display_name"] = \
initial_device_display_name
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to add similar statements to above for bind_email and inhibit_login.

@non-Jedi
Copy link
Collaborator

non-Jedi commented Sep 7, 2018

LGTM. If you can squash down to one commit, I'll go ahead and merge. Thanks!

Copy link
Contributor

@Zil0 Zil0 left a comment

Choose a reason for hiding this comment

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

Two small things and then we'll be good. Thanks!

username (str): The localpart of a Matrix ID.
password (str): The desired password of the account.
device_id (str): ID of the client device.
initial_device_display_name (str): Display name to be assigned.
Copy link
Contributor

Choose a reason for hiding this comment

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

This list lacks inhibit_login.

Args:
login_type (str): The value for the 'type' key.
**kwargs: Additional key/values to add to the JSON submitted.
**kwargs: Additional key/values to add to JSON submitted.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this change.

Refactored api.register to use auth_body and **kwargs.

Fixed silly PEP8 mistakes.

Expanded keyword arguments in the doc string

Fixed PEP8 Trailing Whitespace error

Explicitly listed key word arguments

Explicitly listed keyword arguments

Final finishes

Refactored api.register to use auth_body and **kwargs

Minor documentation fixes.

Refactored api.register to use auth_body and **kwargs.
@Zil0 Zil0 merged commit f46b5b3 into matrix-org:master Oct 4, 2018
@Zil0
Copy link
Contributor

Zil0 commented Oct 4, 2018

Merged, thanks for the time you spent on this :)

@abhishekkumar2718 abhishekkumar2718 deleted the refactor_api branch October 14, 2018 20:16
@abhishekkumar2718
Copy link
Contributor Author

It was my pleasure! Onto the next open issue. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants