Skip to content

Commit

Permalink
Manglet request context, som gjorde at pepclient ikke kunne finne idt…
Browse files Browse the repository at this point in the history
…oken
  • Loading branch information
mbolstad committed Oct 31, 2024
1 parent d48d70c commit 6b36ac3
Showing 1 changed file with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,56 @@ import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import no.nav.k9.los.integrasjon.abac.IPepClient
import no.nav.k9.los.integrasjon.rest.RequestContextService
import no.nav.k9.los.tjenester.avdelingsleder.oppgaveko.IdDto
import org.koin.ktor.ext.inject
import java.util.*

fun Route.DriftsmeldingerApis() {
val driftsmeldingTjeneste by inject<DriftsmeldingTjeneste>()
val requestContextService by inject<RequestContextService>()
val pepClient by inject<IPepClient>()
val driftsmeldingTjeneste by inject<DriftsmeldingTjeneste>()

get("/") {
if (pepClient.harBasisTilgang()) {
call.respond(driftsmeldingTjeneste.hentDriftsmeldinger())
} else {
call.respond(HttpStatusCode.Forbidden)
get {
requestContextService.withRequestContext(call) {
if (pepClient.harBasisTilgang()) {
call.respond(driftsmeldingTjeneste.hentDriftsmeldinger())
} else {
call.respond(HttpStatusCode.Forbidden)
}
}
}

post("/") {
if (pepClient.harBasisTilgang()) {
val melding = call.receive<Driftsmelding>()
call.respond(driftsmeldingTjeneste.leggTilDriftsmelding(melding.driftsmelding))
} else {
call.respond(HttpStatusCode.Forbidden)
post {
requestContextService.withRequestContext(call) {
if (pepClient.kanLeggeUtDriftsmelding()) {
val melding = call.receive<Driftsmelding>()
call.respond(driftsmeldingTjeneste.leggTilDriftsmelding(melding.driftsmelding))
} else {
call.respond(HttpStatusCode.Forbidden)
}
}
}

post("/slett") {
if (pepClient.harBasisTilgang()) {
val param = call.receive<IdDto>()
call.respond(driftsmeldingTjeneste.slettDriftsmelding(UUID.fromString(param.id)))
} else {
call.respond(HttpStatusCode.Forbidden)
requestContextService.withRequestContext(call) {
if (pepClient.kanLeggeUtDriftsmelding()) {
val param = call.receive<IdDto>()
call.respond(driftsmeldingTjeneste.slettDriftsmelding(UUID.fromString(param.id)))
} else {
call.respond(HttpStatusCode.Forbidden)
}
}
}

post("/toggle") {
if (pepClient.harBasisTilgang()) {
val param = call.receive<DriftsmeldingSwitch>()
call.respond(driftsmeldingTjeneste.toggleDriftsmelding(param))
} else {
call.respond(HttpStatusCode.Forbidden)
requestContextService.withRequestContext(call) {
if (pepClient.kanLeggeUtDriftsmelding()) {
val param = call.receive<DriftsmeldingSwitch>()
call.respond(driftsmeldingTjeneste.toggleDriftsmelding(param))
} else {
call.respond(HttpStatusCode.Forbidden)
}
}
}
}

0 comments on commit 6b36ac3

Please sign in to comment.