-
Notifications
You must be signed in to change notification settings - Fork 4
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 #77 from navikt/debug_unleash
Debug unleash
- Loading branch information
Showing
3 changed files
with
36 additions
and
13 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
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/no/nav/klage/oppgave/service/unleash/ByUserStrategy.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,32 @@ | ||
package no.nav.klage.oppgave.service.unleash | ||
|
||
import no.finn.unleash.strategy.Strategy | ||
import no.nav.klage.oppgave.repositories.InnloggetSaksbehandlerRepository | ||
import no.nav.klage.oppgave.util.getLogger | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ByUserStrategy(private val innloggetSaksbehandlerRepository: InnloggetSaksbehandlerRepository) : Strategy { | ||
|
||
companion object { | ||
@Suppress("JAVA_CLASS_ON_COMPANION") | ||
private val logger = getLogger(javaClass.enclosingClass) | ||
const val PARAM = "user" | ||
} | ||
|
||
override fun getName(): String = "byUserId" | ||
|
||
override fun isEnabled(parameters: Map<String, String>?): Boolean = | ||
getEnabledUsers(parameters)?.any { isCurrentUserEnabled(it) } ?: false | ||
|
||
private fun getEnabledUsers(parameters: Map<String, String>?) = | ||
parameters?.get(PARAM)?.split(',') | ||
|
||
private fun isCurrentUserEnabled(ident: String): Boolean { | ||
val currentIdent = getIdent() | ||
logger.debug("isCurrentUserEnabled? ident: {}, currentIdent: {}", ident, currentIdent) | ||
return ident == currentIdent | ||
} | ||
|
||
private fun getIdent() = innloggetSaksbehandlerRepository.getInnloggetIdent() | ||
} |