Skip to content

Commit

Permalink
Merge pull request #554 from SUSE/workaround-normalizr-bug
Browse files Browse the repository at this point in the history
Fix two role bugs related to Non-admins missing roles in Organisation Users page
  • Loading branch information
richard-cox committed May 3, 2022
2 parents 878c66b + 31f923f commit 7370d74
Show file tree
Hide file tree
Showing 19 changed files with 687 additions and 20 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"ngrx-store-localstorage": "10.1.1",
"ngx-moment": "^3.5.0",
"ngx-monaco-editor": "^9.0.0",
"normalizr": "^3.6.0",
"reselect": "^4.0.0",
"rxjs": "^6.6.3",
"rxjs-spy": "^7.5.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, schema } from 'normalizr';
import { Schema, schema } from '../../../store/src/normalizr/normalizr';

import { getAPIResourceGuid } from '../../../cloud-foundry/src/store/selectors/api.selectors';
import { EntitySchema } from '../../../store/src/helpers/entity-schema';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, schema } from 'normalizr';
import { Schema, schema } from '../../store/src/normalizr/normalizr';

import { EntitySchema } from '../../store/src/helpers/entity-schema';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ describe('Entity Relations - validate -', () => {

advancedSetup(store => {
store.requestData[orgEntityKey][orgGuid].entity.spaces = [space];
// Ensure the space exists in the store so when we denormalize it can correctly find it
store.requestData[spaceEntityKey][space.metadata.guid] = space;
return store;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Action, Store } from '@ngrx/store';
import { denormalize } from 'normalizr';
import { denormalize } from '../../../store/src/normalizr/normalizr';
import { Observable, of as observableOf } from 'rxjs';
import { filter, first, map, mergeMap, pairwise, skipWhile, switchMap, withLatestFrom } from 'rxjs/operators';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function hasSpaceRoleWithinOrg(user: CfUser, orgGuid: string): boolean {
const orgSpaces = [];

for (const role of roles) {
const roleSpaces = user[role] as APIResource<ISpace>[];
const roleSpaces = (user[role] || []) as APIResource<ISpace>[];

orgSpaces.push(...roleSpaces.filter((space) => {
return space.entity.organization_guid === orgGuid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, OnInit } from '@angular/core';
import { schema } from 'normalizr';
import { schema } from '../../../../../store/src/normalizr/normalizr';
import { never as observableNever, Observable, of as observableOf } from 'rxjs';
import { map, publishReplay, refCount } from 'rxjs/operators';

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/packages/git/src/store/git-entity-factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schema } from 'normalizr';
import { Schema, schema } from '../../../store/src/normalizr/normalizr';

import { EntitySchema } from '../../../store/src/helpers/entity-schema';
import { GitBranch, GitCommit, GitRepo } from './git.public-types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, schema } from 'normalizr';
import { Schema, schema } from '../../../store/src/normalizr/normalizr';

import { EntitySchema } from '../../../store/src/helpers/entity-schema';
import { stratosMonocularEndpointGuid } from './monocular/stratos-monocular.helper';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, schema } from 'normalizr';
import { Schema, schema } from '../../../store/src/normalizr/normalizr';

import { getAPIResourceGuid } from '../../../cloud-foundry/src/store/selectors/api.selectors';
import { EntitySchema } from '../../../store/src/helpers/entity-schema';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Action } from '@ngrx/store';
import { normalize } from 'normalizr';
import { normalize } from '../../../../store/src/normalizr/normalizr';

import { entityCatalog } from '../../entity-catalog/entity-catalog';
import { StratosBaseCatalogEntity } from '../../entity-catalog/entity-catalog-entity/entity-catalog-entity';
Expand Down
7 changes: 2 additions & 5 deletions src/frontend/packages/store/src/entity-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ const catalogEndpointEntity = new StratosBaseCatalogEntity({
const catalogEntity = new StratosBaseCatalogEntity({
endpoint: catalogEndpointEntity.definition as IStratosEndpointDefinition,
type: entityType,
schema: new EntitySchema(
entityType,
endpointType
),
schema: entitySchema,
label: 'Entity',
labelPlural: 'Entities',

Expand All @@ -81,7 +78,7 @@ function getAllTheThings(store: Store<GeneralAppState>, guid: string, schemaKey:
const entities = {
[entitySchema.key]: {
[guid]: {
guid,
id: guid,
test: 123
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/packages/store/src/extension-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Type } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Schema, schema } from 'normalizr';
import { Schema, schema } from '../../store/src/normalizr/normalizr';

// Allowable endpoint types
export type EndpointType = 'cf' | 'metrics' | string;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/packages/store/src/helpers/entity-schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Schema, schema } from 'normalizr';
import { Schema, schema } from '../../../store/src/normalizr/normalizr';

import { EntityCatalogHelpers } from '../entity-catalog/entity-catalog.helper';
import { EntityCatalogEntityConfig } from '../entity-catalog/entity-catalog.types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { denormalize } from 'normalizr';
import { denormalize } from '../../../store/src/normalizr/normalizr';

import { IRequestTypeState } from '../app-state';
import { IRecursiveDelete } from '../effects/recursive-entity-delete.effect';
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/packages/store/src/monitors/entity-monitor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Store } from '@ngrx/store';
import { denormalize, schema as normalizrSchema } from 'normalizr';
import { denormalize, schema as normalizrSchema } from '../../../store/src/normalizr/normalizr';

import { combineLatest, interval as observableInterval, Observable } from 'rxjs';
import { tag } from 'rxjs-spy/operators/tag';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Store } from '@ngrx/store';
import { denormalize, schema as normalizrSchema } from 'normalizr';
import { denormalize, schema as normalizrSchema } from '../../../store/src/normalizr/normalizr';

import { asapScheduler, combineLatest, Observable, ReplaySubject } from 'rxjs';
import { tag } from 'rxjs-spy/operators';
import {
Expand Down
70 changes: 70 additions & 0 deletions src/frontend/packages/store/src/normalizr/normalizr.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* tslint:disable */
declare namespace schema {
export type StrategyFunction<T> = (value: any, parent: any, key: string) => T;
export type SchemaFunction = (value: any, parent: any, key: string) => string;
export type MergeFunction = (entityA: any, entityB: any) => any;

export class Array<T = any> {
constructor(definition: Schema<T>, schemaAttribute?: string | SchemaFunction)
define(definition: Schema): void
}

export interface EntityOptions<T = any> {
idAttribute?: string | SchemaFunction
mergeStrategy?: MergeFunction
processStrategy?: StrategyFunction<T>
}

export class Entity<T = any> {
constructor(key: string | symbol, definition?: Schema, options?: EntityOptions<T>)
define(definition: Schema): void
key: string
getId: SchemaFunction
_processStrategy: StrategyFunction<T>
}

export class Object<T = any> {
constructor(definition: SchemaObject<T>)
define(definition: Schema): void
}

export class Union<T = any> {
constructor(definition: Schema<T>, schemaAttribute?: string | SchemaFunction)
define(definition: Schema): void
}

export class Values<T = any> {
constructor(definition: Schema<T>, schemaAttribute?: string | SchemaFunction)
define(definition: Schema): void
}
}

export type Schema<T = any> =
| schema.Entity<T>
| schema.Object<T>
| schema.Union<T>
| schema.Values<T>
| SchemaObject<T>
| SchemaArray<T>;

export type SchemaValueFunction<T> = (t: T) => Schema<T>;
export type SchemaValue<T> = Schema<T> | SchemaValueFunction<T>;

export interface SchemaObject<T> {
[key: string]: SchemaValue<T>
}

export interface SchemaArray<T> extends Array<Schema<T>> {}

export type NormalizedSchema<E, R> = { entities: E, result: R };

export function normalize<T = any, E = { [key:string]: { [key:string]: T } | undefined}, R = any>(
data: any,
schema: Schema<T>
): NormalizedSchema<E, R>;

export function denormalize(
input: any,
schema: Schema,
entities: any
): any;
Loading

0 comments on commit 7370d74

Please sign in to comment.