Skip to content

Commit

Permalink
feat: limit project management pages p.o.c.
Browse files Browse the repository at this point in the history
  • Loading branch information
martastain authored and flynput committed Oct 21, 2024
1 parent 8fb808a commit ed4b0ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/pages/ProjectManagerPage/ProjectAnatomy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { toast } from 'react-toastify'
import { useState } from 'react'
import { ScrollPanel, SaveButton, Spacer, Button } from '@ynput/ayon-react-components'
import { useUpdateProjectAnatomyMutation } from '@queries/project/updateProject'
import { useGetCurrentUserProjectPermissionsQuery } from '@queries/permissions/getPermissions'
import ProjectManagerPageLayout from './ProjectManagerPageLayout'
import AnatomyEditor from '@containers/AnatomyEditor'

Expand All @@ -15,6 +16,15 @@ const ProjectAnatomy = ({ projectName, projectList }) => {
const [updateProjectAnatomy, { isLoading: isUpdating }] = useUpdateProjectAnatomyMutation()
const { requestPaste } = usePaste()


const { data: permissions } = useGetCurrentUserProjectPermissionsQuery({
projectName: projectName,
})

const accessLevel = permissions?.project?.enabled ? permissions.project.anatomy : 2
//const accessLevel = 2


const saveAnatomy = () => {
updateProjectAnatomy({ projectName, anatomy: formData })
.unwrap()
Expand Down Expand Up @@ -62,23 +72,25 @@ const ProjectAnatomy = ({ projectName, projectList }) => {
}}
/>
<Button label="Paste anatomy" icon="content_paste" onClick={onPasteAnatomy} />
{accessLevel === 1 && "Read-only"}
<Spacer />
<SaveButton
label="Save changes"
onClick={saveAnatomy}
active={isChanged}
active={isChanged && accessLevel > 1}
saving={isUpdating}
/>
</>
}
>
<ScrollPanel style={{ flexGrow: 1 }} className="transparent">
{accessLevel ? (
<AnatomyEditor
projectName={projectName}
formData={formData}
setFormData={setFormData}
setIsChanged={setIsChanged}
/>
/>) : "You don't have access to this project's anatomy. We should redirect you somewhere else."}
</ScrollPanel>
</ProjectManagerPageLayout>
)
Expand Down
26 changes: 15 additions & 11 deletions src/pages/ProjectManagerPage/ProjectManagerPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const ProjectManagerPage = () => {
withDefault(StringParam, projectName),
)

const { data: permissions} = useGetCurrentUserProjectPermissionsQuery({ projectName: selectedProject })
const { data: permissions } = useGetCurrentUserProjectPermissionsQuery({
projectName: selectedProject,
})

// UPDATE DATA
const [updateProject] = useUpdateProjectMutation()
Expand Down Expand Up @@ -85,20 +87,23 @@ const ProjectManagerPage = () => {
}

const links = []
const projectPermissions = permissions?.project_settings
if (permissions?.project) {
// How to read this code:
// If project management restrictions are NOT enabled
// OR if project management restrctions ARE enabled
// and access to anatomy is allowed

if (projectPermissions){
if (!projectPermissions.enabled || projectPermissions.anatomy_update) {
if (!permissions.project.enabled || permissions.project.anatomy) {
links.push({
name: 'Anatomy',
path: '/manageProjects/anatomy',
module: 'anatomy',
accessLevels: [],
shortcut: 'A+A',
name: 'Anatomy',
path: '/manageProjects/anatomy',
module: 'anatomy',
accessLevels: [],
shortcut: 'A+A',
})
}

if (!projectPermissions.enabled || projectPermissions.addon_settings_update) {
if (!permissions.project.enabled || permissions.project.settings) {
links.push({
name: 'Project settings',
path: '/manageProjects/projectSettings',
Expand All @@ -109,7 +114,6 @@ const ProjectManagerPage = () => {
}
}


links.push(
{
name: 'Site settings',
Expand Down

0 comments on commit ed4b0ca

Please sign in to comment.