Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

User role homescreen #945

Merged
merged 23 commits into from
Mar 15, 2017
Merged

User role homescreen #945

merged 23 commits into from
Mar 15, 2017

Conversation

tangollama
Copy link
Member

@jkleinsc this is for review, not necessarily for merging. The idea here is to overcome the feature issue (and therefore usability concern) of users logging into a back “what do you want to do?” screen. Let’s discuss.

@tangollama
Copy link
Member Author

@jkleinsc can you review this PR for the purposes of getting into 1.0?

Copy link
Member

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

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

@tangollama there are some code changes needed as I've explained in my comments.

Also, I have added an acceptance test that should pass if you make the suggested changes.

})
}),

findNavItemByRoute: function(route) {
Copy link
Member

Choose a reason for hiding this comment

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

This is failing eslint checks. It should be written as:

findNavItemByRoute(route) {

if (el.route == route) {
return el;
} else {
for (var j = 0; j < el.subnav.length; j++) {
Copy link
Member

Choose a reason for hiding this comment

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

This line is also failing eslint. Use let instead of var. Actually you should use a foreach instead, eg:

el.subnav.forEach((item) => {
});

@@ -1,6 +1,34 @@
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import Navigation from 'hospitalrun/mixins/navigation';
import SetupUserRole from 'hospitalrun/mixins/setup-user-role';
Copy link
Member

Choose a reason for hiding this comment

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

This mixin isn't used in this route.

export default Ember.Route.extend(AuthenticatedRouteMixin, Navigation, SetupUserRole, UserRoles, {
session: inject.service(),
beforeModel() {
// this.setupUserRole();
Copy link
Member

Choose a reason for hiding this comment

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

Commented out code should be removed.

let session = this.get('session');
if (session != null) {
let role = session.get('data.authenticated.userRole');
if (role != null) {
Copy link
Member

Choose a reason for hiding this comment

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

I would use isEmpty instead of != null.
Eg

const { isEmpty } = Ember;  <- Declare this after the imports

then in your code:

if (!isEmpty(role)) {

@@ -3,6 +3,7 @@ export default Ember.Mixin.create({
setupUserRole() {
let session = this.get('session');
let userRole = session.get('data.authenticated.role');
session.set('data.authenticated.userRole', userRole);
Copy link
Member

Choose a reason for hiding this comment

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

Why not just pull the user's role from data.authenticated.role? Why double store it?

}),

findNavItemByRoute: function(route) {
return this.navItems.find(function(el) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you want to use find here. According to the docs
find "Returns the first item in the array for which the callback returns true". You are not returning true anywhere here and the way this code is written, if the item is found in a subnav item, it is going to return the parent item, not the subnav item. You could accomplish what you need with forEach loops.

// this.setupUserRole();
let session = this.get('session');
if (session != null) {
let role = session.get('data.authenticated.userRole');
Copy link
Member

Choose a reason for hiding this comment

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

This should pull data.authenticated.role not data.authenticated.userRole, particularly if you want the acceptance test I added to pass. 😄

jkleinsc and others added 7 commits February 22, 2017 17:22
Removed commented out code, using isEmpty, removing unused import
Using isEqual and cleaning up the formatting of the looping structure.
Not needed. Thx for the feedback @jkleinsc
@tangollama
Copy link
Member Author

@jkleinsc I think I've satisfied the requested changes. Happy to discuss the why's Monday.

@tangollama
Copy link
Member Author

@jkleinsc All 16 acceptance tests pass for this locally (http://localhost:4200/tests?filter=Testing%20User%20Role%20homescreen). Travis appears to be timing out with a few of these. What shall we do?

Moved user administrator role test to users-test because it needs the
fake rest calls defined there.
@jkleinsc jkleinsc merged commit c2afff6 into master Mar 15, 2017
@stukalin stukalin deleted the user-role-homescreen branch August 29, 2018 07:50
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.

2 participants