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

flatten associated users roles #1195

Merged
merged 1 commit into from Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions static_src/stores/user_store.js
Expand Up @@ -89,8 +89,7 @@ export class UserStore extends BaseStore {
case userActionTypes.USER_ORG_ASSOCIATED : {
this._inviteInputActive = true;
const user = Object.assign({}, {
guid: action.userGuid,
roles: { [action.entityGuid]: [] }
guid: action.userGuid
}, action.user);
this.associateUsersAndRolesToEntity([user], action.entityGuid,
'organization_roles');
Expand All @@ -101,8 +100,7 @@ export class UserStore extends BaseStore {
case userActionTypes.USER_SPACE_ASSOCIATED: {
this._inviteInputActive = true;
const user = Object.assign({}, action.user, {
guid: action.userGuid,
space_roles: { [action.entityGuid]: action.user.space_roles }
guid: action.userGuid
});
this.associateUsersAndRolesToEntity([user], action.entityGuid,
'space_roles');
Expand Down Expand Up @@ -385,9 +383,13 @@ export class UserStore extends BaseStore {
return this._loading.currentUser === true;
}

getDefaultUserInfo(user) {
return { guid: user.guid, username: user.username };
}

mergeRoles(roles, entityGuid, entityType) {
return roles.map((role) => {
const user = Object.assign({}, this.get(role.guid) || { guid: role.guid });
const user = Object.assign({}, this.get(role.guid) || this.getDefaultUserInfo(role));
const updatingRoles = role[entityType] || [];

if (entityType === 'space_roles') {
Expand Down
4 changes: 4 additions & 0 deletions static_src/test/unit/stores/user_store.spec.js
Expand Up @@ -159,6 +159,7 @@ describe('UserStore', function () {
const spaceUserRoles = [
{
guid: userGuidA,
username: "userA",
space_roles: [ 'space_developer' ]
},
{
Expand All @@ -169,16 +170,19 @@ describe('UserStore', function () {
const currentUsers = [
{
guid: userGuidB,
username: "userB",
space_roles: { [spaceGuid]: ['space_developer'] }
}
];
expectedUsers = [
{
guid: userGuidA,
username: "userA",
space_roles: { [spaceGuid]: ['space_developer'] }
},
{
guid: userGuidB,
username: "userB",
space_roles: { [spaceGuid]: ['space_developer', 'space_manager'] }
}
];
Expand Down