Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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: 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
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 @@ -16,7 +16,7 @@ export const UsersRolesActions = {

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 UsersRolesSetOrgRole implements Action {
Expand Down Expand Up @@ -58,4 +58,5 @@ export class UsersRolesSetChanges implements Action {

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

interface ChangeUserRoleByUsernameParams {
username: string;
origin?: string;
}

// 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
export class ChangeUserRole extends CFStartAction implements EntityRequestAction {
Expand All @@ -92,15 +98,17 @@ export class ChangeUserRole extends CFStartAction implements EntityRequestAction
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.createUrl(),
this.createParams()
);
this.entityType = isSpace ? spaceEntityType : organizationEntityType;
this.entity = cfEntityFactory(this.entityType);
Expand All @@ -115,6 +123,29 @@ export class ChangeUserRole extends CFStartAction implements EntityRequestAction
static generateUpdatingKey<T>(permissionType: OrgUserRoleNames | SpaceUserRoleNames, userGuid: string) {
return `${permissionType}/${userGuid}`;
}

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

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

return null;
}
}

export class AddUserRole extends ChangeUserRole {
Expand All @@ -125,7 +156,9 @@ export class AddUserRole extends ChangeUserRole {
permissionTypeKey: OrgUserRoleNames | SpaceUserRoleNames,
isSpace = false,
updateConnectedUser = false,
orgGuid?: string
orgGuid?: string,
username = '',
usernameOrigin = '',
) {
super(
endpointGuid,
Expand All @@ -136,7 +169,9 @@ export class AddUserRole extends ChangeUserRole {
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
@@ -1,10 +1,37 @@
import { OrchestratedActionBuilders } from '../../../store/src/entity-catalog/action-orchestrator/action-orchestrator';
import { GetAllOrgUsers } from '../actions/organization.actions';
import { GetAllSpaceUsers } from '../actions/space.actions';
import { GetAllUsersAsAdmin, GetUser } from '../actions/users.actions';
import { CFBasePipelineRequestActionMeta } from '../cf-entity-generator';
import { CFOrchestratedActionBuilders } from './cf.action-builder.types';

export const userActionBuilders = {
export interface UserActionBuilders extends CFOrchestratedActionBuilders {
get: (
guid: string,
endpointGuid: string
) => GetUser;
// Must be admin user for this to succeed.
getMultiple: (
endpointGuid: string,
paginationKey: string,
{ includeRelations, populateMissing }?: CFBasePipelineRequestActionMeta
) => GetAllUsersAsAdmin;
getAllInOrganization: (
guid: string,
endpointGuid: string,
paginationKey: string,
isAdmin: boolean,
includeRelations?: string[]
) => GetAllOrgUsers;
getAllInSpace: (
guid: string,
endpointGuid: string,
paginationKey: string,
isAdmin: boolean,
includeRelations?: string[]
) => GetAllSpaceUsers;
}

export const userActionBuilders: UserActionBuilders = {
get: (
guid,
endpointGuid
Expand All @@ -30,4 +57,4 @@ export const userActionBuilders = {
includeRelations?: string[]
) => new GetAllSpaceUsers(guid, paginationKey, endpointGuid, isAdmin, includeRelations),

} as OrchestratedActionBuilders;
};
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import { Store } from '@ngrx/store';
import { map } from 'rxjs/operators';

import { CF_ENDPOINT_TYPE } from '../../cf-types';
import { GetOrganization } from '../../actions/organization.actions';
import { GetSpace } from '../../actions/space.actions';
import {
cfUserEntityType,
organizationEntityType,
spaceEntityType,
} from '../../cf-entity-types';
import { getCFEntityKey } from '../../cf-entity-helpers';
import { entityCatalog } from '../../../../store/src/entity-catalog/entity-catalog.service';
import { APIResponse } from '../../../../store/src/actions/request.actions';
import { GeneralEntityAppState, GeneralRequestDataState, IRequestEntityTypeState } from '../../../../store/src/app-state';
import { entityCatalog } from '../../../../store/src/entity-catalog/entity-catalog.service';
import { deepMergeState, mergeEntity } from '../../../../store/src/helpers/reducer.helper';
import { selectPaginationState } from '../../../../store/src/selectors/pagination.selectors';
import { APIResource } from '../../../../store/src/types/api.types';
import { PaginatedAction, PaginationEntityState } from '../../../../store/src/types/pagination.types';
import { RequestEntityLocation, WrapperRequestActionSuccess } from '../../../../store/src/types/request.types';
import { deepMergeState, mergeEntity } from '../../../../store/src/helpers/reducer.helper';
import { GetOrganization } from '../../actions/organization.actions';
import { GetSpace } from '../../actions/space.actions';
import { getCFEntityKey } from '../../cf-entity-helpers';
import { cfUserEntityType, organizationEntityType, spaceEntityType } from '../../cf-entity-types';
import { CF_ENDPOINT_TYPE } from '../../cf-types';
import { CfUser, CfUserRoleParams, OrgUserRoleNames, SpaceUserRoleNames } from '../../store/types/user.types';
import {
createEntityRelationPaginationKey,
ValidateEntityResult,
ValidateResultFetchingState,
} from '../entity-relations.types';
import { CfUser, OrgUserRoleNames, CfUserRoleParams, SpaceUserRoleNames } from '../../store/types/user.types';

/**
* Add roles from (org|space)\[role\]\[user\] into user\[role\]
Expand Down Expand Up @@ -74,7 +70,7 @@ export function orgSpacePostProcess(
const userCatalogEntity = entityCatalog.getEntity(CF_ENDPOINT_TYPE, cfUserEntityType);
const { entityKey: cfUserEntityKey } = userCatalogEntity;
const users = entities[cfUserEntityKey];
const existingUsers = allEntities[cfOrgOrSpaceEntityKey];
const existingUsers = allEntities[cfUserEntityKey];

const newUsers = {};
if (cfOrgOrSpaceEntityKey === getCFEntityKey(organizationEntityType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import { Store } from '@ngrx/store';
import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs';
import { combineLatest, delay, distinct, filter, first, map, mergeMap, startWith, tap } from 'rxjs/operators';

import { CF_ENDPOINT_TYPE } from '../../../../../../cf-types';
import { AppMetadataTypes, GetAppStatsAction } from '../../../../../../../../cloud-foundry/src/actions/app-metadata.actions';
import { UpdateExistingApplication } from '../../../../../../../../cloud-foundry/src/actions/application.actions';
import { CFAppState } from '../../../../../../../../cloud-foundry/src/cf-app-state';
import { applicationEntityType, appStatsEntityType } from '../../../../../../../../cloud-foundry/src/cf-entity-types';
import { IAppSummary } from '../../../../../../../../core/src/core/cf-api.types';
import { CurrentUserPermissions } from '../../../../../../../../core/src/core/current-user-permissions.config';
import { entityCatalog } from '../../../../../../../../store/src/entity-catalog/entity-catalog.service';
import { EntityService } from '../../../../../../../../store/src/entity-service';
import { getFullEndpointApiUrl } from '../../../../../../../../core/src/features/endpoints/endpoint-helpers';
import { ConfirmationDialogConfig } from '../../../../../../../../core/src/shared/components/confirmation-dialog.config';
import { ConfirmationDialogService } from '../../../../../../../../core/src/shared/components/confirmation-dialog.service';
import { GitSCMService, GitSCMType } from '../../../../../../../../core/src/shared/data-services/scm/scm.service';
import { ENTITY_SERVICE } from '../../../../../../../../core/src/shared/entity.tokens';
import { ResetPagination } from '../../../../../../../../store/src/actions/pagination.actions';
import { entityCatalog } from '../../../../../../../../store/src/entity-catalog/entity-catalog.service';
import { EntityService } from '../../../../../../../../store/src/entity-service';
import { ActionState } from '../../../../../../../../store/src/reducers/api-request-reducer/types';
import { APIResource, EntityInfo } from '../../../../../../../../store/src/types/api.types';
import { CF_ENDPOINT_TYPE } from '../../../../../../cf-types';
import { ApplicationMonitorService } from '../../../../application-monitor.service';
import { ApplicationData, ApplicationService } from '../../../../application.service';
import { DEPLOY_TYPES_IDS } from '../../../../deploy-application/deploy-application-steps.types';
Expand Down
Loading