Skip to content

Commit

Permalink
create copies also to employee accounts in the unit
Browse files Browse the repository at this point in the history
  • Loading branch information
Joosakur committed Nov 11, 2024
1 parent 11300e5 commit 0038709
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const personalMessageBoxes: View[] = [
'received',
'sent',
'drafts',
'copies',
'archive'
]
export const groupMessageBoxes: View[] = [
Expand Down
46 changes: 37 additions & 9 deletions service/src/main/kotlin/fi/espoo/evaka/messaging/MessageQueries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1343,15 +1343,43 @@ fun Database.Read.getStaffCopyRecipients(
return createQuery {
sql(
"""
SELECT receiver_acc.id
FROM message_account sender_acc
JOIN daycare_acl_view acl ON sender_acc.employee_id = acl.employee_id OR sender_acc.type = 'MUNICIPAL'
JOIN daycare u ON u.id = acl.daycare_id
JOIN daycare_group g ON u.id = g.daycare_id
JOIN message_account receiver_acc ON g.id = receiver_acc.daycare_group_id
WHERE sender_acc.id = ${bind(senderId)}
AND (g.end_date IS NULL OR g.end_date >= ${bind(date)})
AND (u.care_area_id = ANY(${bind(areaIds)}) OR u.id = ANY(${bind(unitIds)}) OR g.id = ANY(${bind(groupIds)}))
WITH sender AS (
SELECT id, employee_id, type
FROM message_account
WHERE id = ${bind(senderId)}
), groups AS (
SELECT u.id AS unit_id, g.id AS group_id
FROM daycare u
JOIN daycare_group g ON u.id = g.daycare_id
JOIN sender ON TRUE
WHERE (u.care_area_id = ANY(${bind(areaIds)}) OR u.id = ANY(${bind(unitIds)}) OR g.id = ANY(${bind(groupIds)}))
AND (sender.type = 'MUNICIPAL' OR EXISTS(
SELECT FROM daycare_acl_view acl
WHERE acl.daycare_id = u.id AND sender.employee_id = acl.employee_id
))
AND (u.closing_date IS NULL OR u.closing_date >= ${bind(date)})
AND (g.end_date IS NULL OR g.end_date >= ${bind(date)})
), units AS (
SELECT DISTINCT unit_id
FROM groups
), recipients AS (
-- group accounts
SELECT receiver_acc.id
FROM groups g
JOIN message_account receiver_acc ON receiver_acc.daycare_group_id = g.group_id
UNION ALL
-- unit supervisor and special education teacher accounts
SELECT receiver_acc.id
FROM units u
JOIN daycare_acl unit_employee ON unit_employee.daycare_id = u.unit_id
AND unit_employee.role = ANY('{UNIT_SUPERVISOR,SPECIAL_EDUCATION_TEACHER}'::user_role[])
JOIN message_account receiver_acc ON receiver_acc.employee_id = unit_employee.employee_id
)
SELECT id
FROM recipients
WHERE id <> ${bind(senderId)}
"""
)
}
Expand Down

0 comments on commit 0038709

Please sign in to comment.