Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
559d697
WIP
richard-cox Feb 24, 2020
d0ae727
Part 1) Fix Org Service Entity Relations & Pagination Monitor Cacheing
richard-cox Feb 25, 2020
850625d
Ensure PaginationMonitorFactory passes in isLocal to PaginationMonitor
richard-cox Feb 26, 2020
8b011c2
WIP
richard-cox Feb 26, 2020
efe91d3
WIP
richard-cox Feb 27, 2020
850d853
WIP
richard-cox Feb 27, 2020
5c78664
Fix create-many script
richard-cox Mar 6, 2020
d0cd637
Merge remote-tracking branch 'origin/master' into add-role-by-username
richard-cox Mar 6, 2020
4740cb4
Merge remote-tracking branch 'origin/fix-org-relations' into add-role…
richard-cox Mar 6, 2020
c0a296e
Fix for org manage, space manager + refresh on space users page
richard-cox Mar 6, 2020
628050c
WIP
richard-cox Mar 9, 2020
dd4c8cf
WIP
richard-cox Mar 16, 2020
5a18798
Merge remote-tracking branch 'origin/master' into add-role-by-username
richard-cox Mar 17, 2020
a484978
Small Tidy Ups
richard-cox Mar 17, 2020
7e91e40
Merge remote-tracking branch 'origin/add-role-by-username' into remov…
richard-cox Mar 17, 2020
aa33d71
Fix remove and a few tidy ups
richard-cox Mar 17, 2020
a2735bb
Merge remote-tracking branch 'origin/master' into remove-role-by-user…
richard-cox Mar 17, 2020
761ba1d
Fix display of space roles in user list after adding by username
richard-cox Mar 17, 2020
b8bf2f9
Fix space manager add by username
richard-cox Mar 17, 2020
c7d85a5
Merge remote-tracking branch 'origin/master' into add-role-by-username
richard-cox Mar 18, 2020
b6e6f98
Fix unit tests
richard-cox Mar 18, 2020
f1a7885
Merge remote-tracking branch 'origin/add-role-by-username' into remov…
richard-cox Mar 18, 2020
a67f7a1
Merge remote-tracking branch 'origin/master' into add-role-by-username
richard-cox Mar 18, 2020
4a95015
Merge remote-tracking branch 'origin/add-role-by-username' into remov…
richard-cox Mar 18, 2020
6db3775
Fix unit test
richard-cox Mar 19, 2020
8ada952
Fixes following review
richard-cox Mar 23, 2020
c95740a
Feature Flag Permission Fixes
richard-cox Mar 24, 2020
df71cce
Ensure manage by user button is updated continuously
richard-cox Mar 25, 2020
105e000
Fix issue where setting stepper to remove mode isn't applied
richard-cox Mar 25, 2020
d179abe
Fix add/remove radio when can both add and remove
richard-cox Mar 25, 2020
4978108
Add e2e tests for add/remove roles by username at org/space level
richard-cox Mar 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions deploy/tools/init-cf-for-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,8 @@ fi
# Enable docker for deploy app from docker test
cf enable-feature-flag diego_docker

# Enable features for testing add/remove role via username
cf enable-feature-flag set_roles_by_username
cf enable-feature-flag unset_roles_by_username

echo "All done"
4 changes: 1 addition & 3 deletions deploy/tools/populate-cf/create-many-orgs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ while [ $counter -le $COUNT ]
do
ORG=$ORG_PREFIX-$counter
if [ "$DELETE" == "true" ]; then
# echo "DELETE $ORG"
cf delete-org $ORG
cf delete-org $ORG -f
else
# echo "CREATE $ORG"
cf create-org $ORG
fi

if [ "$SPACE_COUNT" != "" ]; then
# echo "$ORG SPACES: $SPACE_COUNT"
cf target -o $ORG
./create-many-spaces.sh -o "$ORG" -s "$ORG-spaces" -c $SPACE_COUNT -a 0 -r 0 -p "false"
fi
Expand Down
3 changes: 2 additions & 1 deletion protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ const manageUsersSuite = globby.sync([
'./src/test-e2e/cloud-foundry/space-level/space-users-removal-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/cf-level/cf-invite-config-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/org-level/org-invite-user-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/space-level/space-invite-user-e2e.spec.ts'
'./src/test-e2e/cloud-foundry/space-level/space-invite-user-e2e.spec.ts',
'./src/test-e2e/cloud-foundry/manage-users-by-username-stepper-e2e.spec.ts'
])

