Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Add error message when Space user exists on Org user removal. #1163

Merged
merged 33 commits into from
Jul 24, 2017

Conversation

rememberlenny
Copy link
Contributor

spaceor

@@ -267,9 +269,9 @@ const userActionTypes = keymirror({
// Action when something goes wrong in user invite and email process.
USER_INVITE_ERROR: null,
// Action to display an invite notification
USER_INVITE_STATUS_DISPLAYED: null,
USER_INVITE_STATUS_CREATED: null,
// Action to dismiss an invite notification
Copy link
Contributor

Choose a reason for hiding this comment

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

update comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!

@@ -267,9 +269,9 @@ const userActionTypes = keymirror({
// Action when something goes wrong in user invite and email process.
USER_INVITE_ERROR: null,
// Action to display an invite notification
USER_INVITE_STATUS_DISPLAYED: null,
USER_INVITE_STATUS_CREATED: null,
Copy link
Contributor

@jcscottiii jcscottiii Jul 19, 2017

Choose a reason for hiding this comment

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

i think you meant to get rid of this since you created the new one above https://github.com/18F/cg-dashboard/pull/1163/files#diff-286a478a0e7b0544d442395e82edf6c1R262

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was intentional. I moved away from having multiple constants that result in a notification being displayed. Instead, there are multiple constants that lead to the preparation of a notification, but only one actual constant that leads to the creation of a notification. As a result, this one is changed to reflect the preparation of the invite specific notification.

).catch(res => {
const err = parseError(res);
if (res && res.response && res.response.status === 400) {
if (res.response.data.error_code === 'CF-AssociationNotEmpty') {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you combine these two conditionals into one long one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

const err = parseError(res);
if (res && res.response && res.response.status === 400) {
if (res.response.data.error_code === 'CF-AssociationNotEmpty') {
const description = 'This user can\'t be removed because they still have a Space ' +
Copy link
Contributor

Choose a reason for hiding this comment

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

Uncapitalize non-proper nouns.
s/Space/space
s/Organization/organization
s/User/user

also, spell out organization.
s/Org/organization

'role within the Organization. Please remove all Space ' +
'associations before removing this User from the Org.';
userActions.createUserSpaceAssociationNotification(description);
return Promise.reject(err);
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need this.

also, a noob JS question here, do you want to have a return on userActions.createUserSpaceAssociationNotification(description);?

Copy link
Contributor Author

@rememberlenny rememberlenny Jul 19, 2017

Choose a reason for hiding this comment

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

In this case, we dont need one. The createUserSpaceAssociationNotification kicks off the notification, but doesnt return anything.

Copy link
Contributor

@jcscottiii jcscottiii left a comment

Choose a reason for hiding this comment

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

a few changes

Copy link
Contributor

@el-mapache el-mapache left a comment

Choose a reason for hiding this comment

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

As a general note, I don't hate the name inviteNotice. userListInviteNotice basically ties the data to a specific component. Was it changed because the UserList is the only current component with the invite functionality?

});
},

createUserListNotification(noticeType, description) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should start writing new actions in this format:

type: RAD_TYPE,
data: {
  datum1: false,
  datum2: true
}

Then every action presents a consistent interface regardless of the information being passed in. What do you think?

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 think thats a good idea. It currently uses the ES6 syntax for exampling the variable name as the key. Instead of data, it does what you are describing with action. I think it would be a lot of refactoring to change them all.

Copy link
Contributor

Choose a reason for hiding this comment

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

i like the idea as well. but let's save that for a broader discussion.

},

createUserSpaceAssociationNotification(notification) {
const description = notification;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these are unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified

@jcscottiii jcscottiii requested a review from fureigh July 19, 2017 19:43
@rememberlenny
Copy link
Contributor Author

@el-mapache Regarding the naming, Im a proponent of breaking out a global notification action. For now, this is highly tied into the User List panel because of where it sits. I was proposing starting with a global notification component, but since we didnt go that route, I think its better to explicitly tie the functionality to the location.

// Action to display an invite notification
USER_INVITE_STATUS_DISPLAYED: null,
// Action to prepare an invite notification
USER_INVITE_STATUS_CREATED: null,
Copy link
Contributor

Choose a reason for hiding this comment

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

you dont need this. you have USER_LIST_NOTICE_CREATED

res.response.data.error_code === 'CF-AssociationNotEmpty'
);
if (errorConditions) {
const description = 'This user can\'t be removed because they still have a space ' +
Copy link
Contributor

@jcscottiii jcscottiii Jul 20, 2017

Choose a reason for hiding this comment

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

you don't have a test that calls deleteOrgUserPermissions and verifies that createUserSpaceAssociationNotification is called with the description

} else {
userActions.deleteUser(userGuid, orgGuid);
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

we need a catch here

James C. Scott and others added 2 commits July 20, 2017 17:47
jcscottiii
jcscottiii previously approved these changes Jul 20, 2017
Copy link
Contributor

@fureigh fureigh left a comment

Choose a reason for hiding this comment

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

Looking good! I added a few inline questions and comments. Once those are addressed, let's :shipit:.

});
if (usersSpaces.length > 0) {
const description = 'This user can\'t be removed because they still have a space ' +
'role within the organization. Please remove all space ' +
Copy link
Contributor

Choose a reason for hiding this comment

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

The natural response to "Please remove all space associations" is "How/where do I do that?" Let's add a link or a few words to point them in the right direction.

@@ -266,10 +268,8 @@ const userActionTypes = keymirror({
USER_ASSOCIATED_ORG_DISPLAYED: null,
// Action when something goes wrong in user invite and email process.
USER_INVITE_ERROR: null,
// Action to display an invite notification
USER_INVITE_STATUS_DISPLAYED: null,
// Action to dismiss an invite notification
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment still accurate?

@@ -1007,6 +1007,46 @@ describe('cfApi', function() {
done();
}).catch(done.fail);
});
describe('error handling', function() {
it('should return display a generic error if unsuccessful', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is return display the intended phrasing?

}).catch(done.fail);
});

it('should return display a notification about user having existing roles', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is return display the intended phrasing?

response: {error_code: 'CF-AssociationNotEmpty'},
});

const description = "This user can't be removed because they still " +
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that this will need to be updated if the other piece is.

@@ -386,9 +386,23 @@ export default {
.then(() => {
userActions.deletedUser(userGuid, orgGuid);
}).catch((err) => {
if (err.response.data) {
userActions.errorRemoveUser(userGuid, err.data);
// Check if we got caught on user roles in spaces
Copy link
Contributor

Choose a reason for hiding this comment

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

if --> whether

(not a big deal)

error.response.data.error_code === 'CF-AssociationNotEmpty'
);
if (userHasSpaceRoles) {
const description = 'This user can\'t be removed because they still have a space ' +
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar note as above.

@jcscottiii jcscottiii dismissed their stale review July 21, 2017 00:28

let's talk about the need for deleteUserIfNoSpaceAssociation

@rememberlenny
Copy link
Contributor Author

All the changes should be reflected! @jcscottiii @fureigh

@rememberlenny
Copy link
Contributor Author

Note: I added some new documentation in the cg-site repo to correspond with the instructions about managing users.

cloud-gov/cg-site#977

@jcscottiii
Copy link
Contributor

jcscottiii commented Jul 21, 2017

we need to talk because we have the description twice.
https://github.com/18F/cg-dashboard/pull/1163/files#diff-8a5ca76252b92305d2b0c5dece9c18fdR81

https://github.com/18F/cg-dashboard/pull/1163/files#diff-d45ddca2d392b7558d8957b40dd036ccR397

needs to be a constant or something

also, per my comment as to why i removed my approval last night

let's talk about the need for deleteUserIfNoSpaceAssociation

we need tests for that stuff.

@@ -386,9 +386,24 @@ export default {
.then(() => {
userActions.deletedUser(userGuid, orgGuid);
}).catch((err) => {
if (err.response.data) {
userActions.errorRemoveUser(userGuid, err.data);
// Check whether we got caught on user roles in spaces
Copy link
Contributor

@el-mapache el-mapache Jul 21, 2017

Choose a reason for hiding this comment

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

I think we can probably move this error handling up into the calling function, it gives us a little more flexibility in case we want to handle the error another way in different contexts.

@@ -60,6 +60,35 @@ const userActions = {
});
},

receivedOrgSpacesToExtractSpaceUsers(orgSpaces) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these methods need some tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added!

Copy link
Contributor

@fureigh fureigh left a comment

Choose a reason for hiding this comment

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

Thanks for those changes! I added some missing spaces in a quick commit (d9984cc).

LGTM, pending @el-mapache and @jcscottiii's comments being addressed.

@rememberlenny
Copy link
Contributor Author

Looks good!

@rememberlenny rememberlenny merged commit c447c73 into master Jul 24, 2017
@rememberlenny rememberlenny deleted the lkb-space-remove branch July 24, 2017 14:56
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