Skip to content

Commit

Permalink
Merge pull request #2577 from Amsterdam/improvement/121703-check-for-…
Browse files Browse the repository at this point in the history
…permission

121703 Added permission checks
  • Loading branch information
remyvdwereld authored Aug 13, 2024
2 parents de21b54 + d484cf3 commit d8a4650
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 88 deletions.
92 changes: 50 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"devDependencies": {
"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.23.3",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@types/dotenv-flow": "^3.2.0",
"@types/jest": "^29.5.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from "styled-components"
import { Icon, themeSpacing } from "@amsterdam/asc-ui"
import { Edit } from "app/components/shared/Icons"
import useHasPermission, { CAN_PERFORM_TASK } from "app/state/rest/custom/usePermissions/useHasPermission"

type Props = {
name?: string
Expand All @@ -27,16 +28,19 @@ const StyledIcon = styled(Icon)`
margin-left: ${ themeSpacing(1) };
`

const ChangeableItem = ({ name = "-", titleAccess = "", onClick }: Props) => (
<Span
role="link"
onClick={ onClick }
>
{ name }
<StyledIcon size={ 20 }>
<Edit titleAccess={ titleAccess } />
</StyledIcon>
</Span>
)
const ChangeableItem = ({ name = "-", titleAccess = "", onClick }: Props) => {
const [hasPermission] = useHasPermission([CAN_PERFORM_TASK])
return hasPermission ? (
<Span
role="link"
onClick={ onClick }
>
{ name }
<StyledIcon size={ 20 }>
<Edit titleAccess={ titleAccess } />
</StyledIcon>
</Span>
) : <>{ name }</>
}

export default ChangeableItem
26 changes: 15 additions & 11 deletions src/app/components/case/CaseDetails/EditableTag/CaseTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import styled, { keyframes } from "styled-components"
import { Icon, themeSpacing } from "@amsterdam/asc-ui"
import { Edit } from "app/components/shared/Icons"
import useHasPermission, { CAN_PERFORM_TASK } from "app/state/rest/custom/usePermissions/useHasPermission"


type Props = {
Expand Down Expand Up @@ -43,16 +44,19 @@ const StyledIcon = styled(Icon)`
cursor: pointer;
`

const CaseTags: React.FC<Props> = ({ tags = [], titleAccess = "Wijzig tag", onClick }) => (
<ClickableSpan
role="link"
onClick={ onClick }
>
{ tags.map(tag => <Tag key={ tag.id }>{ tag.name }</Tag>)}
<StyledIcon size={ 20 }>
<Edit titleAccess={ titleAccess } />
</StyledIcon>
</ClickableSpan>
)
const CaseTags: React.FC<Props> = ({ tags = [], titleAccess = "Wijzig tag", onClick }) => {
const [hasPermission] = useHasPermission([CAN_PERFORM_TASK])
return hasPermission ? (
<ClickableSpan
role="link"
onClick={ onClick }
>
{ tags.map(tag => <Tag key={ tag.id }>{ tag.name }</Tag>)}
<StyledIcon size={ 20 }>
<Edit titleAccess={ titleAccess } />
</StyledIcon>
</ClickableSpan>
) : <>{ tags.length > 0 ? tags.map(tag => <Tag key={ tag.id }>{ tag.name }</Tag>) : "-"}</>
}

export default CaseTags
15 changes: 10 additions & 5 deletions src/app/components/case/CaseStatus/CaseStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

import styled from "styled-components"
import { Button, Divider, Heading, themeSpacing } from "@amsterdam/asc-ui"
import { Divider, Heading, themeSpacing } from "@amsterdam/asc-ui"

import Workflow from "../Workflow/Workflow"
import { Row, Column, RowWithColumn } from "app/components/layouts/Grid"
import ButtonLink from "app/components/shared/ButtonLink/ButtonLink"
import to from "app/routing/utils/to"
import IsAuthorizedButtonLink from "app/components/shared/ButtonLink/IsAuthorizedButtonLink"
import { CAN_PERFORM_TASK } from "app/state/rest/custom/usePermissions/useHasPermission"

type Props = {
id: Components.Schemas.CaseDetail["id"]
Expand All @@ -29,9 +30,13 @@ const CaseStatus: React.FC<Props> = ({ id }) => (
</Column>
<Column spanSmall={ 50 } spanLarge={ 50 }>
<ButtonWrap>
<ButtonLink to={ to("/zaken/:id/taak", { id }) }>
<Button as="span" variant="tertiary">Taak opvoeren</Button>
</ButtonLink>
<IsAuthorizedButtonLink
permissionNames={ [CAN_PERFORM_TASK] }
to={ to("/zaken/:id/taak", { id }) }
text="Taak opvoeren"
variant="tertiary"
data-testid="btn_add_extra_task"
/>
</ButtonWrap>
</Column>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createNameAbbreviation } from "app/components/shared/Helpers/helpers"
import CustomTooltip from "app/components/help/HelpContent/CustomTooltip"
import { makeApiUrl } from "app/state/rest/hooks/utils/apiUrl"
import UserIcon from "./UserInitials"
import useHasPermission, { CAN_PERFORM_TASK } from "app/state/rest/custom/usePermissions/useHasPermission"


type Props = {
Expand All @@ -33,8 +34,8 @@ const SelectTaskWorkflow: React.FC<Props> = ({ task }) => {
const [me, { isBusy }] = useUsersMe()
const [, { execPatch }] = useTask(taskId)
const apiUrl = makeApiUrl("cases", caseId, "workflows")

const { getContextItem, updateContextItem } = useContextCache("cases", apiUrl)
const [hasPermission] = useHasPermission([CAN_PERFORM_TASK])

useEffect(() => {
// Check if userId is matching with the taskOwner.
Expand Down Expand Up @@ -88,13 +89,13 @@ const SelectTaskWorkflow: React.FC<Props> = ({ task }) => {
if (taskOwner && taskOwner !== me?.id ) {
return <UserIcon owner={ taskOwner }/>
}
return (
return hasPermission ? (
<StyledLabel htmlFor={ `cb_${ taskId }` } label={ me && me?.id === taskOwner ? `${ createNameAbbreviation(me) }` : "" }>
<CustomTooltip title={ isChecked ? "Mijn taak" : "Beschikbaar" }>
<StyledCheckbox data-testid={ `${ taskId }` } id={ `cb_${ taskId }` } checked={ isChecked } onChange={ onChange }/>
</CustomTooltip>
</StyledLabel>
)
) : <>-</>
}

export default SelectTaskWorkflow
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { appendTimeToDate } from "app/components/shared/Helpers/helpers"
import DueDate from "app/components/shared/DueDate/DueDate"
import ChangeDueDateModal from "./ChangeDueDateModal"
import { useTaskUpdate } from "app/state/rest"
import useHasPermission, { CAN_PERFORM_TASK } from "app/state/rest/custom/usePermissions/useHasPermission"

type Props = {
caseId: Components.Schemas.CaseDetail["id"]
Expand All @@ -30,17 +31,17 @@ const StyledIcon = styled(Icon)`
`

const ChangeableDueDate: React.FC<Props> = ({ dueDate, caseId, caseUserTaskId }) => {

const { isModalOpen, openModal, closeModal } = useModal()
const [, { execPatch }] = useTaskUpdate(caseUserTaskId)
const [hasPermission] = useHasPermission([CAN_PERFORM_TASK])

const onSubmit = (data: { date: string, id: string }) => {
appendTimeToDate(data.date) !== dueDate
? execPatch( { due_date: appendTimeToDate( data.date ) })
: closeModal()
}

return (
return hasPermission ? (
<>
<Span
role="link"
Expand All @@ -57,7 +58,7 @@ const ChangeableDueDate: React.FC<Props> = ({ dueDate, caseId, caseUserTaskId })
taskId={ caseUserTaskId }
/>
</>
)
) : <DueDate date={ dueDate } />
}

export default ChangeableDueDate
8 changes: 5 additions & 3 deletions src/app/components/tasks/TableTasks/SelectTask/SelectTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UserIcon from "./UserIcon"
import useContextCache from "app/state/rest/provider/useContextCache"
import { createNameAbbreviation } from "app/components/shared/Helpers/helpers"
import CustomTooltip from "app/components/help/HelpContent/CustomTooltip"
import useHasPermission, { SENSITIVE_CASE_PERMISSION } from "app/state/rest/custom/usePermissions/useHasPermission"
import useHasPermission, { CAN_PERFORM_TASK, SENSITIVE_CASE_PERMISSION } from "app/state/rest/custom/usePermissions/useHasPermission"
import { ContextValues } from "app/state/context/ValueProvider"
import { getQueryUrl } from "app/state/rest/tasks"

Expand Down Expand Up @@ -37,6 +37,7 @@ const SelectTask: React.FC<Props> = ({ taskId, taskOwner, isEnforcement }) => {
tags, taskNames, reason, districtNames, housingCorporations
} = useContext(ContextValues)["tasks"]
const [hasPermission] = useHasPermission([SENSITIVE_CASE_PERMISSION])
const [hasPerformTaskPermission] = useHasPermission([CAN_PERFORM_TASK])
const [isChecked, setIsChecked] = useState(false)
const [loading, setLoading] = useState(false)
const [data, { isBusy }] = useUsersMe()
Expand Down Expand Up @@ -93,13 +94,14 @@ const SelectTask: React.FC<Props> = ({ taskId, taskOwner, isEnforcement }) => {
if (taskOwner && taskOwner !== data?.id ) {
return <UserIcon owner={ taskOwner }/>
}
return (

return hasPerformTaskPermission ? (
<StyledLabel htmlFor={ `cb_${ taskId }` } label={ data && data?.id === taskOwner ? `${ createNameAbbreviation(data) }` : "" }>
<CustomTooltip title={ isChecked ? "Mijn taak" : "Beschikbaar" }>
<Checkbox data-testid={ `${ taskId }` } id={ `cb_${ taskId }` } checked={ isChecked } onChange={ onChange }/>
</CustomTooltip>
</StyledLabel>
)
) : <>-</>
}

export default SelectTask
Loading

0 comments on commit d8a4650

Please sign in to comment.