Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lagre informasjon om hvem som oppretter behandling #98

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .nais/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ env:
BIDRAG_TILGANGSKONTROLL_URL: http://bidrag-tilgangskontroll-feature
BIDRAG_TILGANGGSKONTROLL_SCOPE: dev-gcp.bidrag.bidrag-tilgangskontroll-feature
TOPIC_VEDTAK: bidrag.vedtak-feature
BIDRAG_ORGANISASJON_SCOPE: dev-fss.bidrag.bidrag-organisasjon
BIDRAG_ORGANISASJON_URL: https://bidrag-organisasjon-feature.dev-fss-pub.nais.io/bidrag-organisasjon
JAVA_TOOL_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
kafka:
pool: nav-dev
Expand All @@ -39,4 +41,5 @@ outbound-access-apps:
- bidrag-dokument-forsendelse-feature
- bidrag-tilgangskontroll-feature
outbound-access-hosts:
- bidrag-person-feature.dev-fss-pub.nais.io
- bidrag-person-feature.dev-fss-pub.nais.io
- bidrag-organisasjon-feature.dev-fss-pub.nais.io
5 changes: 4 additions & 1 deletion .nais/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
BIDRAG_FORSENDELSE_SCOPE: dev-gcp.bidrag.bidrag-dokument-forsendelse
BIDRAG_TILGANGSKONTROLL_URL: http://bidrag-tilgangskontroll
BIDRAG_TILGANGGSKONTROLL_SCOPE: dev-gcp.bidrag.bidrag-tilgangskontroll
BIDRAG_ORGANISASJON_SCOPE: dev-fss.bidrag.bidrag-organisasjon
BIDRAG_ORGANISASJON_URL: https://bidrag-organisasjon.dev-fss-pub.nais.io/bidrag-organisasjon
TOPIC_VEDTAK: bidrag.vedtak-syntetisk
JAVA_TOOL_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
kafka:
Expand Down Expand Up @@ -39,4 +41,5 @@ outbound-access-apps:
- bidrag-dokument-forsendelse
- bidrag-tilgangskontroll
outbound-access-hosts:
- bidrag-person.dev-fss-pub.nais.io
- bidrag-person.dev-fss-pub.nais.io
- bidrag-organisasjon.dev-fss-pub.nais.io
5 changes: 4 additions & 1 deletion .nais/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
BIDRAG_FORSENDELSE_SCOPE: prod-gcp.bidrag.bidrag-dokument-forsendelse
BIDRAG_TILGANGSKONTROLL_URL: http://bidrag-tilgangskontroll
BIDRAG_TILGANGGSKONTROLL_SCOPE: prod-gcp.bidrag.bidrag-tilgangskontroll
BIDRAG_ORGANISASJON_SCOPE: prod-fss.bidrag.bidrag-organisasjon
BIDRAG_ORGANISASJON_URL: https://bidrag-organisasjon.prod-fss-pub.nais.io/bidrag-organisasjon
TOPIC_VEDTAK: bidrag.vedtak
kafka:
pool: nav-prod
Expand All @@ -38,4 +40,5 @@ outbound-access-apps:
- bidrag-dokument-forsendelse
- bidrag-tilgangskontroll
outbound-access-hosts:
- bidrag-person.prod-fss-pub.nais.io
- bidrag-person.prod-fss-pub.nais.io
- bidrag-organisasjon.prod-fss-pub.nais.io
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<properties>
<java.version>21</java.version>
<kotlin.version>1.9.21</kotlin.version>
<bidrag-commons.version>20231124134729_6778484</bidrag-commons.version>
<bidrag-commons.version>20231201131246_f719b2b</bidrag-commons.version>
<bidrag-transport.version>20231129081122_595a8a8</bidrag-transport.version>
<logback-encoder.version>7.4</logback-encoder.version>
<token-support.version>3.1.9</token-support.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.datatype.jsr310.deser.YearMonthDeserializer
import com.fasterxml.jackson.module.kotlin.KotlinModule
import no.nav.bidrag.commons.security.api.EnableSecurityConfiguration
import no.nav.bidrag.commons.service.AppContext
import no.nav.bidrag.commons.service.organisasjon.EnableSaksbehandlernavnProvider
import no.nav.bidrag.commons.web.config.RestOperationsAzure
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand All @@ -16,7 +18,8 @@ import java.time.format.DateTimeFormatter

