Skip to content

Commit

Permalink
chore: need org admin permission for import and sysadmin has read per…
Browse files Browse the repository at this point in the history
…mission
  • Loading branch information
jeffreiffers committed Sep 29, 2023
1 parent 1e5f526 commit fddd357
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ConceptsController(
val user = endpointPermissions.getUser(jwt)
return when {
user == null -> ResponseEntity(HttpStatus.UNAUTHORIZED)
concepts.any { !endpointPermissions.hasOrgWritePermission(jwt, it.ansvarligVirksomhet.id) } ->
concepts.any { !endpointPermissions.hasOrgAdminPermission(jwt, it.ansvarligVirksomhet.id) } ->
ResponseEntity(HttpStatus.FORBIDDEN)
else -> {
logger.info("creating ${concepts.size} concepts for ${concepts.firstOrNull()?.ansvarligVirksomhet?.id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ class EndpointPermissions {
return when {
orgnr == null -> false
authorities == null -> false
hasSysAdminPermission(jwt) -> true
authorities.contains(roleOrgAdmin(orgnr)) -> true
authorities.contains(roleOrgWrite(orgnr)) -> true
else -> false
}
}

fun hasOrgAdminPermission(jwt: Jwt, orgnr: String?): Boolean {
val authorities: String? = jwt.claims["authorities"] as? String
return when {
orgnr == null -> false
authorities == null -> false
authorities.contains(roleOrgAdmin(orgnr)) -> true
else -> false
}
}

fun hasSysAdminPermission(jwt: Jwt): Boolean {
val authorities: String? = jwt.claims["authorities"] as? String

Expand Down

0 comments on commit fddd357

Please sign in to comment.