Skip to content

Commit

Permalink
Håndter manglende felter i Azure nav ansatt
Browse files Browse the repository at this point in the history
Finnes brukere i dev som mangler epost f. eks. Bare filtrerer de vekk i
søk
  • Loading branch information
fredrikpe committed Oct 3, 2024
1 parent 05da039 commit e5bf598
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ class MicrosoftGraphClient(

val user = response.body<MsGraphUserDto>()

return toNavAnsatt(user)
return toNavAnsatt(user) ?: throw Exception("Ansatt med azureId ${user.id} manglet required felter")
}

suspend fun getNavAnsattByNavIdent(navIdent: NavIdent, accessType: AccessType): AzureAdNavAnsatt? {
val response = client.get("$baseUrl/v1.0/users") {
bearerAuth(tokenProvider.exchange(accessType))
parameter("\$filter", "onPremisesSamAccountName eq '$navIdent'")
parameter("\$search", "\"onPremisesSamAccountName:$navIdent\"")
parameter("\$select", azureAdNavAnsattFields)
}

Expand Down Expand Up @@ -102,10 +102,7 @@ class MicrosoftGraphClient(

return response.body<GetUserSearchResponse>()
.value
.filter { isNavAnsatt(it) }
.map {
toNavAnsatt(it)
}
.mapNotNull { toNavAnsatt(it) }
}

suspend fun getMemberGroups(navAnsattAzureId: UUID, accessType: AccessType): List<AdGruppe> {
Expand Down Expand Up @@ -142,7 +139,7 @@ class MicrosoftGraphClient(

return result.value
.filter { isNavAnsatt(it) }
.map { toNavAnsatt(it) }
.map { toNavAnsatt(it) ?: throw Exception("Ansatt med azureId ${it.id} manglet required felter") }
}

suspend fun addToGroup(objectId: UUID, groupId: UUID) {
Expand All @@ -164,23 +161,28 @@ class MicrosoftGraphClient(

private fun toNavAnsatt(user: MsGraphUserDto) = when {
user.onPremisesSamAccountName == null -> {
throw RuntimeException("NAVident mangler for bruker med id=${user.id}")
log.warn("NAVident mangler for bruker med id=${user.id}")
null
}

user.streetAddress == null -> {
throw RuntimeException("NAV Enhetskode mangler for bruker med id=${user.id}")
log.warn("NAV Enhetskode mangler for bruker med id=${user.id}")
null
}

user.city == null -> {
throw RuntimeException("NAV Enhetsnavn mangler for bruker med id=${user.id}")
log.warn("NAV Enhetsnavn mangler for bruker med id=${user.id}")
null
}

user.givenName == null -> {
throw RuntimeException("Fornavn på ansatt mangler for bruker med id=${user.id}")
log.warn("Fornavn på ansatt mangler for bruker med id=${user.id}")
null
}

user.surname == null -> {
throw RuntimeException("Etternavn på ansatt mangler for bruker med id=${user.id}")
log.warn("Etternavn på ansatt mangler for bruker med id=${user.id}")
null
}
user.mail == null -> {
log.warn("Epost på ansatt mangler for bruker med id=${user.id}")
null
}

else -> AzureAdNavAnsatt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal data class MsGraphUserDto(
/**
* E-postadresse
*/
val mail: String,
val mail: String?,
/**
* NAV Enhetskode
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ data class NavAnsattDbo(
*/
val hovedenhet: String,
val azureId: UUID,
val mobilnummer: String? = null,
val mobilnummer: String?,
val epost: String,
val roller: Set<NavAnsattRolle>,
val skalSlettesDato: LocalDate? = null,
val skalSlettesDato: LocalDate?,
) {
companion object {
fun fromNavAnsattDto(dto: NavAnsattDto): NavAnsattDbo = NavAnsattDbo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object NavAnsattFixture {
NavAnsattRolle.TILTAKSGJENNOMFORINGER_SKRIV,
NavAnsattRolle.AVTALER_SKRIV,
),
skalSlettesDato = null,
)
val ansatt2: NavAnsattDbo = NavAnsattDbo(
navIdent = NavIdent("DD2"),
Expand All @@ -33,5 +34,6 @@ object NavAnsattFixture {
NavAnsattRolle.TILTAKSGJENNOMFORINGER_SKRIV,
NavAnsattRolle.AVTALER_SKRIV,
),
skalSlettesDato = null,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class NavAnsattRepositoryTest : FunSpec({
mobilnummer = "12345678",
epost = "[email protected]",
roller = setOf(NavAnsattRolle.TILTAKADMINISTRASJON_GENERELL),
skalSlettesDato = null,
)

val ansatt2 = NavAnsattDbo(
Expand All @@ -80,6 +81,7 @@ class NavAnsattRepositoryTest : FunSpec({
mobilnummer = "12345678",
epost = "[email protected]",
roller = setOf(NavAnsattRolle.KONTAKTPERSON),
skalSlettesDato = null,
)

val ansatt3 = NavAnsattDbo(
Expand All @@ -91,6 +93,7 @@ class NavAnsattRepositoryTest : FunSpec({
mobilnummer = "12345678",
epost = "[email protected]",
roller = setOf(NavAnsattRolle.KONTAKTPERSON, NavAnsattRolle.TILTAKADMINISTRASJON_GENERELL),
skalSlettesDato = null,
)

test("CRUD") {
Expand Down

0 comments on commit e5bf598

Please sign in to comment.