generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3951b4c
commit b30126e
Showing
5 changed files
with
58 additions
and
3 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
17 changes: 17 additions & 0 deletions
17
...elius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/UserAccessController.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,17 @@ | ||
package uk.gov.justice.digital.hmpps.api.controller | ||
|
||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RestController | ||
import uk.gov.justice.digital.hmpps.service.UserAccessService | ||
|
||
@RestController | ||
@Tag(name = "User access") | ||
@PreAuthorize("hasRole('PROBATION_API__MANAGE_A_SUPERVISION__CASE_DETAIL')") | ||
class UserAccessController(private val userAccessService: UserAccessService) { | ||
@GetMapping("/user/{username}/access/{crn}") | ||
fun checkAccess(@PathVariable username: String, @PathVariable crn: String) = | ||
userAccessService.caseAccessFor(username, crn) | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...s/src/test/kotlin/uk/gov/justice/digital/hmpps/api/controller/UserAccessControllerTest.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,37 @@ | ||
package uk.gov.justice.digital.hmpps.api.controller | ||
|
||
import org.hamcrest.CoreMatchers.equalTo | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.whenever | ||
import uk.gov.justice.digital.hmpps.service.CaseAccess | ||
import uk.gov.justice.digital.hmpps.service.UserAccessService | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
internal class UserControllerTest { | ||
@Mock | ||
lateinit var userAccessService: UserAccessService | ||
|
||
@InjectMocks | ||
lateinit var userAccessController: UserAccessController | ||
|
||
@Test | ||
fun `check user access`() { | ||
val caseAccess = CaseAccess( | ||
crn = "crn", | ||
userRestricted = false, | ||
userExcluded = true, | ||
exclusionMessage = "testing", | ||
) | ||
|
||
whenever(userAccessService.caseAccessFor("username", "crn")).thenReturn(caseAccess) | ||
|
||
val response = userAccessController.checkAccess("username", "crn") | ||
|
||
assertThat(response, equalTo(caseAccess)) | ||
} | ||
} |