@@ -27,19 +27,23 @@ import fi.espoo.evaka.shared.ChildDocumentDecisionId
2727import fi.espoo.evaka.shared.ChildDocumentId
2828import fi.espoo.evaka.shared.DocumentTemplateId
2929import fi.espoo.evaka.shared.EmployeeId
30+ import fi.espoo.evaka.shared.PlacementId
3031import fi.espoo.evaka.shared.async.AsyncJob
3132import fi.espoo.evaka.shared.async.AsyncJobRunner
3233import fi.espoo.evaka.shared.auth.AuthenticatedUser
3334import fi.espoo.evaka.shared.auth.UserRole
3435import fi.espoo.evaka.shared.auth.insertDaycareAclRow
3536import fi.espoo.evaka.shared.dev.DevDaycare
37+ import fi.espoo.evaka.shared.dev.DevDaycareGroup
38+ import fi.espoo.evaka.shared.dev.DevDaycareGroupPlacement
3639import fi.espoo.evaka.shared.dev.DevDocumentTemplate
3740import fi.espoo.evaka.shared.dev.DevEmployee
3841import fi.espoo.evaka.shared.dev.DevPerson
3942import fi.espoo.evaka.shared.dev.DevPersonType
4043import fi.espoo.evaka.shared.dev.DevPlacement
4144import fi.espoo.evaka.shared.dev.DevSfiMessageEvent
4245import fi.espoo.evaka.shared.dev.insert
46+ import fi.espoo.evaka.shared.dev.insertEmployeeToDaycareGroupAcl
4347import fi.espoo.evaka.shared.domain.BadRequest
4448import fi.espoo.evaka.shared.domain.Conflict
4549import fi.espoo.evaka.shared.domain.DateRange
@@ -77,6 +81,7 @@ class ChildDocumentControllerIntegrationTest : FullApplicationTest(resetDbBefore
7781 lateinit var areaId: AreaId
7882 val employeeUser = DevEmployee (roles = setOf (UserRole .ADMIN ))
7983 lateinit var unitSupervisorUser: AuthenticatedUser .Employee
84+ lateinit var placementId: PlacementId
8085
8186 final val clock = MockEvakaClock (2022 , 1 , 1 , 15 , 0 )
8287
@@ -209,14 +214,15 @@ class ChildDocumentControllerIntegrationTest : FullApplicationTest(resetDbBefore
209214 tx.insert(testChild_1, DevPersonType .CHILD )
210215 tx.insert(testAdult_1, DevPersonType .ADULT )
211216 tx.insertGuardian(testAdult_1.id, testChild_1.id)
212- tx.insert(
213- DevPlacement (
214- childId = testChild_1.id,
215- unitId = testDaycare.id,
216- startDate = clock.today(),
217- endDate = clock.today().plusDays(5 ),
217+ placementId =
218+ tx.insert(
219+ DevPlacement (
220+ childId = testChild_1.id,
221+ unitId = testDaycare.id,
222+ startDate = clock.today(),
223+ endDate = clock.today().plusDays(5 ),
224+ )
218225 )
219- )
220226 tx.insert(devTemplatePed)
221227 tx.insert(devTemplatePedagogicalReport)
222228 tx.insert(devTemplateHojks)
@@ -1252,6 +1258,84 @@ class ChildDocumentControllerIntegrationTest : FullApplicationTest(resetDbBefore
12521258 )
12531259 }
12541260
1261+ @Test
1262+ fun `employee with STAFF permission can edit ordinary document but not decision document` () {
1263+ val groupId =
1264+ db.transaction { tx ->
1265+ val id = tx.insert(DevDaycareGroup (daycareId = testDaycare.id))
1266+ tx.insert(
1267+ DevDaycareGroupPlacement (
1268+ daycarePlacementId = placementId,
1269+ daycareGroupId = id,
1270+ startDate = clock.today(),
1271+ endDate = clock.today().plusDays(10 ),
1272+ )
1273+ )
1274+ id
1275+ }
1276+
1277+ val staffEmployee = DevEmployee ()
1278+ val staffUser =
1279+ db.transaction { tx ->
1280+ val staffId = tx.insert(staffEmployee)
1281+ tx.insertDaycareAclRow(testDaycare.id, staffId, UserRole .STAFF )
1282+ tx.insertEmployeeToDaycareGroupAcl(groupId, staffId)
1283+ AuthenticatedUser .Employee (staffId, setOf (UserRole .STAFF ))
1284+ }
1285+
1286+ // Create an ordinary child document (PEDAGOGICAL_ASSESSMENT)
1287+ val ordinaryDocumentId =
1288+ controller.createDocument(
1289+ dbInstance(),
1290+ employeeUser.user,
1291+ clock,
1292+ ChildDocumentCreateRequest (testChild_1.id, templateIdPed),
1293+ )
1294+
1295+ // Create a decision document (OTHER_DECISION)
1296+ val decisionDocumentId =
1297+ controller.createDocument(
1298+ dbInstance(),
1299+ employeeUser.user,
1300+ clock,
1301+ ChildDocumentCreateRequest (testChild_1.id, templateIdAssistanceDecision),
1302+ )
1303+
1304+ // Staff employee should be able to update the ordinary document
1305+ val laterClock = MockEvakaClock (clock.now().plusMinutes(6 ))
1306+ val ordinaryContent =
1307+ DocumentContent (answers = listOf (AnsweredQuestion .TextAnswer (" q1" , " staff edit" )))
1308+ updateDocumentContent(
1309+ ordinaryDocumentId,
1310+ ordinaryContent,
1311+ now = laterClock,
1312+ user = staffUser,
1313+ )
1314+
1315+ // Verify the update succeeded
1316+ assertEquals(
1317+ ordinaryContent,
1318+ controller
1319+ .getDocument(dbInstance(), staffUser, laterClock, ordinaryDocumentId)
1320+ .data
1321+ .content,
1322+ )
1323+
1324+ // Staff employee should NOT be able to update the decision document
1325+ val decisionContent =
1326+ DocumentContent (
1327+ answers = listOf (AnsweredQuestion .TextAnswer (" q1" , " staff edit decision" ))
1328+ )
1329+ assertThrows<Forbidden > {
1330+ updateDocumentContent(
1331+ decisionDocumentId,
1332+ decisionContent,
1333+ now = laterClock,
1334+ user = staffUser,
1335+ )
1336+ }
1337+ }
1338+
12551339 private fun getDocument (id : ChildDocumentId ) =
12561340 controller.getDocument(dbInstance(), employeeUser.user, clock, id).data
12571341
0 commit comments