Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Muutetaan ryhmät-välilehden yhteystietokooste-linkki tukemaan käyttöoikeussääntöjä #5992

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions frontend/src/employee-frontend/components/Reports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import React, { Fragment, ReactNode, useContext, useMemo } from 'react'
import { Link } from 'react-router-dom'
import styled from 'styled-components'

import { wrapResult } from 'lib-common/api'
import { useApiState } from 'lib-common/utils/useRestApi'
import { useQueryResult } from 'lib-common/query'
import RoundIcon from 'lib-components/atoms/RoundIcon'
import Title from 'lib-components/atoms/Title'
import { Container, ContentArea } from 'lib-components/layout/Container'
Expand Down Expand Up @@ -37,13 +36,11 @@ import {
faUtensils
} from 'lib-icons'

import { getPermittedReports } from '../generated/api-clients/reports'
import { useTranslation } from '../state/i18n'

import { renderResult } from './async-rendering'
import { AssistanceNeedDecisionReportContext } from './reports/AssistanceNeedDecisionReportContext'

const getPermittedReportsResult = wrapResult(getPermittedReports)
import { permittedReportsQuery } from './reports/queries'

const ReportItems = styled.div`
margin: 20px 0;
Expand Down Expand Up @@ -122,7 +119,7 @@ export default React.memo(function Reports() {
AssistanceNeedDecisionReportContext
)

const [permittedReports] = useApiState(getPermittedReportsResult, [])
const permittedReports = useQueryResult(permittedReportsQuery())
const permittedReportsSet = useMemo(
() => permittedReports.map((reports) => new Set(reports)),
[permittedReports]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ import { faChevronDown, faChevronUp } from 'lib-icons'
import ReportDownload from '../../components/reports/ReportDownload'
import {
getAssistanceNeedsAndActionsReport,
getAssistanceNeedsAndActionsReportByChild,
getPermittedReports
getAssistanceNeedsAndActionsReportByChild
} from '../../generated/api-clients/reports'
import { useTranslation } from '../../state/i18n'
import { reducePropertySum } from '../../utils'
import { renderResult } from '../async-rendering'
import { areaQuery, unitsQuery } from '../unit/queries'

import { FilterLabel, FilterRow, TableFooter, TableScrollable } from './common'
import { permittedReportsQuery } from './queries'

const getPermittedReportsResult = wrapResult(getPermittedReports)
const getAssistanceNeedsAndActionsReportResult = wrapResult(
getAssistanceNeedsAndActionsReport
)
Expand Down Expand Up @@ -277,7 +276,7 @@ const resolveGroupingType = (

export default React.memo(function AssistanceNeedsAndActions() {
const { i18n } = useTranslation()
const [permittedReports] = useApiState(getPermittedReportsResult, [])
const permittedReports = useQueryResult(permittedReportsQuery())
const [filters, setFilters] =
useState<AssistanceNeedsAndActionsReportFilters>({
date: LocalDate.todayInSystemTz()
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/employee-frontend/components/reports/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getNonSsnChildrenReportRows,
getOccupancyGroupReport,
getOccupancyUnitReport,
getPermittedReports,
getPlacementGuaranteeReport,
getPreschoolAbsenceReport,
getPreschoolApplicationReport,
Expand All @@ -43,6 +44,7 @@ import { createQueryKeys } from '../../query'
import { OccupancyReportFilters } from './Occupancies'

const queryKeys = createQueryKeys('reports', {
permittedReports: () => ['permittedReports'],
attendanceReservationByChild: (
filters: Arg0<typeof getAttendanceReservationReportByChild>
) => ['attendanceReservationByUnitAndChild', filters],
Expand Down Expand Up @@ -100,6 +102,11 @@ const queryKeys = createQueryKeys('reports', {
) => ['startingPlacementsReport', filters]
})

export const permittedReportsQuery = query({
api: getPermittedReports,
queryKey: queryKeys.permittedReports
})

export const attendanceReservationReportByChildQuery = query({
api: getAttendanceReservationReportByChild,
queryKey: queryKeys.attendanceReservationByChild
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from 'lib-common/generated/api-types/daycare'
import { OccupancyResponse } from 'lib-common/generated/api-types/occupancy'
import { DaycarePlacementWithDetails } from 'lib-common/generated/api-types/placement'
import { useQueryResult } from 'lib-common/query'
import { UUID } from 'lib-common/types'
import AddButton from 'lib-components/atoms/buttons/AddButton'
import { Button } from 'lib-components/atoms/buttons/Button'
Expand All @@ -40,6 +41,7 @@ import {
} from '../../../types/unit'
import { UnitFilters } from '../../../utils/UnitFilters'
import { requireRole } from '../../../utils/roles'
import { permittedReportsQuery } from '../../reports/queries'

function renderGroups(
unit: Daycare,
Expand Down Expand Up @@ -156,11 +158,10 @@ export default React.memo(function Groups({
}
}

const canSeeFamilyContactsReport = requireRole(
roles,
'ADMIN',
'UNIT_SUPERVISOR'
)
const permittedReportsResult = useQueryResult(permittedReportsQuery())
const canSeeFamilyContactsReport = permittedReportsResult
.map((reports) => reports.includes('FAMILY_CONTACT'))
.getOrElse(false)

return (
<>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib-common/generated/api-types/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ export type Report =
| 'ENDED_PLACEMENTS'
| 'EXCEEDED_SERVICE_NEEDS'
| 'FAMILY_CONFLICT'
| 'FAMILY_CONTACT'
| 'FAMILY_DAYCARE_MEAL_REPORT'
| 'HOLIDAY_PERIOD_ATTENDANCE'
| 'INVOICE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class Report {
ENDED_PLACEMENTS,
EXCEEDED_SERVICE_NEEDS,
FAMILY_CONFLICT,
FAMILY_CONTACT,
FAMILY_DAYCARE_MEAL_REPORT,
HOLIDAY_PERIOD_ATTENDANCE,
INVOICE,
Expand Down Expand Up @@ -133,6 +134,9 @@ class ReportPermissions(private val accessControl: AccessControl) {
Action.Unit.READ_FAMILY_CONFLICT_REPORT
)
},
Report.FAMILY_CONTACT.takeIf {
permittedActionsForSomeUnit.contains(Action.Unit.READ_FAMILY_CONTACT_REPORT)
},
Report.FAMILY_DAYCARE_MEAL_REPORT.takeIf {
permittedActionsForSomeUnit.contains(
Action.Unit.READ_FAMILY_DAYCARE_MEAL_REPORT
Expand Down