Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Error when user roles is missing or is invalid #9040

Merged
merged 3 commits into from
Dec 19, 2017
Merged

[FIX] Error when user roles is missing or is invalid #9040

merged 3 commits into from
Dec 19, 2017

Conversation

paulovitin
Copy link
Contributor

@RocketChat/core

Closes #8958

Adds:

  • Check if roles is present in user and is valid array;
  • i18n messages;

@paulovitin paulovitin changed the title [FIX] When user roles is missing or invalid finish gracefully #8958 [FIX] When user roles is missing or invalid finish gracefully Dec 7, 2017
@@ -168,6 +168,12 @@ Accounts.validateLoginAttempt(function(login) {
});
}

if (!{}.hasOwnProperty.call(login.user, 'roles') || !Array.isArray(login.user.roles)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about others, but I find !{}.hasOwnProperty.call to be a tad confusing at first glance. Can we change this to something like if (login.user && (!login.user.roles || Array.isArray(login.user.roles)) {}?

Copy link
Contributor Author

@paulovitin paulovitin Dec 7, 2017

Choose a reason for hiding this comment

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

Sorry about that, I like to follow no-prototype-builtins.

But, in this code I needs to check the presence of property, !login.user.roles can be true if roles is false.

I know the value needs to be an array, but (!login.user.roles) is not better approach to check presence of property.

Copy link
Contributor

@graywolf336 graywolf336 Dec 7, 2017

Choose a reason for hiding this comment

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

Because if you look through the rest of our code base, you will see the style is how I mentioned. So, it's more about being consistent than anything to be honest.

@RocketChat/core can correct me if I am wrong though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should look at making part of our style guide if this is a more proper way of checking for the property?

But I do agree on we need to stay consistent, I don't think we use that elsewhere. Not to say we shouldn't... just we don't so does make it stick out.

Even a comment with a note about the style guide would help a bit in regards to readability here.

All for better code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree about the consistency of style. In this particular piece of code, even the user.roles is undef or null or false, we have the second criteria to check if is array, so this dont cause any bug.

But is good idea too make the things in most safety away. Is a good idea add this in style guide in future.

Copy link
Contributor

@geekgonecrazy geekgonecrazy Dec 7, 2017

Choose a reason for hiding this comment

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

I believe we have an issue discussing code style #1163 this would be good to add to discussion as something to include

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure @geekgonecrazy :)

Adds:
  - Check if roles is present in user and is valid array;
  - i18n messages;
@rodrigok rodrigok changed the title [FIX] When user roles is missing or invalid finish gracefully [FIX] Error when user roles is missing or is invalid Dec 19, 2017
@rodrigok rodrigok added this to the 0.60.0 milestone Dec 19, 2017
@rodrigok rodrigok merged commit 9ed2653 into RocketChat:develop Dec 19, 2017
rodrigok added a commit that referenced this pull request Dec 20, 2017
[FIX] Error when user roles is missing or is invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants