From bfd63c99f6d1efe5b091ef52ac76b69ef6e4072d Mon Sep 17 00:00:00 2001 From: Deepankumar Loganathan Date: Sat, 3 Feb 2024 18:31:59 +0100 Subject: [PATCH] README updated and comments fixed Signed-off-by: Deepankumar Loganathan --- .../src/service/router.ts | 8 +-- plugins/azure-devops/README.md | 59 +++++++++++++++++++ .../EntityPageAzureGitTags.tsx | 9 +-- .../EntityPageAzurePipelines.tsx | 9 +-- .../EntityPageAzurePullRequests.tsx | 9 +-- .../src/components/ReadmeCard/ReadmeCard.tsx | 8 +-- 6 files changed, 67 insertions(+), 35 deletions(-) diff --git a/plugins/azure-devops-backend/src/service/router.ts b/plugins/azure-devops-backend/src/service/router.ts index a77aa42c8a..b9667a9ade 100644 --- a/plugins/azure-devops-backend/src/service/router.ts +++ b/plugins/azure-devops-backend/src/service/router.ts @@ -131,7 +131,7 @@ export async function createRouter( const host = req.query.host?.toString(); const org = req.query.org?.toString(); - const entityRef = req.query.entityRef?.toString(); + const entityRef = req.query.entityRef; if (typeof entityRef !== 'string') { throw new InputError('Invalid entityRef, not a string'); } @@ -181,7 +181,7 @@ export async function createRouter( status: status, }; - const entityRef = req.query.entityRef?.toString(); + const entityRef = req.query.entityRef; if (typeof entityRef !== 'string') { throw new InputError('Invalid entityRef, not a string'); } @@ -290,7 +290,7 @@ export async function createRouter( const host = req.query.host?.toString(); const org = req.query.org?.toString(); - const entityRef = req.query.entityRef?.toString(); + const entityRef = req.query.entityRef; if (typeof entityRef !== 'string') { throw new InputError('Invalid entityRef, not a string'); } @@ -355,7 +355,7 @@ export async function createRouter( const { projectName, repoName } = req.params; - const entityRef = req.query.entityRef?.toString(); + const entityRef = req.query.entityRef; if (typeof entityRef !== 'string') { throw new InputError('Invalid entityRef, not a string'); } diff --git a/plugins/azure-devops/README.md b/plugins/azure-devops/README.md index 935e78c82c..996ff57690 100644 --- a/plugins/azure-devops/README.md +++ b/plugins/azure-devops/README.md @@ -319,3 +319,62 @@ To get the README component working you'll need to do the following two steps: - You'll need to add the `EntitySwitch.Case` above from step 2 to all the entity sections you want to see Readme in. For example if you wanted to see Readme when looking at Website entities then you would need to add this to the `websiteEntityPage` section. - The `if` prop is optional on the `EntitySwitch.Case`, you can remove it if you always want to see the tab even if the entity being viewed does not have the needed annotation - The `maxHeight` property on the `EntityAzureReadmeCard` will set the maximum screen size you would like to see, if not set it will default to 100% + +## Permission Framework + +Azure DevOps plugin is now supporting the permission framework for PRs, GitTags, Pipelines & ReadMe. + +To enable the permission on the legacy backend system add the below config in `packages/backend/src/plugins/azure-devops.ts`. + +```diff +export default async function createPlugin( + env: PluginEnvironment, +): Promise { + return createRouter({ + logger: env.logger, + config: env.config, + reader: env.reader, ++ permissions: env.permissions, + }); +} +``` + +### Configure Permission + +To apply the permission rule add the following in `packages/backend/src/plugins/permissions.ts`. + +> Note this is example only `azureDevOpsPullRequestDashboardReadPermission` is Basic permission rest all Resource Permission. As an adopter you can configure how you wanted. + +```diff ++ import { ++ azureDevOpsPullRequestReadPermission, ++ azureDevOpsPipelineReadPermission, ++ azureDevOpsGitTagReadPermission, ++ azureDevOpsReadmeReadPermission, ++ azureDevOpsPullRequestDashboardReadPermission } from '@backstage/azure-devops-common'; +... +async handle( + request: PolicyQuery, + user?: BackstageIdentityResponse, +): Promise { ++ if ( isPermission(request.permission, azureDevOpsPullRequestReadPermission) || ++ isPermission(request.permission, azureDevOpsPipelineReadPermission) || ++ isPermission(request.permission, azureDevOpsGitTagReadPermission) || ++ isPermission(request.permission, azureDevOpsReadmeReadPermission)) { ++ return createTodoListConditionalDecision( ++ request.permission, ++ catalogConditions.isEntityOwner({ ++ claims: user?.identity.ownershipEntityRefs ?? [], ++ }), ++ ); ++ } + ++ if ( isPermission(request.permission, azureDevOpsPullRequestDashboardReadPermission) { ++ result: AuthorizeResult.ALLOW, ++ } + + return { + result: AuthorizeResult.ALLOW, + }; +} +``` diff --git a/plugins/azure-devops/src/components/EntityPageAzureGitTags/EntityPageAzureGitTags.tsx b/plugins/azure-devops/src/components/EntityPageAzureGitTags/EntityPageAzureGitTags.tsx index 1632649d59..3e174fd31b 100644 --- a/plugins/azure-devops/src/components/EntityPageAzureGitTags/EntityPageAzureGitTags.tsx +++ b/plugins/azure-devops/src/components/EntityPageAzureGitTags/EntityPageAzureGitTags.tsx @@ -20,7 +20,6 @@ import React from 'react'; import { stringifyEntityRef } from '@backstage/catalog-model'; import { useEntity } from '@backstage/plugin-catalog-react'; import { RequirePermission } from '@backstage/plugin-permission-react'; -import { EmptyState } from '@backstage/core-components'; export const EntityPageAzureGitTags = () => { const { entity } = useEntity(); @@ -28,13 +27,7 @@ export const EntityPageAzureGitTags = () => { - } + errorPage={null} > diff --git a/plugins/azure-devops/src/components/EntityPageAzurePipelines/EntityPageAzurePipelines.tsx b/plugins/azure-devops/src/components/EntityPageAzurePipelines/EntityPageAzurePipelines.tsx index 39e3da1a7e..d8c6483a3e 100644 --- a/plugins/azure-devops/src/components/EntityPageAzurePipelines/EntityPageAzurePipelines.tsx +++ b/plugins/azure-devops/src/components/EntityPageAzurePipelines/EntityPageAzurePipelines.tsx @@ -21,7 +21,6 @@ import { useEntity } from '@backstage/plugin-catalog-react'; import { azureDevOpsPipelineReadPermission } from '@backstage/plugin-azure-devops-common'; import { stringifyEntityRef } from '@backstage/catalog-model'; import { RequirePermission } from '@backstage/plugin-permission-react'; -import { EmptyState } from '@backstage/core-components'; export const EntityPageAzurePipelines = (props: { defaultLimit?: number }) => { const { entity } = useEntity(); @@ -32,13 +31,7 @@ export const EntityPageAzurePipelines = (props: { defaultLimit?: number }) => { - } + errorPage={null} > diff --git a/plugins/azure-devops/src/components/EntityPageAzurePullRequests/EntityPageAzurePullRequests.tsx b/plugins/azure-devops/src/components/EntityPageAzurePullRequests/EntityPageAzurePullRequests.tsx index 7b828c512c..1d59ea4b8f 100644 --- a/plugins/azure-devops/src/components/EntityPageAzurePullRequests/EntityPageAzurePullRequests.tsx +++ b/plugins/azure-devops/src/components/EntityPageAzurePullRequests/EntityPageAzurePullRequests.tsx @@ -20,7 +20,6 @@ import React from 'react'; import { RequirePermission } from '@backstage/plugin-permission-react'; import { useEntity } from '@backstage/plugin-catalog-react'; import { stringifyEntityRef } from '@backstage/catalog-model'; -import { EmptyState } from '@backstage/core-components'; export const EntityPageAzurePullRequests = (props: { defaultLimit?: number; @@ -30,13 +29,7 @@ export const EntityPageAzurePullRequests = (props: { - } + errorPage={null} > diff --git a/plugins/azure-devops/src/components/ReadmeCard/ReadmeCard.tsx b/plugins/azure-devops/src/components/ReadmeCard/ReadmeCard.tsx index 6c9c427f9c..b2c874a3ba 100644 --- a/plugins/azure-devops/src/components/ReadmeCard/ReadmeCard.tsx +++ b/plugins/azure-devops/src/components/ReadmeCard/ReadmeCard.tsx @@ -103,13 +103,7 @@ export const ReadmeCard = (props: Props) => { - } + errorPage={null} >