@Configuration
@EnableSecurityConfiguration
@Import(RestOperationsAzure::class)
@EnableSaksbehandlernavnProvider
@Import(RestOperationsAzure::class, AppContext::class)
class RestConfig {
@Bean
fun jackson2ObjectMapperBuilder(): Jackson2ObjectMapperBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import no.nav.bidrag.behandling.transformers.toLocalDate
import no.nav.bidrag.behandling.transformers.toRolle
import no.nav.bidrag.behandling.transformers.toRolleTypeDto
import no.nav.bidrag.behandling.transformers.toSivilstandDto
import no.nav.bidrag.commons.security.utils.TokenUtils
import no.nav.bidrag.commons.service.organisasjon.SaksbehandlernavnProvider
import org.apache.commons.lang3.Validate
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
Expand Down Expand Up @@ -63,6 +65,11 @@ class BehandlingController(private val behandlingService: BehandlingService) {
),
)

val opprettetAv =
TokenUtils.hentSaksbehandlerIdent() ?: TokenUtils.hentApplikasjonsnavn() ?: "ukjent"
val opprettetAvNavn =
TokenUtils.hentSaksbehandlerIdent()
?.let { SaksbehandlernavnProvider.hentSaksbehandlernavn(it) }
val behandling =
Behandling(
createBehandling.behandlingType,
Expand All @@ -74,6 +81,9 @@ class BehandlingController(private val behandlingService: BehandlingService) {
createBehandling.soknadId,
createBehandling.soknadRefId,
createBehandling.behandlerEnhet,
opprettetAv = opprettetAv,
opprettetAvNavn = opprettetAvNavn,
kildeapplikasjon = TokenUtils.hentApplikasjonsnavn() ?: "ukjent",
createBehandling.soknadFra,
createBehandling.stonadType,
createBehandling.engangsbelopType,
Expand Down Expand Up @@ -189,7 +199,14 @@ class BehandlingController(private val behandlingService: BehandlingService) {
behandling.soknadId,
behandling.behandlerEnhet,
behandling.roller.map {
RolleDto(it.id!!, it.rolleType.toRolleTypeDto(), it.ident, it.navn, it.fodtDato, it.opprettetDato)
RolleDto(
it.id!!,
it.rolleType.toRolleTypeDto(),
it.ident,
it.navn,
it.fodtDato,
it.opprettetDato,
)
}.toSet(),
behandling.husstandsBarn.toHusstandsBarnDto(),
behandling.sivilstand.toSivilstandDto(),
Expand Down Expand Up @@ -232,6 +249,7 @@ class BehandlingController(private val behandlingService: BehandlingService) {
}

private fun ingenVoksneUtenIdent(roller: Set<CreateRolleDto>): Boolean {
return roller.filter { r -> r.rolleType != CreateRolleRolleType.BARN && r.ident.isNullOrBlank() }.none()
return roller.filter { r -> r.rolleType != CreateRolleRolleType.BARN && r.ident.isNullOrBlank() }
.none()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Behandling(
val soknadId: Long,
val soknadRefId: Long? = null,
val behandlerEnhet: String,
val opprettetAv: String,
val opprettetAvNavn: String? = null,
val kildeapplikasjon: String,
@Enumerated(EnumType.STRING)
val soknadFra: SøktAvType,
@Enumerated(EnumType.STRING)
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ no.nav.security.jwt:
client-id: ${AZURE_APP_CLIENT_ID}
client-secret: ${AZURE_APP_CLIENT_SECRET}
client-auth-method: client_secret_post
bidrag-organisasjon:
resource-url: ${BIDRAG_ORGANISASJON_URL}
token-endpoint-url: https://login.microsoftonline.com/${AZURE_APP_TENANT_ID}/oauth2/v2.0/token
grant-type: urn:ietf:params:oauth:grant-type:jwt-bearer
scope: api://${BIDRAG_ORGANISASJON_SCOPE}/.default
authentication:
client-id: ${AZURE_APP_CLIENT_ID}
client-secret: ${AZURE_APP_CLIENT_SECRET}
client-auth-method: client_secret_post
issuer.aad:
discovery_url: https://login.microsoftonline.com/${AZURE_APP_TENANT_ID}/v2.0/.well-known/openid-configuration
accepted_audience: ${AZURE_APP_CLIENT_ID}, api://${AZURE_APP_CLIENT_ID}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Table: BEHANDLING
alter table BEHANDLING
add column if not exists opprettet_av text default '' not null;

alter table BEHANDLING
add column if not exists opprettet_av_navn text;

alter table BEHANDLING
add column if not exists kildeapplikasjon text default 'bisys' not null;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.bidrag.behandling.controller

import io.kotest.matchers.shouldBe
import no.nav.bidrag.behandling.database.datamodell.Behandling
import no.nav.bidrag.behandling.database.datamodell.Behandlingstype
import no.nav.bidrag.behandling.database.datamodell.SoknadType
Expand Down Expand Up @@ -61,9 +62,13 @@ class BehandlingControllerTest() : KontrollerTestRunner() {
"${rootUri()}/behandling",
HttpMethod.POST,
HttpEntity(behandlingReq),
Void::class.java,
CreateBehandlingResponse::class.java,
)
assertEquals(HttpStatus.OK, behandlingRes.statusCode)
val opprettetBehandling = behandlingService.hentBehandlingById(behandlingRes.body!!.id)
opprettetBehandling.opprettetAv shouldBe "aud-localhost"
opprettetBehandling.opprettetAvNavn shouldBe "Fornavn Etternavn"
opprettetBehandling.kildeapplikasjon shouldBe "aud-localhost"
}

@Test
Expand Down Expand Up @@ -225,6 +230,9 @@ class BehandlingControllerTest() : KontrollerTestRunner() {
123213L,
null,
"EN123",
"Z9999",
"Navn Navnesen",
"bisys",
SøktAvType.VERGE,
null,
null,
Expand Down Expand Up @@ -327,7 +335,12 @@ class BehandlingControllerTest() : KontrollerTestRunner() {
val roller =
setOf(
CreateRolleDtoTest(CreateRolleRolleType.BARN, "1235", Date(1)),
CreateRolleDtoTest(CreateRolleRolleType.BIDRAGS_MOTTAKER, null, Date(1), "Ola Dunk"),
CreateRolleDtoTest(
CreateRolleRolleType.BIDRAGS_MOTTAKER,
null,
Date(1),
"Ola Dunk",
),
)
val testBehandlingMedNull = createBehandlingRequestTest("sak123", "en12", roller)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ abstract class KontrollerTestRunner : CommonTestRunner() {
@BeforeEach
fun initMocks() {
WireMock.resetAllRequests()
stubUtils.stubHentSaksbehandler()
stubUtils.stubOpprettForsendelse()
stubUtils.stubSlettForsendelse()
stubUtils.stubHentForsendelserForSak()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class VedtakHendelseTest : CommonTestRunner() {
saksnummer = SAKSNUMMER,
soknadId = 123123L,
behandlerEnhet = "4806",
opprettetAv = "Z99999",
opprettetAvNavn = "Saksbehandler Navn",
kildeapplikasjon = "bisys",
behandlingType = Behandlingstype.BIDRAG18AAR,
engangsbelopType = null,
mottatDato = Date(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ class BehandlingServiceTest : TestContainerRunner() {
123213L,
null,
"1234",
"Z9999",
"Navn Navnesen",
"bisys",
SøktAvType.BIDRAGSMOTTAKER,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class OpplysningerServiceTest : TestContainerRunner() {
123L,
null,
"ENH1",
"Z9999",
"Navn Navnesen",
"bisys",
SøktAvType.VERGE,
engangsbelopType = Engangsbeløptype.ETTERGIVELSE,
stonadType = null,
Expand Down
22 changes: 22 additions & 0 deletions src/test/kotlin/no/nav/bidrag/behandling/utils/StubUtils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.CountMatchingStrategy
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder
import com.github.tomakehurst.wiremock.client.WireMock
Expand All @@ -10,6 +11,8 @@ import no.nav.bidrag.behandling.consumer.ForsendelseResponsTo
import no.nav.bidrag.behandling.consumer.OpprettForsendelseRespons
import no.nav.bidrag.behandling.dto.HentPersonResponse
import no.nav.bidrag.behandling.utils.opprettForsendelseResponsUnderOpprettelse
import no.nav.bidrag.commons.service.AppContext
import no.nav.bidrag.commons.service.organisasjon.SaksbehandlerInfoResponse
import no.nav.bidrag.domene.enums.grunnlag.Grunnlagstype
import no.nav.bidrag.domene.tid.ÅrMånedsperiode
import no.nav.bidrag.transport.behandling.beregning.felles.BeregnGrunnlag
Expand Down Expand Up @@ -151,6 +154,25 @@ class StubUtils {
)
}

fun stubHentSaksbehandler() {
AppContext.getBean(WireMockServer::class.java).stubFor(
WireMock.get(WireMock.urlMatching("/organisasjon/saksbehandler/info/(.*)")).willReturn(
aResponse()
.withHeader(HttpHeaders.CONNECTION, "close")
.withHeader(HttpHeaders.CONTENT_TYPE, "application/json")
.withStatus(HttpStatus.OK.value())
.withBody(
toJsonString(
SaksbehandlerInfoResponse(
"Z99999",
"Fornavn Etternavn",
),
),
),
),
)
}

inner class Verify {
fun opprettForsendelseKaltMed(vararg contains: String) {
val verify =
Expand Down
3 changes: 3 additions & 0 deletions src/test/kotlin/no/nav/bidrag/behandling/utils/Testdata.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ fun oppretteBehandling(): Behandling {
123,
null,
"ENH",
"Z9999",
"Navn Navnesen",
"bisys",
SøktAvType.BIDRAGSMOTTAKER,
null,
null,
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AZURE_APP_CLIENT_SECRET: unset
server.port: 8990
NAIS_APP_NAME: bidrag-behandling
DB_HOST: localhost
DB_PORT: 5445
DB_PORT: 5454
DB_DATABASE: bidrag-behandling
DB_USERNAME: cloudsqliamuser
DB_PASSWORD: admin
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ BIDRAG_PERSON_URL: http://localhost:${wiremock.server.port}/bidrag-person
BIDRAG_BEREGN_FORSKUDD_URL: http://localhost:${wiremock.server.port}
BIDRAG_FORSENDELSE_URL: http://localhost:${wiremock.server.port}/forsendelse
BIDRAG_TILGANGSKONTROLL_URL: http://localhost:${wiremock.server.port}/tilgangskontroll
BIDRAG_ORGANISASJON_URL: http://localhost:${wiremock.server.port}/organisasjon
AZURE_OPENID_CONFIG_ISSUER: http://localhost:${mock-oauth2-server.port}/aad
AZURE_APP_TENANT_ID: 12321321-123213-3213123
AZURE_APP_CLIENT_ID: asdasd-sadas-ddas-qwe
Expand Down
Loading