Skip to content

Commit

Permalink
feat(kotoutumiskoulutus): add audit log event entries when viewing ko…
Browse files Browse the repository at this point in the history
…to suoritus
  • Loading branch information
saku-koodari committed Jan 10, 2025
1 parent 278627c commit 72a2377
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import org.springframework.web.servlet.ModelAndView
@Controller
@RequestMapping("koto-kielitesti", produces = ["text/html"])
class KielitestiViewController(
private val suoritusRepository: KielitestiSuoritusRepository,
private val suoritusService: KoealustaService,
) {
@GetMapping("/suoritukset")
fun suorituksetView(): ModelAndView {
val suoritukset: List<KielitestiSuoritus> = suoritusRepository.findAll().toList()

val modelAndView = ModelAndView("koto-kielitesti-suoritukset")
modelAndView.addObject("suoritukset", suoritukset)
modelAndView.addObject("suoritukset", suoritusService.getSuoritukset())

return modelAndView
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fi.oph.kitu.PeerService
import fi.oph.kitu.logging.Logging
import fi.oph.kitu.logging.add
import fi.oph.kitu.logging.addHttpResponse
import fi.oph.kitu.logging.addUser
import fi.oph.kitu.logging.withEventAndPerformanceCheck
import fi.oph.kitu.oppijanumero.addValidationExceptions
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -31,6 +32,18 @@ class KoealustaService(

private val restClient by lazy { restClientBuilder.baseUrl(koealustaBaseUrl).build() }

fun getSuoritukset() =
kielitestiSuoritusRepository.findAll().toList().also {
for (suoritus in it) {
auditLogger
.atInfo()
.addUser()
.add(
"suoritus.id" to suoritus.id,
).log("Kielitesti suoritus viewed")
}
}

fun importSuoritukset(from: Instant) =
logger
.atInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ class KoealustaServiceTests {
KoealustaService(
restClientBuilder = mockRestClientBuilder,
kielitestiSuoritusRepository = kielitestiSuoritusRepository,
jacksonObjectMapper = objectMapper,
mappingService = KoealustaMappingService(OppijanumeroServiceMock("123")),
mappingService =
KoealustaMappingService(
objectMapper,
OppijanumeroServiceMock("123"),
),
)

koealustaService.koealustaToken = "token"
Expand Down

0 comments on commit 72a2377

Please sign in to comment.