diff --git a/src/main/kotlin/no/nav/k9/los/nyoppgavestyring/query/OppgaveQueryApis.kt b/src/main/kotlin/no/nav/k9/los/nyoppgavestyring/query/OppgaveQueryApis.kt index 6bcbb6380..5dcb0cf05 100644 --- a/src/main/kotlin/no/nav/k9/los/nyoppgavestyring/query/OppgaveQueryApis.kt +++ b/src/main/kotlin/no/nav/k9/los/nyoppgavestyring/query/OppgaveQueryApis.kt @@ -6,18 +6,20 @@ import io.ktor.server.locations.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.Route +import no.nav.k9.los.integrasjon.abac.IPepClient import no.nav.k9.los.integrasjon.rest.RequestContextService import no.nav.k9.los.integrasjon.rest.idToken import no.nav.k9.los.nyoppgavestyring.query.db.OppgaveQueryRepository import no.nav.k9.los.nyoppgavestyring.query.dto.query.OppgaveQuery import no.nav.k9.los.tjenester.avdelingsleder.nokkeltall.tilCsv +import org.koin.java.KoinJavaComponent import org.koin.ktor.ext.inject import java.util.* fun Route.OppgaveQueryApis() { val requestContextService by inject() - val oppgaveQueryRepository by inject() val oppgaveQueryService by inject() + val pepClient by KoinJavaComponent.inject(IPepClient::class.java) @Location("/query") class queryOppgave @@ -30,6 +32,19 @@ fun Route.OppgaveQueryApis() { } } + @Location("/validate") + class validateOppgave + + post { _: validateOppgave -> + val oppgaveQuery = call.receive() + requestContextService.withRequestContext(call) { + if (!pepClient.erOppgaveStyrer()) { + call.respond(HttpStatusCode.Forbidden); + } + call.respond(oppgaveQueryService.validate(oppgaveQuery)) + } + } + @Location("/queryToFile") class queryOppgaveToFile diff --git a/src/main/kotlin/no/nav/k9/los/nyoppgavestyring/query/OppgaveQueryService.kt b/src/main/kotlin/no/nav/k9/los/nyoppgavestyring/query/OppgaveQueryService.kt index 8316409c7..9c0ef95dd 100644 --- a/src/main/kotlin/no/nav/k9/los/nyoppgavestyring/query/OppgaveQueryService.kt +++ b/src/main/kotlin/no/nav/k9/los/nyoppgavestyring/query/OppgaveQueryService.kt @@ -16,6 +16,7 @@ import no.nav.k9.los.nyoppgavestyring.visningoguttrekk.Oppgave import no.nav.k9.los.nyoppgavestyring.visningoguttrekk.OppgaveRepository import no.nav.k9.los.tjenester.saksbehandler.IIdToken import org.koin.java.KoinJavaComponent.inject +import java.lang.RuntimeException import javax.sql.DataSource class OppgaveQueryService() { @@ -134,4 +135,14 @@ class OppgaveQueryService() { it.transaction { tx -> queryToFile(tx, oppgaveQuery, idToken) } } } + + fun validate(oppgaveQuery: OppgaveQuery): Boolean { + try { + queryForOppgaveId(oppgaveQuery) + } catch (e: RuntimeException) { + return false + } + + return true + } } \ No newline at end of file