-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2483 from navikt/kafka-melding-min-side
Skal ha et forvaltningsendepunkt for å aktivere og deaktivere persone…
- Loading branch information
Showing
7 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/no/nav/familie/ef/sak/forvaltning/MinsideForvaltningsController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package no.nav.familie.ef.sak.forvaltning | ||
|
||
import no.nav.familie.ef.sak.felles.dto.PersonIdentDto | ||
import no.nav.familie.ef.sak.infrastruktur.exception.feilHvisIkke | ||
import no.nav.familie.ef.sak.infrastruktur.featuretoggle.FeatureToggleService | ||
import no.nav.familie.ef.sak.infrastruktur.featuretoggle.Toggle | ||
import no.nav.familie.ef.sak.infrastruktur.sikkerhet.SikkerhetContext | ||
import no.nav.familie.ef.sak.minside.MinSideKafkaProducerService | ||
import no.nav.security.token.support.core.api.ProtectedWithClaims | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/minside/forvaltning/") | ||
@ProtectedWithClaims(issuer = "azuread") | ||
class MinsideForvaltningsController( | ||
private val featureToggleService: FeatureToggleService, | ||
private val minSideKafkaProducerService: MinSideKafkaProducerService, | ||
) { | ||
@PostMapping("aktiver") | ||
fun aktiverPersonForMinSide(@RequestBody personIdentDto: PersonIdentDto) { | ||
feilHvisIkke(erUtviklerMedVeilderrolle()) { "Kan kun kjøres av utvikler med veilederrolle" } | ||
validerPersonIdent(personIdentDto) | ||
minSideKafkaProducerService.aktiver(personIdent = personIdentDto.personIdent) | ||
} | ||
|
||
@PostMapping("deaktiver") | ||
fun deaktiverPersonForMinSide(@RequestBody personIdentDto: PersonIdentDto) { | ||
feilHvisIkke(erUtviklerMedVeilderrolle()) { "Kan kun kjøres av utvikler med veilederrolle" } | ||
validerPersonIdent(personIdentDto) | ||
minSideKafkaProducerService.deaktiver(personIdent = personIdentDto.personIdent) | ||
} | ||
|
||
private fun validerPersonIdent(personIdentDto: PersonIdentDto) { | ||
if (personIdentDto.personIdent.length != 11) { | ||
error("PersonIdent må ha 11 siffer") | ||
} | ||
} | ||
|
||
private fun erUtviklerMedVeilderrolle(): Boolean = | ||
SikkerhetContext.erSaksbehandler() && featureToggleService.isEnabled(Toggle.UTVIKLER_MED_VEILEDERRROLLE) | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/no/nav/familie/ef/sak/minside/MinSideKafkaProducerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package no.nav.familie.ef.sak.minside | ||
|
||
import no.nav.familie.log.IdUtils | ||
import no.nav.familie.log.mdc.MDCConstants | ||
import no.nav.tms.microfrontend.MicrofrontendMessageBuilder | ||
import no.nav.tms.microfrontend.Sensitivitet | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import org.slf4j.MDC | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.kafka.core.KafkaTemplate | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class MinSideKafkaProducerService(private val kafkaTemplate: KafkaTemplate<String, String>) { | ||
|
||
@Value("\${MIN_SIDE_TOPIC}") | ||
lateinit var topic: String | ||
private val logger: Logger = LoggerFactory.getLogger(this::class.java) | ||
|
||
fun aktiver(personIdent: String) { | ||
val melding = MicrofrontendMessageBuilder.enable { | ||
ident = personIdent | ||
initiatedBy = "teamfamilie" | ||
microfrontendId = "familie-ef-mikrofrontend-minside" | ||
sensitivitet = Sensitivitet.HIGH | ||
}.text() | ||
val callId = MDC.get(MDCConstants.MDC_CALL_ID) ?: IdUtils.generateId() | ||
logger.info("Sender aktivere minside melding for callId=$callId") | ||
kafkaTemplate.send(topic, callId, melding) | ||
} | ||
|
||
fun deaktiver(personIdent: String) { | ||
val melding = MicrofrontendMessageBuilder.disable { | ||
ident = personIdent | ||
initiatedBy = "teamfamilie" | ||
microfrontendId = "familie-ef-mikrofrontend-minside" | ||
}.text() | ||
val callId = MDC.get(MDCConstants.MDC_CALL_ID) ?: IdUtils.generateId() | ||
logger.info("Sender deaktivere minside melding for callId=$callId") | ||
kafkaTemplate.send(topic, callId, melding) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters