Skip to content

Commit

Permalink
hide project access when no permission
Browse files Browse the repository at this point in the history
  • Loading branch information
debsmita1 committed May 9, 2020
1 parent 4efd97f commit 8ea2712
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ const ProjectAccess: React.FC<ProjectAccessProps> = ({ formName, namespace, role
/>{' '}
.
</PageHeading>
<hr />
<div className="co-m-pane__body">
{roleBindings.loadError ? (
<StatusBox loaded={roleBindings.loaded} loadError={roleBindings.loadError} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import { match as RMatch } from 'react-router';
import { history } from '@console/internal/components/utils';
import { history, useAccessReview } from '@console/internal/components/utils';
import { ALL_NAMESPACES_KEY } from '@console/shared';
import { NamespaceDetails, projectMenuActions } from '@console/internal/components/namespace';
import { ProjectModel } from '@console/internal/models';
import { ProjectModel, RoleBindingModel } from '@console/internal/models';
import { DetailsPage } from '@console/internal/components/factory';
import { ProjectDashboard } from '@console/internal/components/dashboard/project-dashboard/project-dashboard';
import { withStartGuide } from '@console/internal/components/start-guide';
Expand All @@ -29,6 +29,20 @@ const handleNamespaceChange = (newNamespace: string): void => {
export const ProjectDetailsPage: React.FC<MonitoringPageProps> = ({ match, ...props }) => {
const activeNamespace = match.params.ns;

const canListRoleBindings = useAccessReview({
group: RoleBindingModel.apiGroup,
resource: RoleBindingModel.plural,
verb: 'list',
namespace: activeNamespace,
});

const canCreateRoleBindings = useAccessReview({
group: RoleBindingModel.apiGroup,
resource: RoleBindingModel.plural,
verb: 'create',
namespace: activeNamespace,
});

return (
<>
<Helmet>
Expand Down Expand Up @@ -60,11 +74,12 @@ export const ProjectDetailsPage: React.FC<MonitoringPageProps> = ({ match, ...pr
name: 'Details',
component: NamespaceDetails,
},
{
href: 'access',
name: 'Project Access',
component: ProjectAccessPage,
},
canListRoleBindings &&
canCreateRoleBindings && {
href: 'access',
name: 'Project Access',
component: ProjectAccessPage,
},
]}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { BreadCrumbs } from '@console/internal/components/utils';
import * as _ from 'lodash';
import * as utils from '@console/internal/components/utils';
import { ProjectDetailsPage } from '../ProjectDetailsPage';
import ProjectListPage from '../../ProjectListPage';
import NamespacedPage from '../../../NamespacedPage';
Expand All @@ -27,6 +28,14 @@ describe('ProjectDetailsPage', () => {
// Currently rendering the breadcrumbs will buck-up against the redirects and not work as expected
const component = shallow(<ProjectDetailsPage match={testProjectMatch} />);

expect(component.find(BreadCrumbs).exists()).not.toBe(true);
expect(component.find(utils.BreadCrumbs).exists()).not.toBe(true);
});

it('should not render the Project Access tab if user has no access to role bindings', () => {
const spyUseAccessReview = jest.spyOn(utils, 'useAccessReview');
spyUseAccessReview.mockReturnValue(false);
const component = shallow(<ProjectDetailsPage match={testProjectMatch} />);
const pages = component.find(DetailsPage).prop('pages');
expect(_.find(pages, { name: 'Project Access' })).toBe(undefined);
});
});

0 comments on commit 8ea2712

Please sign in to comment.