Skip to content

Commit 92f2dd3

Browse files
committed
Remove out of office permissions from ordinary employees
1 parent 69b20b7 commit 92f2dd3

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

service/src/integrationTest/kotlin/fi/espoo/evaka/outofoffice/OutOfOfficeIntegrationTest.kt

+43
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import fi.espoo.evaka.shared.dev.DevDaycare
1414
import fi.espoo.evaka.shared.dev.DevEmployee
1515
import fi.espoo.evaka.shared.dev.insert
1616
import fi.espoo.evaka.shared.domain.FiniteDateRange
17+
import fi.espoo.evaka.shared.domain.Forbidden
1718
import fi.espoo.evaka.shared.domain.RealEvakaClock
1819
import java.util.*
1920
import kotlin.test.Test
2021
import kotlin.test.assertEquals
2122
import org.junit.jupiter.api.BeforeEach
23+
import org.junit.jupiter.api.assertThrows
2224
import org.springframework.beans.factory.annotation.Autowired
2325

2426
class OutOfOfficeIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
@@ -91,4 +93,45 @@ class OutOfOfficeIntegrationTest : FullApplicationTest(resetDbBeforeEach = true)
9193
outOfOfficeController.getOutOfOfficePeriods(dbInstance(), employee, clock)
9294
assertEquals(0, deletedPeriods.size)
9395
}
96+
97+
@Test
98+
fun `ordinary employees cannot see or create out of office periods`() {
99+
val ordinaryEmployee =
100+
AuthenticatedUser.Employee(
101+
id = EmployeeId(UUID.randomUUID()),
102+
roles = setOf(UserRole.STAFF),
103+
)
104+
105+
db.transaction { tx ->
106+
tx.insert(DevEmployee(id = ordinaryEmployee.id))
107+
tx.insertDaycareAclRow(
108+
daycareId = daycare.id,
109+
employeeId = ordinaryEmployee.id,
110+
UserRole.STAFF,
111+
)
112+
}
113+
114+
val period =
115+
OutOfOfficePeriodUpsert(
116+
id = null,
117+
period =
118+
FiniteDateRange(
119+
start = clock.today().plusDays(1),
120+
end = clock.today().plusDays(2),
121+
),
122+
)
123+
124+
assertThrows<Forbidden> {
125+
outOfOfficeController.getOutOfOfficePeriods(dbInstance(), ordinaryEmployee, clock)
126+
}
127+
128+
assertThrows<Forbidden> {
129+
outOfOfficeController.upsertOutOfOfficePeriod(
130+
dbInstance(),
131+
ordinaryEmployee,
132+
clock,
133+
period,
134+
)
135+
}
136+
}
94137
}

service/src/main/kotlin/fi/espoo/evaka/shared/security/Action.kt

+2-10
Original file line numberDiff line numberDiff line change
@@ -1444,16 +1444,8 @@ sealed interface Action {
14441444
IsMobile(false).isAssociatedWithEmployee(),
14451445
IsEmployee.isInSameUnitWithEmployee(),
14461446
),
1447-
READ_OUT_OF_OFFICE(
1448-
HasGlobalRole(ADMIN),
1449-
HasUnitRole(UNIT_SUPERVISOR).inAnyUnit(),
1450-
IsEmployee.self(),
1451-
),
1452-
UPDATE_OUT_OF_OFFICE(
1453-
HasGlobalRole(ADMIN),
1454-
HasUnitRole(UNIT_SUPERVISOR).inAnyUnit(),
1455-
IsEmployee.self(),
1456-
);
1447+
READ_OUT_OF_OFFICE(HasGlobalRole(ADMIN), HasUnitRole(UNIT_SUPERVISOR).inAnyUnit()),
1448+
UPDATE_OUT_OF_OFFICE(HasGlobalRole(ADMIN), HasUnitRole(UNIT_SUPERVISOR).inAnyUnit());
14571449

14581450
override fun toString(): String = "${javaClass.name}.$name"
14591451
}

0 commit comments

Comments
 (0)