Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

fix(core): Client routes guest access bug #1100

Merged
merged 1 commit into from
Dec 31, 2015

Conversation

mleanos
Copy link
Member

@mleanos mleanos commented Dec 11, 2015

Adds a check for the existence of the "guest" role in the client route
state configuration of data.roles in the $stateChangeStart of core
client app init configuration.

If this role is present then it doesn't attempt to check authentication
on the route that is being transitioned to.

Fixes #1098

@@ -16,7 +16,7 @@ angular.module(ApplicationConfiguration.applicationModuleName).run(function ($ro

// Check authentication before changing state
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
if (toState.data && toState.data.roles && toState.data.roles.length > 0) {
if (toState.data && toState.data.roles && toState.data.roles.length > 0 && toState.data.roles.indexOf('guest') === -1) {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be moved to inside the forEach loop instead of the if statement?

I'm not a fan of iterating over an array to check if we need to iterate over an array.

Copy link
Member Author

Choose a reason for hiding this comment

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

@codydaig Sure. I originally had this check in the forEach loop. Then thought it would be more appropriate here; since it doesn't really make sense to go any further, if the state allows guest access.

I'll move it back down though. Just wanted to point out my reasoning here. Thanks for the comment.

@mleanos
Copy link
Member Author

mleanos commented Dec 16, 2015

@codydaig I've addressed your line comment.

@mleanos mleanos force-pushed the bugfix/ClientRoutes-Guest-Access branch from f63e9e7 to a560351 Compare December 17, 2015 02:19
@mleanos mleanos changed the title bugfix(core): Client routes guest access bug fix(core): Client routes guest access bug Dec 17, 2015
@codydaig
Copy link
Member

@mleanos Just to clarify: If the state it is transitioning too has the role 'guest' it doesn't check authentication anymore. Correct?

@mleanos
Copy link
Member Author

mleanos commented Dec 18, 2015

Well, it does check since the auth check is on the left-side of the || I suppose I should move the check for the guest role to the left-side.

In its its current state, this doesn`t enforce the authentication.

@lirantal lirantal added this to the 0.5.0 milestone Dec 18, 2015
@mleanos
Copy link
Member Author

mleanos commented Dec 22, 2015

@codydaig Did my last comment address what you were after?

@mleanos
Copy link
Member Author

mleanos commented Dec 28, 2015

@codydaig

@codydaig
Copy link
Member

LGTM

@@ -19,7 +19,7 @@ angular.module(ApplicationConfiguration.applicationModuleName).run(function ($ro
if (toState.data && toState.data.roles && toState.data.roles.length > 0) {
var allowed = false;
toState.data.roles.forEach(function (role) {
if (Authentication.user.roles !== undefined && Authentication.user.roles.indexOf(role) !== -1) {
if ((Authentication.user && Authentication.user.roles !== undefined && Authentication.user.roles.indexOf(role) !== -1) || (role === 'guest')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if this needs to be added, I would swap your logic, putting the role === 'guest' check first.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was waiting for clarification on that. It's probably more intuitive to have the guest role check first.

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean by "if this needs to be added"? Do you have another option, or suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was waiting for clarification on that. It's probably more intuitive to have the guest role check first.

and probably more optimized.

What do you mean by "if this needs to be added"? Do you have another option, or suggestion?

I haven't tested or know what issue you're fixing - just added my comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah ok. Just making sure ;) And yea, def more optimized. I'll go ahead amd get that changed.

Adds a check for the existence of the "guest" role in the state configuration
that we're transitioning to, in the core $stateChangeStart event handler. If
it exists, then we allow access.

Also, added validation of Authentication.user object. While writing
tests, I ran into an issue here when the Authentication service wasn't injected
into a controller. Probably best to have this check in place.

Fixes meanjs#1098
@mleanos mleanos force-pushed the bugfix/ClientRoutes-Guest-Access branch from a560351 to bfcfb55 Compare December 30, 2015 07:28
@rhutchison
Copy link
Contributor

LGTM

codydaig added a commit that referenced this pull request Dec 31, 2015
@codydaig codydaig merged commit 169d4cd into meanjs:master Dec 31, 2015
@mleanos mleanos deleted the bugfix/ClientRoutes-Guest-Access branch December 31, 2015 20:23
@mleanos
Copy link
Member Author

mleanos commented Dec 31, 2015

Thanks guys!

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

Successfully merging this pull request may close these issues.

4 participants