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.
Merge branch 'main' into MAN-108-record-if-complied
- Loading branch information
Showing
16 changed files
with
130 additions
and
74 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
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
2 changes: 1 addition & 1 deletion
2
...-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.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
9 changes: 7 additions & 2 deletions
9
...ts-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/UserGenerator.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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.user.AuditUser | ||
import uk.gov.justice.digital.hmpps.entity.User | ||
import java.time.LocalDate | ||
|
||
object UserGenerator { | ||
val AUDIT_USER = AuditUser(IdGenerator.getAndIncrement(), "SubjectAccessRequestsAndDelius") | ||
val AUDIT_USER = User(IdGenerator.getAndIncrement(), "SubjectAccessRequestsAndDelius", "Service") | ||
|
||
val USER1 = User(IdGenerator.getAndIncrement(), "username1", "surname1") | ||
val USER2 = User(IdGenerator.getAndIncrement(), "username2", "surname2") | ||
val INACTIVE_USER = User(IdGenerator.getAndIncrement(), "inactive", "inactive", LocalDate.now().minusDays(1)) | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/UserIntegrationTest.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,34 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import uk.gov.justice.digital.hmpps.api.model.User | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.andExpectJson | ||
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken | ||
|
||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
internal class UserIntegrationTest { | ||
@Autowired | ||
lateinit var mockMvc: MockMvc | ||
|
||
@Test | ||
fun `returns data`() { | ||
mockMvc | ||
.perform(get("/user").withToken()) | ||
.andExpect(status().isOk) | ||
.andExpectJson( | ||
listOf( | ||
User("SubjectAccessRequestsAndDelius", "Service"), | ||
User("username1", "surname1"), | ||
User("username2", "surname2") | ||
), strict = true | ||
) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...us/src/main/kotlin/uk/gov/justice/digital/hmpps/api/controller/ProbationCaseController.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,20 @@ | ||
package uk.gov.justice.digital.hmpps.api.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.RestController | ||
import uk.gov.justice.digital.hmpps.api.model.Name | ||
import uk.gov.justice.digital.hmpps.api.model.Person | ||
import uk.gov.justice.digital.hmpps.entity.PersonRepository | ||
import uk.gov.justice.digital.hmpps.entity.getPerson | ||
|
||
@RestController | ||
@PreAuthorize("hasRole('PROBATION_API__SUBJECT_ACCESS_REQUEST__DETAIL')") | ||
class ProbationCaseController(private val personRepository: PersonRepository) { | ||
@GetMapping("/probation-case/{crn}") | ||
fun getPersonalDetails(@PathVariable crn: String) = with(personRepository.getPerson(crn)) { | ||
val middleName = listOfNotNull(secondName, thirdName).takeIf { it.isNotEmpty() }?.joinToString(" ") | ||
Person(Name(forename, middleName, surname)) | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
...ain/kotlin/uk/gov/justice/digital/hmpps/api/controller/SubjectAccessRequestsController.kt
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/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,14 @@ | ||
package uk.gov.justice.digital.hmpps.api.controller | ||
|
||
import org.springframework.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import uk.gov.justice.digital.hmpps.api.model.User | ||
import uk.gov.justice.digital.hmpps.entity.UserRepository | ||
|
||
@RestController | ||
@PreAuthorize("hasRole('PROBATION_API__SUBJECT_ACCESS_REQUEST__DETAIL')") | ||
class UserController(private val userRepository: UserRepository) { | ||
@GetMapping("/user") | ||
fun getUsers() = userRepository.findAll().map { User(it.username, it.surname) } | ||
} |
6 changes: 6 additions & 0 deletions
6
...access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/User.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,6 @@ | ||
package uk.gov.justice.digital.hmpps.api.model | ||
|
||
data class User( | ||
val username: String, | ||
val lastName: String | ||
) |
2 changes: 1 addition & 1 deletion
2
...ntegration/delius/person/entity/Person.kt → ...ov/justice/digital/hmpps/entity/Person.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
31 changes: 31 additions & 0 deletions
31
...ct-access-requests-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/entity/User.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,31 @@ | ||
package uk.gov.justice.digital.hmpps.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import org.hibernate.annotations.Immutable | ||
import org.hibernate.annotations.SQLRestriction | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.time.LocalDate | ||
|
||
@Entity | ||
@Immutable | ||
@Table(name = "user_") | ||
@SQLRestriction("end_date is null or end_date > current_date") | ||
class User( | ||
@Id | ||
@Column(name = "user_id") | ||
val id: Long, | ||
|
||
@Column(name = "distinguished_name") | ||
val username: String, | ||
|
||
@Column(name = "surname") | ||
val surname: String, | ||
|
||
@Column | ||
val endDate: LocalDate? = null | ||
) | ||
|
||
interface UserRepository : JpaRepository<User, Long> |
27 changes: 0 additions & 27 deletions
27
...lius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SubjectAccessRequestsService.kt
This file was deleted.
Oops, something went wrong.
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