Updated permissions documentation to match paramsSchema changes

Signed-off-by: Harry Hogg <hhogg@spotify.com>
This commit is contained in:
Harry Hogg
2022-10-18 13:00:27 +01:00
parent 2fc86111c2
commit 24fb30fdb3
4 changed files with 32 additions and 18 deletions
+14 -8
View File
@@ -14,12 +14,18 @@ Plugins should export a rule factory that provides type-safety that ensures comp
import type { Entity } from '@backstage/plugin-catalog-model';
import { createCatalogPermissionRule } from '@backstage/plugin-catalog-backend/alpha';
import { createConditionFactory } from '@backstage/plugin-permission-node';
import { z } from 'zod';
export const isInSystemRule = createCatalogPermissionRule({
name: 'IS_IN_SYSTEM',
description: 'Checks if an entity is part of the system provided',
resourceType: 'catalog-entity',
apply: (resource: Entity, systemRef: string) => {
paramsSchema: z.object({
systemRef: z
.string()
.describe('SystemRef to check the resource is part of'),
}),
apply: (resource: Entity, { systemRef }) => {
if (!resource.relations) {
return false;
}
@@ -28,7 +34,7 @@ export const isInSystemRule = createCatalogPermissionRule({
.filter(relation => relation.type === 'partOf')
.some(relation => relation.targetRef === systemRef);
},
toQuery: (systemRef: string) => ({
toQuery: ({ systemRef }) => ({
key: 'relations.partOf',
values: [systemRef],
}),
@@ -85,14 +91,14 @@ class TestPermissionPolicy implements PermissionPolicy {
if (isResourcePermission(request.permission, 'catalog-entity')) {
return createCatalogConditionalDecision(
request.permission,
- catalogConditions.isEntityOwner(
- user?.identity.ownershipEntityRefs ?? [],
- ),
- catalogConditions.isEntityOwner({
- claims: user?.identity.ownershipEntityRefs ?? [],
- }),
+ {
+ anyOf: [
+ catalogConditions.isEntityOwner(
+ user?.identity.ownershipEntityRefs ?? []
+ ),
+ catalogConditions.isEntityOwner({
+ claims: user?.identity.ownershipEntityRefs ?? []
+ }),
+ isInSystem('interviewing')
+ ]
+ }