const coreSuite = globby.sync([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { HttpParams, HttpRequest } from '@angular/common/http';

import { IUpdateSpace } from '../../../core/src/core/cf-api.types';
import { getActions } from '../../../store/src/actions/action.helper';
import { PaginatedAction } from '../../../store/src/types/pagination.types';
import { ICFAction } from '../../../store/src/types/request.types';
import { CFEntityConfig } from '../cf-types';
import { cfEntityFactory } from '../cf-entity-factory';
import {
applicationEntityType,
Expand All @@ -15,6 +16,7 @@ import {
spaceEntityType,
spaceWithOrgEntityType,
} from '../cf-entity-types';
import { CFEntityConfig } from '../cf-types';
import {
createEntityRelationKey,
EntityInlineChildAction,
Expand All @@ -24,7 +26,6 @@ import { CFStartAction } from './cf-action.types';
import { GetAllOrgUsers } from './organization.actions';
import { RouteEvents } from './route.actions';
import { getServiceInstanceRelations } from './service-instances.actions';
import { HttpRequest, HttpParams } from '@angular/common/http';

export const GET_SPACES = '[Space] Get all';
export const GET_SPACES_SUCCESS = '[Space] Get all success';
Expand Down Expand Up @@ -231,7 +232,6 @@ export class GetAllSpaceUsers extends GetAllOrgUsers {
'GET',
`spaces/${guid}/user_roles`
);
this.flattenPaginationMax = 600;
}
actions = getActions('Spaces', 'List all user roles');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@ export const UsersRolesActions = {
SetOrg: '[Users Roles] Set org',
SetOrgRole: '[Users Roles] Set org role',
SetSpaceRole: '[Users Roles] Set space role',
FlipSetRoles: '[Users Roles] Flip Set Roles',
SetIsRemove: '[Users Roles] Set Is Remove',
SetIsSetByUsername: '[Users Roles] Set Is Set By Username',
SetChanges: '[Users Roles] Set role changes',
ExecuteChanges: '[Users Roles] Execute changes',
};

export class UsersRolesSetUsers implements Action {
type = UsersRolesActions.SetUsers;
constructor(public cfGuid: string, public users: CfUser[]) { }
constructor(public cfGuid: string, public users: CfUser[], public origin?: string) { }
}

export class UsersRolesFlipSetRoles implements Action {
type = UsersRolesActions.FlipSetRoles;
constructor() { }
}

export class UsersRolesSetIsRemove implements Action {
type = UsersRolesActions.SetIsRemove;
constructor(public isRemove: boolean) { }
}

export class UsersRolesSetIsSetByUsername implements Action {
type = UsersRolesActions.SetIsSetByUsername;
constructor(public isSetByUsername: boolean) { }
}

export class UsersRolesSetOrgRole implements Action {
Expand Down Expand Up @@ -58,4 +76,5 @@ export class UsersRolesSetChanges implements Action {

export class UsersRolesExecuteChanges implements Action {
type = UsersRolesActions.ExecuteChanges;
constructor(public setByUsername = false, public resetOrgUsers?: string, public resetSpaceUsers?: string) { }
}
79 changes: 68 additions & 11 deletions src/frontend/packages/cloud-foundry/src/actions/users.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,47 @@ export class GetAllUsersAsAdmin extends CFStartAction implements PaginatedAction
return !!action.isGetAllUsersAsAdmin;
}
}

interface HttpParamsPayload {
[param: string]: string;
}
interface ChangeUserRoleByUsernameParams extends HttpParamsPayload {
username: string;
origin?: string;
}
enum ChangeUserRoleType {
ADD,
REMOVE
}


// FIXME: These actions are user related however return either an org or space entity. These responses can be ignored and not stored, need
// a flag somewhere to handle that - https://jira.capbristol.com/browse/STRAT-119
/**
* Add or remove a user's role, either by user guid or name
*/
export class ChangeUserRole extends CFStartAction implements EntityRequestAction {
public endpointType = 'cf';
constructor(
public endpointGuid: string,
public userGuid: string,
public method: 'PUT' | 'DELETE',
public changeRoleType: ChangeUserRoleType,
public actions: string[],
public permissionTypeKey: OrgUserRoleNames | SpaceUserRoleNames,
public entityGuid: string,
public isSpace = false,
public updateConnectedUser = false,
public orgGuid?: string
public orgGuid?: string,
public username = '',
public usernameOrigin = '',
) {
super();
this.guid = entityGuid;
this.updatingKey = ChangeUserRole.generateUpdatingKey(permissionTypeKey, userGuid);
this.options = new HttpRequest(
method,
`${isSpace ? 'spaces' : 'organizations'}/${this.guid}/${this.updatingKey}`,
{}
this.createMethod(),
this.createUrl(),
this.createParams()
);
this.entityType = isSpace ? spaceEntityType : organizationEntityType;
this.entity = cfEntityFactory(this.entityType);
Expand All @@ -115,6 +134,36 @@ export class ChangeUserRole extends CFStartAction implements EntityRequestAction
static generateUpdatingKey<T>(permissionType: OrgUserRoleNames | SpaceUserRoleNames, userGuid: string) {
return `${permissionType}/${userGuid}`;
}

createMethod(): string {
if (this.changeRoleType === ChangeUserRoleType.ADD) {
return 'PUT';
}
return this.username ? 'POST' : 'DELETE';
}

createUrl(): string {
const spaceOrOrg = this.isSpace ? 'spaces' : 'organizations';
if (this.username) {
// Change role via the username url
return `${spaceOrOrg}/${this.guid}/${this.permissionTypeKey}${this.changeRoleType === ChangeUserRoleType.REMOVE ? '/remove' : ''}`;
} else {
return `${spaceOrOrg}/${this.guid}/${this.updatingKey}`;
}
}

createParams(): object {
if (this.username) {
const payload: ChangeUserRoleByUsernameParams = {
username: this.username,
};
if (this.usernameOrigin) {
payload.origin = this.usernameOrigin;
}
return payload;
}
return null;
}
}

export class AddUserRole extends ChangeUserRole {
Expand All @@ -125,18 +174,22 @@ export class AddUserRole extends ChangeUserRole {
permissionTypeKey: OrgUserRoleNames | SpaceUserRoleNames,
isSpace = false,
updateConnectedUser = false,
orgGuid?: string
orgGuid?: string,
username = '',
usernameOrigin = '',
) {
super(
endpointGuid,
userGuid,
'PUT',
ChangeUserRoleType.ADD,
[ADD_ROLE, ADD_ROLE_SUCCESS, ADD_ROLE_FAILED],
permissionTypeKey,
entityGuid,
isSpace,
updateConnectedUser,
orgGuid
orgGuid,
username,
usernameOrigin
);
}
}
Expand All @@ -149,18 +202,22 @@ export class RemoveUserRole extends ChangeUserRole {
permissionTypeKey: OrgUserRoleNames | SpaceUserRoleNames,
isSpace = false,
updateConnectedUser = false,
orgGuid?: string
orgGuid?: string,
username = '',
usernameOrigin = '',
) {
super(
endpointGuid,
userGuid,
'DELETE',
ChangeUserRoleType.REMOVE,
[REMOVE_ROLE, REMOVE_ROLE_SUCCESS, REMOVE_ROLE_FAILED],
permissionTypeKey,
entityGuid,
isSpace,
updateConnectedUser,
orgGuid
orgGuid,
username,
usernameOrigin
);
}
}
Expand Down
87 changes: 38 additions & 49 deletions src/frontend/packages/cloud-foundry/src/cf-entity-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,45 @@ const ApplicationWithoutSpaceEntitySchema = new CFApplicationEntitySchema(
}
);

const CFUserSchema = new CFUserEntitySchema({
entity: {
organizations: [createUserOrgSpaceSchema(organizationEntityType, {}, CfUserRoleParams.ORGANIZATIONS)],
audited_organizations: [createUserOrgSpaceSchema(organizationEntityType, {}, CfUserRoleParams.AUDITED_ORGS)],
managed_organizations: [createUserOrgSpaceSchema(organizationEntityType, {}, CfUserRoleParams.MANAGED_ORGS)],
billing_managed_organizations: [createUserOrgSpaceSchema(organizationEntityType, {}, CfUserRoleParams.BILLING_MANAGER_ORGS)],
spaces: [createUserOrgSpaceSchema(spaceEntityType, {}, CfUserRoleParams.SPACES)],
managed_spaces: [createUserOrgSpaceSchema(spaceEntityType, {}, CfUserRoleParams.MANAGED_SPACES)],
audited_spaces: [createUserOrgSpaceSchema(spaceEntityType, {}, CfUserRoleParams.AUDITED_SPACES)],
}
}, {
idAttribute: getAPIResourceGuid,
processStrategy: (user: APIResource<CfUser>) => {
if (user.entity.username) {
return user;
}
const entity = {
...user.entity,
username: user.metadata.guid
};

return user.metadata ? {
entity,
metadata: user.metadata
} : {
entity
};
}
});
entityCache[cfUserEntityType] = CFUserSchema;

const coreSpaceSchemaParams = {
routes: [RouteSchema],
domains: [DomainSchema],
space_quota_definition: SpaceQuotaSchema,
service_instances: [ServiceInstancesSchema],
[SpaceUserRoleNames.DEVELOPER]: [
new CFEntitySchema(cfUserEntityType, {}, { idAttribute: getAPIResourceGuid }, SpaceUserRoleNames.DEVELOPER)
],
[SpaceUserRoleNames.MANAGER]: [new CFUserEntitySchema(undefined, undefined, SpaceUserRoleNames.MANAGER)],
[SpaceUserRoleNames.AUDITOR]: [new CFUserEntitySchema(undefined, undefined, SpaceUserRoleNames.AUDITOR)]
[SpaceUserRoleNames.DEVELOPER]: [CFUserSchema],
[SpaceUserRoleNames.MANAGER]: [CFUserSchema],
[SpaceUserRoleNames.AUDITOR]: [CFUserSchema]
};
const SpaceSchema = new CFSpaceEntitySchema({
entity: {
Expand Down Expand Up @@ -226,12 +255,10 @@ const OrganizationSchema = new CFOrgEntitySchema({
entity: {
...coreOrgSchemaParams,
spaces: [SpaceSchema],
[OrgUserRoleNames.USER]: [new CFUserEntitySchema(undefined, undefined, OrgUserRoleNames.USER)],
[OrgUserRoleNames.MANAGER]: [new CFUserEntitySchema(undefined, undefined, OrgUserRoleNames.MANAGER)],
[OrgUserRoleNames.BILLING_MANAGERS]: [
new CFUserEntitySchema(undefined, undefined, OrgUserRoleNames.BILLING_MANAGERS)
],
[OrgUserRoleNames.AUDITOR]: [new CFUserEntitySchema(undefined, undefined, OrgUserRoleNames.AUDITOR)]
[OrgUserRoleNames.USER]: [CFUserSchema],
[OrgUserRoleNames.MANAGER]: [CFUserSchema],
[OrgUserRoleNames.BILLING_MANAGERS]: [CFUserSchema],
[OrgUserRoleNames.AUDITOR]: [CFUserSchema]
}
});
entityCache[organizationEntityType] = OrganizationSchema;
Expand Down Expand Up @@ -300,51 +327,13 @@ entityCache[securityGroupEntityType] = SecurityGroupSchema;
const FeatureFlagSchema = new CFEntitySchema(featureFlagEntityType, {}, { idAttribute: 'name' });
entityCache[featureFlagEntityType] = FeatureFlagSchema;

const SpaceEmptySchema = SpaceSchema.withEmptyDefinition();
const orgUserEntity = {
entity: {
spaces: [SpaceEmptySchema]
}
};

const ServiceBrokerSchema = new CFEntitySchema(serviceBrokerEntityType, {}, { idAttribute: getAPIResourceGuid });
entityCache[serviceBrokerEntityType] = ServiceBrokerSchema;

function createUserOrgSpaceSchema(schemaKey, entity, relationKey): EntitySchema {
return new CFEntitySchema(schemaKey, entity, { idAttribute: getAPIResourceGuid }, relationKey);
}

const CFUserSchema = new CFUserEntitySchema({
entity: {
organizations: [createUserOrgSpaceSchema(organizationEntityType, orgUserEntity, CfUserRoleParams.ORGANIZATIONS)],
audited_organizations: [createUserOrgSpaceSchema(organizationEntityType, orgUserEntity, CfUserRoleParams.AUDITED_ORGS)],
managed_organizations: [createUserOrgSpaceSchema(organizationEntityType, orgUserEntity, CfUserRoleParams.MANAGED_ORGS)],
billing_managed_organizations: [createUserOrgSpaceSchema(organizationEntityType, orgUserEntity, CfUserRoleParams.BILLING_MANAGER_ORGS)],
spaces: [createUserOrgSpaceSchema(spaceEntityType, {}, CfUserRoleParams.SPACES)],
managed_spaces: [createUserOrgSpaceSchema(spaceEntityType, {}, CfUserRoleParams.MANAGED_SPACES)],
audited_spaces: [createUserOrgSpaceSchema(spaceEntityType, {}, CfUserRoleParams.AUDITED_SPACES)],
}
}, {
idAttribute: getAPIResourceGuid,
processStrategy: (user: APIResource<CfUser>) => {
if (user.entity.username) {
return user;
}
const entity = {
...user.entity,
username: user.metadata.guid
};

return user.metadata ? {
entity,
metadata: user.metadata
} : {
entity
};
}
});
entityCache[cfUserEntityType] = CFUserSchema;


const UserProvidedServiceInstanceSchema = new CFEntitySchema(userProvidedServiceInstanceEntityType, {
entity: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ function generateCFServiceBindingEntity(endpointDefinition: StratosEndpointExten
actionBuilders: serviceBindingActionBuilders,
entityBuilder: {
getMetadata: ent => ({
name: ent.entity.guid
name: ent.metadata.guid
}),
getGuid: metadata => metadata.guid,
}
Expand Down Expand Up @@ -617,7 +617,7 @@ function generateCFUserEntity(endpointDefinition: StratosEndpointExtensionDefini
dataReducers: [userReducer, endpointDisconnectUserReducer],
entityBuilder: {
getMetadata: ent => ({
name: ent.entity.username || ent.entity.guid
name: ent.entity.username || ent.entity.guid || ent.metadata.guid
}),
getGuid: metadata => metadata.guid,
}
Expand Down
Loading