Skip to content

Commit

Permalink
feat: Manage tags permission (#4615)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Oct 2, 2024
1 parent 7c746f4 commit b3da659
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
18 changes: 12 additions & 6 deletions frontend/web/components/tags/AddEditTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ const AddEditTags: FC<AddEditTagsType> = ({
const [tab, setTab] = useState<'SELECT' | 'CREATE' | 'EDIT'>('SELECT')
const [deleteTag] = useDeleteTagMutation()
const [createTag] = useCreateTagMutation()
const { permission: projectAdminPermission } = useHasPermission({
const permissionType = Utils.getFlagsmithHasFeature('manage_tags_permission')
? 'MANAGE_TAGS'
: 'ADMIN'

const { permission: createEditTagPermission } = useHasPermission({
id: projectId,
level: 'project',
permission: 'ADMIN',
permission: permissionType,
})

useEffect(() => {
Expand Down Expand Up @@ -166,12 +170,14 @@ const AddEditTags: FC<AddEditTagsType> = ({
!readOnly && (
<div className='text-right'>
{Utils.renderWithPermission(
projectAdminPermission,
Constants.projectPermissions('Admin'),
createEditTagPermission,
Constants.projectPermissions(
permissionType === 'ADMIN' ? 'Admin' : 'Manage Tags',
),
<div className='text-center'>
<Button
className=''
disabled={!projectAdminPermission}
disabled={!createEditTagPermission}
onClick={() => {
setTab('CREATE')
setFilter('')
Expand Down Expand Up @@ -206,7 +212,7 @@ const AddEditTags: FC<AddEditTagsType> = ({
/>
</Flex>
{!readOnly &&
!!projectAdminPermission &&
!!createEditTagPermission &&
!tag.is_system_tag && (
<>
<div
Expand Down
13 changes: 11 additions & 2 deletions frontend/web/components/tags/CreateEditTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ const CreateEditTag: FC<CreateEditTagType> = ({
}
}

const permissionType = Utils.getFlagsmithHasFeature('manage_tags_permission')
? 'MANAGE_TAGS'
: 'ADMIN'
return (
<InlineModal
title={title}
Expand All @@ -123,11 +126,17 @@ const CreateEditTag: FC<CreateEditTagType> = ({
<Button onClick={onClose} type='button' theme='secondary'>
Cancel
</Button>
<Permission level='project' permission='ADMIN' id={projectId}>
<Permission
level='project'
permission={permissionType}
id={projectId}
>
{({ permission }) =>
Utils.renderWithPermission(
permission,
Constants.projectPermissions('Admin'),
Constants.projectPermissions(
permissionType === 'ADMIN' ? 'Admin' : 'Manage Tags',
),
<div className='ml-2'>
<Button
onClick={save}
Expand Down

0 comments on commit b3da659

Please sign in to comment.