Skip to content

Commit

Permalink
feat: update dependency permission (#4910)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Oct 4, 2023
1 parent b319cec commit 296cc9a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { Button } from '@mui/material';
import { Add } from '@mui/icons-material';
import { AddDependencyDialogue } from 'component/feature/Dependencies/AddDependencyDialogue';
import { IFeatureToggle } from 'interfaces/featureToggle';
import { FC, useState } from 'react';
Expand All @@ -9,6 +7,9 @@ import { DependencyActions } from './DependencyActions';
import { useDependentFeaturesApi } from 'hooks/api/actions/useDependentFeaturesApi/useDependentFeaturesApi';
import { useFeature } from 'hooks/api/getters/useFeature/useFeature';
import { ChildrenTooltip } from './ChildrenTooltip';
import PermissionButton from 'component/common/PermissionButton/PermissionButton';
import { UPDATE_FEATURE_DEPENDENCY } from 'component/providers/AccessProvider/permissions';
import { useCheckProjectPermissions } from 'hooks/useHasAccess';

export const DependencyRow: FC<{ feature: IFeatureToggle }> = ({ feature }) => {
const { removeDependencies } = useDependentFeaturesApi(feature.project);
Expand All @@ -21,6 +22,7 @@ export const DependencyRow: FC<{ feature: IFeatureToggle }> = ({ feature }) => {
const hasParentDependency =
Boolean(feature.project) && Boolean(feature.dependencies.length > 0);
const hasChildren = Boolean(feature.project) && feature.children.length > 0;
const checkAccess = useCheckProjectPermissions(feature.project);

return (
<>
Expand All @@ -30,14 +32,16 @@ export const DependencyRow: FC<{ feature: IFeatureToggle }> = ({ feature }) => {
<FlexRow>
<StyledDetail>
<StyledLabel>Dependency:</StyledLabel>
<Button
startIcon={<Add />}
<PermissionButton
permission={UPDATE_FEATURE_DEPENDENCY}
projectId={feature.project}
variant='text'
onClick={() => {
setShowDependencyDialogue(true);
}}
>
Add parent feature
</Button>
</PermissionButton>
</StyledDetail>
</FlexRow>
}
Expand All @@ -54,13 +58,20 @@ export const DependencyRow: FC<{ feature: IFeatureToggle }> = ({ feature }) => {
{feature.dependencies[0]?.feature}
</StyledLink>
</StyledDetail>
<DependencyActions
feature={feature.name}
onEdit={() => setShowDependencyDialogue(true)}
onDelete={async () => {
await removeDependencies(feature.name);
await refetchFeature();
}}
<ConditionallyRender
condition={checkAccess(UPDATE_FEATURE_DEPENDENCY)}
show={
<DependencyActions
feature={feature.name}
onEdit={() =>
setShowDependencyDialogue(true)
}
onDelete={async () => {
await removeDependencies(feature.name);
await refetchFeature();
}}
/>
}
/>
</FlexRow>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ test('show dependency dialogue', async () => {
}
header={''}
/>,
{
permissions: [
{ permission: 'UPDATE_FEATURE_DEPENDENCY', project: 'default' },
],
},
);

const addParentButton = await screen.findByText('Add parent feature');
Expand Down Expand Up @@ -100,6 +105,11 @@ test('delete dependency', async () => {
}
header={''}
/>,
{
permissions: [
{ permission: 'UPDATE_FEATURE_DEPENDENCY', project: 'default' },
],
},
);

await screen.findByText('Dependency:');
Expand Down Expand Up @@ -127,6 +137,11 @@ test('edit dependency', async () => {
}
header={''}
/>,
{
permissions: [
{ permission: 'UPDATE_FEATURE_DEPENDENCY', project: 'default' },
],
},
);

await screen.findByText('Dependency:');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const ADMIN = 'ADMIN';
export const CREATE_FEATURE = 'CREATE_FEATURE';
export const UPDATE_FEATURE = 'UPDATE_FEATURE';
export const UPDATE_FEATURE_DEPENDENCY = 'UPDATE_FEATURE_DEPENDENCY';
export const DELETE_FEATURE = 'DELETE_FEATURE';
export const CREATE_STRATEGY = 'CREATE_STRATEGY';
export const UPDATE_STRATEGY = 'UPDATE_STRATEGY';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IUnleashConfig,
IUnleashServices,
NONE,
UPDATE_FEATURE,
UPDATE_FEATURE_DEPENDENCY,
} from '../../types';
import { Logger } from '../../logger';
import {
Expand Down Expand Up @@ -88,7 +88,7 @@ export default class DependentFeaturesController extends Controller {
method: 'post',
path: PATH_DEPENDENCIES,
handler: this.addFeatureDependency,
permission: UPDATE_FEATURE,
permission: UPDATE_FEATURE_DEPENDENCY,
middleware: [
openApiService.validPath({
tags: ['Features'],
Expand All @@ -111,7 +111,7 @@ export default class DependentFeaturesController extends Controller {
method: 'delete',
path: PATH_DEPENDENCY,
handler: this.deleteFeatureDependency,
permission: UPDATE_FEATURE,
permission: UPDATE_FEATURE_DEPENDENCY,
acceptAnyContentType: true,
middleware: [
openApiService.validPath({
Expand All @@ -131,7 +131,7 @@ export default class DependentFeaturesController extends Controller {
method: 'delete',
path: PATH_DEPENDENCIES,
handler: this.deleteFeatureDependencies,
permission: UPDATE_FEATURE,
permission: UPDATE_FEATURE_DEPENDENCY,
acceptAnyContentType: true,
middleware: [
openApiService.validPath({
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const DELETE_TAG_TYPE = 'DELETE_TAG_TYPE';
// Project
export const CREATE_FEATURE = 'CREATE_FEATURE';
export const UPDATE_FEATURE = 'UPDATE_FEATURE';
export const UPDATE_FEATURE_DEPENDENCY = 'UPDATE_FEATURE_DEPENDENCY';
export const DELETE_FEATURE = 'DELETE_FEATURE';
export const UPDATE_PROJECT = 'UPDATE_PROJECT';
export const DELETE_PROJECT = 'DELETE_PROJECT';
Expand Down
19 changes: 19 additions & 0 deletions src/migrations/20231002122426-update-dependency-permission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
exports.up = function (db, cb) {
db.runSql(
`
INSERT INTO permissions (permission, display_name, type) VALUES ('UPDATE_FEATURE_DEPENDENCY', 'Update feature dependency', 'project');
SELECT assign_unleash_permission_to_role('UPDATE_FEATURE_DEPENDENCY', 'Member');
SELECT assign_unleash_permission_to_role('UPDATE_FEATURE_DEPENDENCY', 'Owner');
`,
cb
);
};

exports.down = function (db, cb) {
db.runSql(
`
DELETE FROM permissions WHERE permission = 'UPDATE_FEATURE_DEPENDENCY';
`,
cb
);
};

0 comments on commit 296cc9a

Please sign in to comment.