diff --git a/.changeset/small-avocados-decide.md b/.changeset/small-avocados-decide.md new file mode 100644 index 0000000000..dc5cea1184 --- /dev/null +++ b/.changeset/small-avocados-decide.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs-backend': patch +--- + +Add support for permissions to the DefaultTechDocsCollator by adding the visibilityPermission prop and including authorization.resourceRef on indexed documents. diff --git a/plugins/techdocs-backend/api-report.md b/plugins/techdocs-backend/api-report.md index 76183d4c6c..cefb7d937b 100644 --- a/plugins/techdocs-backend/api-report.md +++ b/plugins/techdocs-backend/api-report.md @@ -10,6 +10,7 @@ import express from 'express'; import { GeneratorBuilder } from '@backstage/techdocs-common'; import { Knex } from 'knex'; import { Logger as Logger_2 } from 'winston'; +import { Permission } from '@backstage/plugin-permission-common'; import { PluginCacheManager } from '@backstage/backend-common'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { PreparerBuilder } from '@backstage/techdocs-common'; @@ -46,6 +47,8 @@ export class DefaultTechDocsCollator implements DocumentCollator { protected locationTemplate: string; // (undocumented) readonly type: string; + // (undocumented) + readonly visibilityPermission: Permission; } // Warning: (ae-missing-release-tag) "OutOfTheBoxDeploymentOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/plugins/techdocs-backend/package.json b/plugins/techdocs-backend/package.json index 882c8092de..7692eb6825 100644 --- a/plugins/techdocs-backend/package.json +++ b/plugins/techdocs-backend/package.json @@ -37,6 +37,7 @@ "@backstage/config": "^0.1.13", "@backstage/errors": "^0.2.0", "@backstage/integration": "^0.7.2", + "@backstage/plugin-catalog-common": "^0.1.1-next.0", "@backstage/search-common": "^0.2.1", "@backstage/techdocs-common": "^0.11.4", "@types/express": "^4.17.6", diff --git a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts index 5f0bed55dd..7e7545ea1f 100644 --- a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts +++ b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts @@ -200,6 +200,9 @@ describe('DefaultTechDocsCollator', () => { owner: '', kind: entity.kind, name: entity.metadata.name, + authorization: { + resourceRef: `component:default/${entity.metadata.name}`, + }, }); }); }); diff --git a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts index 1d3a3dbc3a..5149fe6c09 100644 --- a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts +++ b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts @@ -18,13 +18,18 @@ import { PluginEndpointDiscovery, TokenManager, } from '@backstage/backend-common'; -import { Entity, RELATION_OWNED_BY } from '@backstage/catalog-model'; +import { + Entity, + RELATION_OWNED_BY, + stringifyEntityRef, +} from '@backstage/catalog-model'; import { DocumentCollator } from '@backstage/search-common'; import fetch from 'node-fetch'; import unescape from 'lodash/unescape'; import { Logger } from 'winston'; import pLimit from 'p-limit'; import { Config } from '@backstage/config'; +import { catalogEntityReadPermission } from '@backstage/plugin-catalog-common'; import { CatalogApi, CatalogClient } from '@backstage/catalog-client'; import { TechDocsDocument } from '@backstage/techdocs-common'; @@ -59,6 +64,7 @@ export class DefaultTechDocsCollator implements DocumentCollator { private readonly parallelismLimit: number; private readonly legacyPathCasing: boolean; public readonly type: string = 'techdocs'; + public readonly visibilityPermission = catalogEntityReadPermission; /** * @deprecated use static fromConfig method instead. @@ -148,6 +154,9 @@ export class DefaultTechDocsCollator implements DocumentCollator { owner: entity.relations?.find(r => r.type === RELATION_OWNED_BY) ?.target?.name || '', + authorization: { + resourceRef: stringifyEntityRef(entity), + }, })); } catch (e) { this.logger.debug(