frontend permission integration changed

Signed-off-by: Deepankumar Loganathan <deepan0433@gmail.com>
This commit is contained in:
Deepankumar Loganathan
2024-01-31 07:05:19 +01:00
parent 3270b1b4f8
commit 2bfd8ac15b
15 changed files with 112 additions and 106 deletions
+1
View File
@@ -50,6 +50,7 @@
"@backstage/frontend-plugin-api": "workspace:^",
"@backstage/plugin-azure-devops-common": "workspace:^",
"@backstage/plugin-catalog-react": "workspace:^",
"@backstage/plugin-permission-react": "workspace:^",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@types/react": "^16.13.1 || ^17.0.0 || ^18.0.0",
@@ -32,14 +32,12 @@ import {
StatusWarning,
Table,
TableColumn,
EmptyState,
} from '@backstage/core-components';
import { AzurePipelinesIcon } from '../AzurePipelinesIcon';
import { DateTime } from 'luxon';
import React from 'react';
import { getDurationFromDates } from '../../utils/getDurationFromDates';
import { isAuthorizationError } from '../../utils';
export const getBuildResultComponent = (result: number | undefined) => {
switch (result) {
@@ -181,15 +179,6 @@ type BuildTableProps = {
export const BuildTable = ({ items, loading, error }: BuildTableProps) => {
if (error) {
if (isAuthorizationError(error)) {
return (
<EmptyState
missing="data"
title="No Buils to show"
description="You are not authorized!"
/>
);
}
return (
<div>
<ResponseErrorPanel error={error} />
@@ -14,7 +14,29 @@
* limitations under the License.
*/
import { azureDevOpsGitTagReadPermission } from '@backstage/plugin-azure-devops-common';
import { GitTagTable } from '../GitTagTable/GitTagTable';
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 = () => <GitTagTable />;
export const EntityPageAzureGitTags = () => {
const { entity } = useEntity();
return (
<RequirePermission
permission={azureDevOpsGitTagReadPermission}
resourceRef={stringifyEntityRef(entity)}
errorPage={
<EmptyState
missing="data"
title="No Tags to show"
description="You are not authorized!"
/>
}
>
<GitTagTable />
</RequirePermission>
);
};
@@ -18,11 +18,29 @@ import { BuildTable } from '../BuildTable/BuildTable';
import React from 'react';
import { useBuildRuns } from '../../hooks';
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();
const { items, loading, error } = useBuildRuns(entity, props.defaultLimit);
return <BuildTable items={items} loading={loading} error={error} />;
return (
<RequirePermission
permission={azureDevOpsPipelineReadPermission}
resourceRef={stringifyEntityRef(entity)}
errorPage={
<EmptyState
missing="data"
title="No Buils to show"
description="You are not authorized!"
/>
}
>
<BuildTable items={items} loading={loading} error={error} />
</RequirePermission>
);
};
@@ -14,11 +14,31 @@
* limitations under the License.
*/
import { azureDevOpsPullRequestReadPermission } from '@backstage/plugin-azure-devops-common';
import { PullRequestTable } from '../PullRequestTable/PullRequestTable';
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;
}) => {
return <PullRequestTable defaultLimit={props.defaultLimit} />;
const { entity } = useEntity();
return (
<RequirePermission
permission={azureDevOpsPullRequestReadPermission}
resourceRef={stringifyEntityRef(entity)}
errorPage={
<EmptyState
missing="data"
title="No Pull Requests to show"
description="You are not authorized!"
/>
}
>
<PullRequestTable defaultLimit={props.defaultLimit} />
</RequirePermission>
);
};
@@ -20,7 +20,6 @@ import {
ResponseErrorPanel,
Table,
TableColumn,
EmptyState,
} from '@backstage/core-components';
import { GitTag } from '@backstage/plugin-azure-devops-common';
import React from 'react';
@@ -28,7 +27,6 @@ import React from 'react';
import { AzureGitTagsIcon } from '../AzureGitTagsIcon';
import { useEntity } from '@backstage/plugin-catalog-react';
import { useGitTags } from '../../hooks/useGitTags';
import { isAuthorizationError } from '../../utils';
const columns: TableColumn[] = [
{
@@ -66,15 +64,6 @@ export const GitTagTable = () => {
const { items, loading, error } = useGitTags(entity);
if (error) {
if (isAuthorizationError(error)) {
return (
<EmptyState
missing="data"
title="No Tags to show"
description="You are not authorized!"
/>
);
}
return <ResponseErrorPanel error={error} />;
}
@@ -21,7 +21,6 @@ import {
ResponseErrorPanel,
Table,
TableColumn,
EmptyState,
} from '@backstage/core-components';
import {
PullRequest,
@@ -34,7 +33,6 @@ import { DateTime } from 'luxon';
import { PullRequestStatusButtonGroup } from '../PullRequestStatusButtonGroup';
import { useEntity } from '@backstage/plugin-catalog-react';
import { usePullRequests } from '../../hooks/usePullRequests';
import { isAuthorizationError } from '../../utils';
const columns: TableColumn[] = [
{
@@ -106,15 +104,6 @@ export const PullRequestTable = ({ defaultLimit }: PullRequestTableProps) => {
);
if (error) {
if (isAuthorizationError(error)) {
return (
<EmptyState
missing="data"
title="No Pull Requests to show"
description="You are not authorized!"
/>
);
}
return <ResponseErrorPanel error={error} />;
}
@@ -16,7 +16,6 @@
import {
Content,
EmptyState,
Header,
Page,
Progress,
@@ -29,7 +28,6 @@ import { FilterType } from './lib/filters';
import { PullRequestGrid } from './lib/PullRequestGrid';
import { useDashboardPullRequests } from '../../hooks';
import { useFilterProcessor } from './lib/hooks';
import { isAuthorizationError } from '../../utils';
type PullRequestsPageContentProps = {
pullRequestGroups: PullRequestGroup[] | undefined;
@@ -47,15 +45,6 @@ const PullRequestsPageContent = ({
}
if (error) {
if (isAuthorizationError(error)) {
return (
<EmptyState
missing="data"
title="No Pull Requests to show"
description="You are not authorized!"
/>
);
}
return <ResponseErrorPanel error={error} />;
}
@@ -28,7 +28,9 @@ import { useEntity } from '@backstage/plugin-catalog-react';
import React from 'react';
import { useReadme } from '../../hooks';
import { isAuthorizationError } from '../../utils';
import { RequirePermission } from '@backstage/plugin-permission-react';
import { azureDevOpsReadmeReadPermission } from '@backstage/plugin-azure-devops-common';
import { stringifyEntityRef } from '@backstage/catalog-model';
const useStyles = makeStyles(theme => ({
readMe: {
@@ -64,15 +66,7 @@ function isNotFoundError(error: any): boolean {
}
const ReadmeCardError = ({ error }: ErrorProps) => {
if (isAuthorizationError(error)) {
return (
<EmptyState
title="No README available for this entity"
missing="field"
description="You are not authorized!"
/>
);
} else if (isNotFoundError(error)) {
if (isNotFoundError(error)) {
return (
<EmptyState
title="No README available for this entity"
@@ -106,16 +100,28 @@ export const ReadmeCard = (props: Props) => {
}
return (
<InfoCard
title="Readme"
deepLink={{
link: value!.url,
title: 'Readme',
}}
<RequirePermission
permission={azureDevOpsReadmeReadPermission}
resourceRef={stringifyEntityRef(entity)}
errorPage={
<EmptyState
title="No README available for this entity"
missing="field"
description="You are not authorized!"
/>
}
>
<Box className={classes.readMe} sx={{ maxHeight: props.maxHeight }}>
<MarkdownContent content={value?.content ?? ''} />
</Box>
</InfoCard>
<InfoCard
title="Readme"
deepLink={{
link: value!.url,
title: 'Readme',
}}
>
<Box className={classes.readMe} sx={{ maxHeight: props.maxHeight }}>
<MarkdownContent content={value?.content ?? ''} />
</Box>
</InfoCard>
</RequirePermission>
);
};
-1
View File
@@ -18,4 +18,3 @@ export * from './arrayHas';
export * from './equalsIgnoreCase';
export * from './getDurationFromDates';
export * from './getAnnotationValuesFromEntity';
export * from './validateError';
@@ -1,18 +0,0 @@
/*
* Copyright 2024 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export function isAuthorizationError(error: any): boolean {
return error?.response?.status === 403;
}