Skip to content

Commit

Permalink
Kalenteri: Tieto jos työntekijä muokannut omaa/mahdollisesti toisen k…
Browse files Browse the repository at this point in the history
…alenterimerkintää
  • Loading branch information
kechpaja-at-gofore committed Nov 13, 2024
1 parent 27329b9 commit 6580f47
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 27 deletions.
1 change: 1 addition & 0 deletions frontend/src/e2e-test/dev-api/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ export class Fixture {
LocalDate.of(2020, 1, 1)
),
modifiedAt: LocalDate.of(2020, 1, 1).toHelsinkiDateTime(LocalTime.MIN),
modifiedBy: systemInternalUser.id,
eventType: 'DAYCARE_EVENT',
...initial
})
Expand Down
1 change: 1 addition & 0 deletions frontend/src/e2e-test/generated/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export interface DevCalendarEvent {
eventType: CalendarEventType
id: UUID
modifiedAt: HelsinkiDateTime
modifiedBy: UUID
period: FiniteDateRange
title: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import LocalDate from 'lib-common/local-date'
import { useQueryResult } from 'lib-common/query'
import { UUID } from 'lib-common/types'
import { useApiState } from 'lib-common/utils/useRestApi'
import Tooltip from 'lib-components/atoms/Tooltip'
import AddButton from 'lib-components/atoms/buttons/AddButton'
import { AsyncButton } from 'lib-components/atoms/buttons/AsyncButton'
import { Button } from 'lib-components/atoms/buttons/Button'
Expand All @@ -41,6 +42,7 @@ import TreeDropdown, {
} from 'lib-components/atoms/dropdowns/TreeDropdown'
import InputField from 'lib-components/atoms/form/InputField'
import TextArea from 'lib-components/atoms/form/TextArea'
import ListGrid from 'lib-components/layout/ListGrid'
import {
FixedSpaceColumn,
FixedSpaceRow
Expand Down Expand Up @@ -394,14 +396,21 @@ export default React.memo(function CalendarEventsSection({
className={`type-${specifier.type}`}
key={event.id}
>
<Link
to={`/units/${unitId}/calendar/events/${event.id}`}
data-qa="event"
<Tooltip
tooltip={i18n.unit.calendar.events.lastModified(
event.contentModifiedAt.format(),
event.contentModifiedBy.name
)}
>
<p>
<Bold>{specifier.text}:</Bold> {event.title}
</p>
</Link>
<Link
to={`/units/${unitId}/calendar/events/${event.id}`}
data-qa="event"
>
<p>
<Bold>{specifier.text}:</Bold> {event.title}
</p>
</Link>
</Tooltip>
</EventLinkContainer>
)
} else if (
Expand All @@ -413,21 +422,28 @@ export default React.memo(function CalendarEventsSection({
className={`type-${specifier.type}`}
key={event.id}
>
<Link
to={`/units/${unitId}/calendar/events/${event.id}?eventDay=${day.formatIso()}`}
data-qa="survey"
<Tooltip
tooltip={i18n.unit.calendar.events.lastModified(
event.contentModifiedAt.format(),
event.contentModifiedBy.name
)}
>
<P noMargin>
<Bold>{event.title}</Bold>
</P>

<P
noMargin
>{`${reservationsToday.length} ${i18n.unit.calendar.events.reservedTimesLabel}`}</P>
<P
noMargin
>{`${freeTimesToday.length} ${i18n.unit.calendar.events.freeTimesLabel}`}</P>
</Link>
<Link
to={`/units/${unitId}/calendar/events/${event.id}?eventDay=${day.formatIso()}`}
data-qa="survey"
>
<P noMargin>
<Bold>{event.title}</Bold>
</P>

<P
noMargin
>{`${reservationsToday.length} ${i18n.unit.calendar.events.reservedTimesLabel}`}</P>
<P
noMargin
>{`${freeTimesToday.length} ${i18n.unit.calendar.events.freeTimesLabel}`}</P>
</Link>
</Tooltip>
</EventLinkContainer>
)
} else return null
Expand Down Expand Up @@ -911,6 +927,19 @@ const EditEventModal = React.memo(function EditEventModal({
data-qa="description-input"
/>

<Gap size="m" />

<ListGrid>
<FixedSpaceColumn>
<Label>{i18n.unit.calendar.events.lastModifiedAt}</Label>
<Label>{i18n.unit.calendar.events.lastModifiedBy}</Label>
</FixedSpaceColumn>
<FixedSpaceColumn>
<span>{event.contentModifiedAt.format()}</span>
<span>{event.contentModifiedBy.name}</span>
</FixedSpaceColumn>
</ListGrid>

<Gap size="L" />
<FixedSpaceRow justifyContent="space-between">
<Button
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib-common/generated/api-types/calendarevent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import HelsinkiDateTime from '../../helsinki-date-time'
import LocalDate from '../../local-date'
import LocalTime from '../../local-time'
import TimeRange from '../../time-range'
import { EvakaUser } from './user'
import { JsonOf } from '../../json'
import { UUID } from '../../types'

Expand All @@ -35,6 +36,7 @@ export interface AttendingChild {
*/
export interface CalendarEvent {
contentModifiedAt: HelsinkiDateTime
contentModifiedBy: EvakaUser
description: string
eventType: CalendarEventType
groups: GroupInfo[]
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib-customizations/defaults/employee/i18n/fi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,10 @@ export const fi = {
events: {
title: 'Tapahtumat',
createEvent: 'Luo muu tapahtuma',
lastModified: (date: string, name: string) =>
`Viimeksi muokattu ${date}; muokkaaja: ${name}`,
lastModifiedAt: 'Viimeksi muokattu',
lastModifiedBy: 'Muokkaaja',
edit: {
title: 'Tapahtuma',
saveChanges: 'Tallenna muutokset',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import fi.espoo.evaka.daycare.domain.Language
import fi.espoo.evaka.shared.CalendarEventId
import fi.espoo.evaka.shared.ChildId
import fi.espoo.evaka.shared.DaycareId
import fi.espoo.evaka.shared.EvakaUserId
import fi.espoo.evaka.shared.GroupId
import fi.espoo.evaka.shared.dev.DevBackupCare
import fi.espoo.evaka.shared.dev.DevCalendarEvent
Expand Down Expand Up @@ -353,6 +354,7 @@ class CalendarEventNotificationQueriesTest : PureJdbiTest(resetDbBeforeEach = tr
description: String = "description",
period: FiniteDateRange,
created: HelsinkiDateTime = now,
createdBy: EvakaUserId = employee.evakaUserId,
unitId: DaycareId,
groupIds: List<GroupId> = listOf(),
groupChildIds: List<Pair<GroupId, ChildId>> = listOf(),
Expand All @@ -365,6 +367,7 @@ class CalendarEventNotificationQueriesTest : PureJdbiTest(resetDbBeforeEach = tr
description = description,
period = period,
modifiedAt = created,
modifiedBy = createdBy,
eventType = CalendarEventType.DAYCARE_EVENT,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2817,6 +2817,7 @@ class CalendarEventServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
eventType = CalendarEventType.DISCUSSION_SURVEY,
period = FiniteDateRange(today.plusDays(3), today.plusDays(3)),
modifiedAt = now,
modifiedBy = admin.evakaUserId,
)
val eventTime =
DevCalendarEventTime(
Expand Down Expand Up @@ -2887,6 +2888,7 @@ class CalendarEventServiceIntegrationTest : FullApplicationTest(resetDbBeforeEac
eventType = CalendarEventType.DISCUSSION_SURVEY,
period = FiniteDateRange(today.plusDays(3), today.plusDays(3)),
modifiedAt = now,
modifiedBy = admin.evakaUserId,
)
val pastEventTime =
DevCalendarEventTime(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import fi.espoo.evaka.shared.GroupId
import fi.espoo.evaka.shared.domain.FiniteDateRange
import fi.espoo.evaka.shared.domain.HelsinkiDateTime
import fi.espoo.evaka.shared.domain.TimeRange
import fi.espoo.evaka.user.EvakaUser
import java.time.LocalDate
import java.time.LocalTime
import org.jdbi.v3.core.mapper.Nested
import org.jdbi.v3.json.Json

data class GroupInfo(val id: GroupId, val name: String)
Expand All @@ -35,6 +37,7 @@ data class CalendarEvent(
val period: FiniteDateRange,
@Json val times: Set<CalendarEventTime>,
val contentModifiedAt: HelsinkiDateTime,
@Nested("content_modified_by") val contentModifiedBy: EvakaUser,
val eventType: CalendarEventType,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ private fun Database.Read.getCalendarEventsQuery(where: PredicateSql) = createQu
sql(
"""
SELECT
ce.id, cea.unit_id, ce.title, ce.description, ce.period, ce.content_modified_at, ce.event_type,
ce.id,
cea.unit_id,
ce.title,
ce.description,
ce.period,
ce.content_modified_at,
eu.id AS content_modified_by_id,
eu.name AS content_modified_by_name,
eu.type AS content_modified_by_type,
ce.event_type,
(
coalesce(jsonb_agg(DISTINCT jsonb_build_object(
'id', cea.group_id,
Expand Down Expand Up @@ -61,6 +70,7 @@ JOIN calendar_event ce ON cea.calendar_event_id = ce.id
LEFT JOIN daycare_group dg ON dg.id = cea.group_id
LEFT JOIN person p ON p.id = cea.child_id
LEFT JOIN calendar_event_time cet ON cet.calendar_event_id = ce.id
LEFT JOIN evaka_user eu ON eu.id = ce.content_modified_by
WHERE ${predicate(where)}
AND (cea.child_id IS NULL OR EXISTS(
-- filter out attendees that haven't been placed in the specified unit/group,
Expand All @@ -71,7 +81,7 @@ AND (cea.child_id IS NULL OR EXISTS(
AND (cea.group_id IS NULL OR rp.group_id = cea.group_id)
AND rp.unit_id = cea.unit_id
))
GROUP BY ce.id, cea.unit_id
GROUP BY ce.id, cea.unit_id, eu.id
"""
)
}
Expand Down Expand Up @@ -101,8 +111,8 @@ fun Database.Transaction.createCalendarEvent(
createUpdate {
sql(
"""
INSERT INTO calendar_event (created_at, title, description, period, modified_at, content_modified_at, event_type)
VALUES (${bind(createdAt)}, ${bind(event.title)}, ${bind(event.description)}, ${bind(event.period)}, ${bind(createdAt)}, ${bind(createdAt)}, ${bind(event.eventType)})
INSERT INTO calendar_event (created_at, created_by, title, description, period, modified_at, modified_by, content_modified_at, content_modified_by, event_type)
VALUES (${bind(createdAt)}, ${bind(createdBy)}, ${bind(event.title)}, ${bind(event.description)}, ${bind(event.period)}, ${bind(createdAt)}, ${bind(createdBy)}, ${bind(createdAt)}, ${bind(createdBy)}, ${bind(event.eventType)})
RETURNING id
"""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1333,8 +1333,8 @@ fun Database.Transaction.insert(row: DevCalendarEvent): CalendarEventId =
createUpdate {
sql(
"""
INSERT INTO calendar_event (id, title, description, period, modified_at, content_modified_at, event_type)
VALUES (${bind(row.id)}, ${bind(row.title)}, ${bind(row.description)}, ${bind(row.period)}, ${bind(row.modifiedAt)}, ${bind(row.modifiedAt)}, ${bind(row.eventType)})
INSERT INTO calendar_event (id, title, description, period, created_at, created_by, modified_at, modified_by, content_modified_at, content_modified_by, event_type)
VALUES (${bind(row.id)}, ${bind(row.title)}, ${bind(row.description)}, ${bind(row.period)}, ${bind(row.modifiedAt)}, ${bind(row.modifiedBy)}, ${bind(row.modifiedAt)}, ${bind(row.modifiedBy)}, ${bind(row.modifiedAt)}, ${bind(row.modifiedBy)}, ${bind(row.eventType)})
RETURNING id
"""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,7 @@ data class DevCalendarEvent(
val description: String,
val period: FiniteDateRange,
val modifiedAt: HelsinkiDateTime,
val modifiedBy: EvakaUserId,
val eventType: CalendarEventType,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ALTER TABLE calendar_event
ADD COLUMN created_by UUID REFERENCES evaka_user,
ADD COLUMN modified_by UUID REFERENCES evaka_user,
ADD COLUMN content_modified_by UUID REFERENCES evaka_user;

UPDATE calendar_event SET
created_by = COALESCE(created_by, '00000000-0000-0000-0000-000000000000'::UUID),
modified_by = COALESCE(modified_by, '00000000-0000-0000-0000-000000000000'::UUID),
content_modified_by = COALESCE(content_modified_by, '00000000-0000-0000-0000-000000000000'::UUID);

ALTER TABLE calendar_event
ALTER COLUMN created_by SET NOT NULL,
ALTER COLUMN modified_by SET NOT NULL,
ALTER COLUMN content_modified_by SET NOT NULL;

CREATE INDEX fk$calendar_event_created_by ON calendar_event(created_by);
CREATE INDEX fk$calendar_event_modified_by ON calendar_event(modified_by);
CREATE INDEX fk$calendar_event_content_modified_by ON calendar_event(content_modified_by);
1 change: 1 addition & 0 deletions service/src/main/resources/migrations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,4 @@ V459__modified_for_message_draft.sql
V460__modification_metadata.sql
V461__replacement_invoices.sql
V462__drop_table_holiday.sql
V463__calendar_event_modified_by.sql

0 comments on commit 6580f47

Please sign in to comment.