-
Couldn't load subscription status.
- Fork 0
S28 3951 Allow SuperUsers to perform more edit actions #1178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 9 commits
2c6016a
aaaed35
4904845
dd06f87
93ffaec
5132d4e
0adf055
b8bfc4f
ab69cb8
85a7280
ecbd49e
2934384
3a9781a
8c0e491
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import uk.gov.hmcts.reform.preapi.enums.CaseState; | ||
| import uk.gov.hmcts.reform.preapi.enums.RecordingStatus; | ||
| import uk.gov.hmcts.reform.preapi.enums.UpsertResult; | ||
| import uk.gov.hmcts.reform.preapi.exception.BadRequestException; | ||
| import uk.gov.hmcts.reform.preapi.exception.NotFoundException; | ||
| import uk.gov.hmcts.reform.preapi.exception.ResourceInDeletedStateException; | ||
| import uk.gov.hmcts.reform.preapi.exception.ResourceInWrongStateException; | ||
|
|
@@ -30,6 +31,8 @@ | |
| import java.sql.Timestamp; | ||
| import java.time.Instant; | ||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.time.ZoneId; | ||
| import java.time.temporal.ChronoUnit; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
@@ -126,6 +129,16 @@ public Page<BookingDTO> searchBy( | |
| @Transactional | ||
| @PreAuthorize("@authorisationService.hasUpsertAccess(authentication, #createBookingDTO)") | ||
| public UpsertResult upsert(CreateBookingDTO createBookingDTO) { | ||
| var auth = ((UserAuthentication) SecurityContextHolder.getContext().getAuthentication()); | ||
|
|
||
| var localDateField = LocalDateTime.ofInstant(createBookingDTO.getScheduledFor().toInstant(), | ||
| ZoneId.of("Europe/London")).toLocalDate(); | ||
| var today = LocalDate.now(); | ||
|
|
||
| if (localDateField.isBefore(today) | ||
| && !auth.hasRole("ROLE_SUPER_USER")) { | ||
| throw new BadRequestException("Scheduled date must not be in the past"); | ||
| } | ||
|
|
||
| if (bookingAlreadyDeleted(createBookingDTO.getId())) { | ||
| throw new ResourceInDeletedStateException("BookingDTO", createBookingDTO.getId().toString()); | ||
|
|
@@ -137,7 +150,7 @@ public UpsertResult upsert(CreateBookingDTO createBookingDTO) { | |
| var caseEntity = caseRepository.findByIdAndDeletedAtIsNull(createBookingDTO.getCaseId()) | ||
| .orElseThrow(() -> new NotFoundException("Case: " + createBookingDTO.getCaseId())); | ||
|
|
||
| if (caseEntity.getState() != CaseState.OPEN) { | ||
| if (caseEntity.getState() != CaseState.OPEN && !auth.hasRole("ROLE_SUPER_USER")) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree that we should have this exception, as I think we need to avoid modifying closed cases altogether |
||
| throw new ResourceInWrongStateException( | ||
| "Booking", | ||
| createBookingDTO.getId(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,12 +123,15 @@ public UpsertResult upsert(CreateCaseDTO createCaseDTO) { | |
| var isCaseClosureCancellation = false; | ||
| var isCasePendingClosure = false; | ||
|
|
||
| var auth = ((UserAuthentication) SecurityContextHolder.getContext().getAuthentication()); | ||
|
|
||
| if (isUpdate) { | ||
| if (foundCase.get().isDeleted()) { | ||
| throw new ResourceInDeletedStateException("CaseDTO", createCaseDTO.getId().toString()); | ||
| } | ||
| if (foundCase.get().getState() != CaseState.OPEN | ||
| && foundCase.get().getState() == createCaseDTO.getState() | ||
| && !auth.hasRole("ROLE_SUPER_USER") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto - I don't like this superpower |
||
| ) { | ||
| throw new ResourceInWrongStateException( | ||
| "Resource Case(" | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this adds a restriction to the API that wasn't there before, i.e. it adds a guard to make sure bookings are in the future. That's fine, but we need to create a separate ticket for this piece of code and put it in front of Jacob to make sure it's been signed off by service as its a behavioural change.edit: sorry I should have read the whole PR first!I agree we need the Super User exception to allow us to recover cases.