Browse Source

Remove deprecated permissions attribute of access

pull/7639/head
Thomas Kaul 1 week ago
parent
commit
cc4e0a0524
  1. 20
      apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts
  2. 1
      libs/common/src/lib/dtos/create-access.dto.ts
  3. 1
      libs/common/src/lib/dtos/update-access.dto.ts
  4. 1
      libs/common/src/lib/interfaces/access.interface.ts
  5. 13
      libs/common/src/lib/scopes.spec.ts
  6. 11
      libs/common/src/lib/scopes.ts

20
apps/client/src/app/components/user-account-access/create-or-update-access-dialog/create-or-update-access-dialog.component.ts

@ -116,10 +116,10 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit {
access?.grantee ?? null,
isPublic ? null : Validators.required
],
hasScopeToReadValues: [
hasScope(access?.scopes, scopes.portfolioReadValues),
Validators.required
],
hasScopeToReadValues: hasScope(
access?.scopes,
scopes.portfolioReadValues
),
type: [
{ disabled: this.mode === 'update', value: access?.type ?? 'PRIVATE' },
Validators.required
@ -178,6 +178,12 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit {
}
}
private buildFilters(): Filter[] {
return getFiltersFromPortfolioFilterFormValue(
this.accessForm.get('filters')?.value
);
}
// The dialog offers the read access only. The write scopes are not granted
// here yet.
private buildScopes() {
@ -188,12 +194,6 @@ export class GfCreateOrUpdateAccessDialogComponent implements OnInit {
];
}
private buildFilters(): Filter[] {
return getFiltersFromPortfolioFilterFormValue(
this.accessForm.get('filters')?.value
);
}
private async createAccess() {
const filters = this.buildFilters();

1
libs/common/src/lib/dtos/create-access.dto.ts

@ -16,6 +16,7 @@ export class CreateAccessDto {
@IsUUID()
granteeUserId?: string;
@IsArray()
@IsIn(Object.values(scopes), { each: true })
@IsOptional()
scopes?: Scope[];

1
libs/common/src/lib/dtos/update-access.dto.ts

@ -19,6 +19,7 @@ export class UpdateAccessDto {
@IsString()
id: string;
@IsArray()
@IsIn(Object.values(scopes), { each: true })
@IsOptional()
scopes?: Scope[];

1
libs/common/src/lib/interfaces/access.interface.ts

@ -6,7 +6,6 @@ export interface Access {
alias: string | null;
grantee?: string;
id: string;
scopes: string[];
settings?: AccessSettings;
type: AccessType;

13
libs/common/src/lib/scopes.spec.ts

@ -81,6 +81,19 @@ describe('Scopes', () => {
})
).toEqual([]);
});
// TODO: Remove this expectation once the dialog allows to configure the
// write scopes
it('Gives no write scope', () => {
const scopesOfAccess = getScopesOfAccess({
granteeUserId: 'ffb08949-2f8a-4b6e-88fd-0f1e6b6b5f5d',
scopes: [...SCOPES_OF_READ_ACCESS, ...SCOPES_OF_WRITE_ACCESS]
});
for (const scope of SCOPES_OF_WRITE_ACCESS) {
expect(scopesOfAccess).not.toContain(scope);
}
});
});
describe('Get scopes of public access', () => {

11
libs/common/src/lib/scopes.ts

@ -59,19 +59,24 @@ export const SCOPES_OF_READ_RESTRICTED_ACCESS: readonly Scope[] =
export function getScopesOfAccess({
granteeUserId,
scopes: scopesOfAccess = []
scopes: scopesOfAccess
}: {
granteeUserId?: string | null;
scopes?: string[];
}): string[] {
const scopesToEvaluate = scopesOfAccess ?? [];
if (granteeUserId) {
return [...scopesOfAccess];
// TODO: Permit the write scopes once the dialog allows to configure them
return SCOPES_OF_READ_ACCESS.filter((scope) => {
return scopesToEvaluate.includes(scope);
});
}
// An access which has not been granted to a user is public, hence it is
// narrowed to the scopes exposed by the public endpoints
return SCOPES_OF_PUBLIC_ACCESS.filter((scope) => {
return scopesOfAccess.includes(scope);
return scopesToEvaluate.includes(scope);
});
}

Loading…
Cancel
Save