Skip to content

Commit

Permalink
Fix: Check the permission before request the compare API (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnettZQG authored Apr 28, 2023
1 parent 6fe131b commit 92d097c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import type { Endpoint } from '../../../../interface/observation';
import type { Target } from '../../../../interface/target';
import { locale } from '../../../../utils/locale';
import { getLink } from '../../../../utils/utils';
import { checkPermission } from '../../../../utils/permission';
import { LoginUserInfo } from '../../../../interface/user';

export type GatewayIP = {
ip: string;
Expand All @@ -47,6 +49,7 @@ type Props = {
disableStatusShow?: boolean;
refresh: () => void;
dispatch: ({}) => void;
userInfo?: LoginUserInfo;
};

type State = {
Expand Down Expand Up @@ -162,11 +165,23 @@ class Header extends Component<Props, State> {
};

compareCurrentWithCluster = (appName: string, envName: string) => {
const { applicationStatus } = this.props;
const { applicationStatus, applicationDetail, userInfo } = this.props;
if (!applicationStatus) {
this.setState({ compare: undefined });
return;
}
if (
!checkPermission(
{
resource: `project:${applicationDetail?.project?.name}/application:${applicationDetail?.name}`,
action: 'compare',
},
applicationDetail?.project?.name,
userInfo
)
) {
return;
}
compareApplication(appName, { compareLatestWithRunning: { env: envName } }).then(
(res: ApplicationCompareResponse) => {
this.setState({ compare: res });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ class ApplicationInstanceList extends React.Component<Props, State> {
<div>
<Header
envbinding={envbinding}
userInfo={userInfo}
targets={this.getTargets()}
components={components}
envName={envName}
Expand Down
1 change: 1 addition & 0 deletions packages/velaux-ui/src/pages/ApplicationStatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class ApplicationStatusPage extends React.Component<Props, State> {
<div className="application-status-wrapper">
<Loading visible={loading && endpointLoading} style={{ width: '100%' }}>
<Header
userInfo={userInfo}
envbinding={this.getEnvbindingByName()}
targets={this.getTargets()}
envName={envName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { beautifyTime } from '../../utils/common';
import { locale } from '../../utils/locale';

import ApplicationWorkflowRecord from './components/WorkflowRecord';
import { LoginUserInfo } from '../../interface/user';

const { Row, Col } = Grid;

Expand All @@ -34,6 +35,7 @@ type Props = {
applicationStatus?: ApplicationStatus;
envbinding: EnvBinding[];
workflows: Workflow[];
userInfo?: LoginUserInfo;
};

type State = {
Expand All @@ -49,7 +51,7 @@ type State = {
};

@connect((store: any) => {
return { ...store.application };
return { ...store.application, ...store.user };
})
class ApplicationWorkflow extends React.Component<Props, State> {
constructor(props: Props) {
Expand Down Expand Up @@ -136,7 +138,7 @@ class ApplicationWorkflow extends React.Component<Props, State> {
runApplicationWorkflow = () => {};

render() {
const { applicationDetail, dispatch, applicationStatus, workflows } = this.props;
const { applicationDetail, dispatch, applicationStatus, workflows, userInfo } = this.props;
const {
params: { record, appName, envName },
} = this.props.match;
Expand Down Expand Up @@ -177,6 +179,7 @@ class ApplicationWorkflow extends React.Component<Props, State> {
return (
<div className="run-layout">
<Header
userInfo={userInfo}
envbinding={this.getEnvbindingByName()}
envName={envName}
appName={appName}
Expand Down

0 comments on commit 92d097c

Please sign in to comment.