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
* PI-1827 Add user access endpoint for Tier UI * Add test
- Loading branch information
1 parent
af11f44
commit 705e93a
Showing
5 changed files
with
73 additions
and
0 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
21 changes: 21 additions & 0 deletions
21
.../tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/UserController.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,21 @@ | ||
package uk.gov.justice.digital.hmpps.controller | ||
|
||
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.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import uk.gov.justice.digital.hmpps.service.CaseAccess | ||
import uk.gov.justice.digital.hmpps.service.UserAccessService | ||
|
||
@RestController | ||
@RequestMapping("users") | ||
@PreAuthorize("hasRole('TIER_DETAILS')") | ||
class UserController(private val userAccessService: UserAccessService) { | ||
|
||
@GetMapping("/{username}/access/{crn}") | ||
fun userAccessCheck( | ||
@PathVariable username: String, | ||
@PathVariable crn: String, | ||
): CaseAccess = userAccessService.caseAccessFor(username, crn) | ||
} |
37 changes: 37 additions & 0 deletions
37
...r-to-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/controller/UserControllerTest.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.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 userController: UserController | ||
|
||
@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 = userController.userAccessCheck("username", "crn") | ||
|
||
assertThat(response, equalTo(caseAccess)) | ||
} | ||
} |