RD: Added 'canEditOrDelete()' method in RegistrationRequestService for blocking updates and deletes when request status is ONBOARDING or SUCCESS. Also updated HTML files accordingly, and improved them a little
This commit is contained in:
parent
fa43a6f1bc
commit
57820e6dd0
@ -72,6 +72,7 @@ public class RegistrationRequestService {
|
||||
throw new RegistrationRequestException(
|
||||
"Registration request with the Id does not exists in repository: "+registrationRequest.getId());
|
||||
checkRegistrationRequest(registrationRequest);
|
||||
canEditOrDelete(result.get());
|
||||
|
||||
registrationRequest.setLastUpdateDate(Instant.now());
|
||||
registrationRequestRepository.save(registrationRequest);
|
||||
@ -99,11 +100,20 @@ public class RegistrationRequestService {
|
||||
//XXX:TODO
|
||||
}
|
||||
|
||||
private void canEditOrDelete(RegistrationRequest registrationRequest) {
|
||||
RegistrationRequestStatus status = registrationRequest.getStatus();
|
||||
if (status==RegistrationRequestStatus.ONBOARDING_REQUESTED || status== RegistrationRequestStatus.SUCCESS)
|
||||
throw new RegistrationRequestException(
|
||||
"Registration request with the Id cannot be deleted due to its status: "
|
||||
+ registrationRequest.getId() + ", status=" + status);
|
||||
}
|
||||
|
||||
public void deleteById(@NonNull String id) {
|
||||
Optional<RegistrationRequest> result = getById(id);
|
||||
if (result.isEmpty())
|
||||
throw new RegistrationRequestException(
|
||||
"Registration request with the Id does not exists in repository: "+id);
|
||||
canEditOrDelete(result.get());
|
||||
registrationRequestRepository.delete(result.get());
|
||||
result.get().setLastUpdateDate(Instant.now());
|
||||
}
|
||||
|
@ -22,8 +22,11 @@
|
||||
$(function() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const reqId = urlParams.get('id') ?? '';
|
||||
const readonly = urlParams.get('readonly') ?? '';
|
||||
|
||||
requestId = reqId;
|
||||
isReadonly = readonly.trim().toLowerCase()==='true';
|
||||
if (isReadonly) makeFormReadonly();
|
||||
|
||||
if (reqId!=='')
|
||||
refreshRequestInfo(reqId);
|
||||
@ -34,10 +37,31 @@ $(function() {
|
||||
|
||||
var isNew = false;
|
||||
var isAdmin = false;
|
||||
var isReadonly = false;
|
||||
var username = '';
|
||||
var requestId;
|
||||
var requester = '';
|
||||
|
||||
function makeFormReadonly() {
|
||||
// Get form fields
|
||||
var q1 = $('input[id^="request#"]');
|
||||
var q2 = $('textarea[id^="request#"]');
|
||||
var all = $.merge(q1, q2);
|
||||
//console.log('makeFormReadonly: form fields: ', all);
|
||||
|
||||
// Make form fields readonly
|
||||
all.each((index, item) => {
|
||||
var it = $(item);
|
||||
console.log('makeFormReadonly: each: ', it.attr('id'), it.val());
|
||||
it.prop('readonly', true);
|
||||
it.removeClass('form-control');
|
||||
it.addClass('form-control-plaintext');
|
||||
});
|
||||
|
||||
// Hide Save button
|
||||
$('#btn-save').hide();
|
||||
}
|
||||
|
||||
function refreshRequestInfo(id) {
|
||||
// show loading spinner
|
||||
$('#loading-spinner').toggleClass('d-none');
|
||||
@ -327,7 +351,7 @@ function sendRequestData(requestData) {
|
||||
<i class="fa fa-refresh"></i>
|
||||
</button>
|
||||
|
||||
<button type="button" class="btn btn-success" onClick="saveRequestInfo();">
|
||||
<button type="button" class="btn btn-success" id="btn-save" onClick="saveRequestInfo();">
|
||||
<i class="fa fa-save"></i>
|
||||
</button>
|
||||
<p> </p>
|
||||
|
@ -48,7 +48,21 @@ function updateRequestsList(asAdmin) {
|
||||
var dateStr = date.toLocaleDateString('en-GB') + ' ' + date.toLocaleTimeString('en-GB')
|
||||
+ '<br/>' + Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
var status = item.status;
|
||||
|
||||
var color = getStatusColor(status);
|
||||
var editDelActions = (status!=='ONBOARDING_REQUESTED' && status!='SUCCESS')
|
||||
? `
|
||||
<button type="button" class="btn btn-danger btn-sm" onClick="if (confirm('Delete request?')) deleteRequest('${reqId}');">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-success btn-sm" onClick="document.location='/request-edit.html?id=${reqId}'; ">
|
||||
<i class="fas fa-pen"></i>
|
||||
</button>
|
||||
` : `
|
||||
<button type="button" class="btn btn-primary btn-sm" onClick="document.location='/request-edit.html?id=${reqId}&readonly=true'; ">
|
||||
<i class="fas fa-eye"></i>
|
||||
</button>
|
||||
`;
|
||||
var adminActions = (isAdmin && (item.status==='PENDING_AUTHORIZATION'
|
||||
|| item.status==='AUTHORIZATION_REJECT'
|
||||
|| item.status==='PENDING_ONBOARDING')
|
||||
@ -59,17 +73,19 @@ function updateRequestsList(asAdmin) {
|
||||
<button type="button" class="btn btn-danger btn-sm" onClick="authorizeRequest('${reqId}', false); ">
|
||||
<i class="fas fa-thumbs-down"></i>
|
||||
</button>
|
||||
` : '';
|
||||
adminActions += (isAdmin) ? `
|
||||
` : '';
|
||||
adminActions += (isAdmin && status!=='ONBOARDING_REQUESTED') ? `
|
||||
<button class="btn btn-warning btn-sm" onClick="archiveRequest('${reqId}')">
|
||||
<i class="fas fa-box"></i>
|
||||
</button>
|
||||
` : '';
|
||||
adminActions += (isAdmin && (status!=='ONBOARDING_REQUESTED' && status!='SUCCESS')) ? `
|
||||
<a href="/discovery/request/${reqId}/status/NEW_REQUEST" target="_blank">
|
||||
<button class="btn btn-outline-danger btn-sm">
|
||||
<i class="fas fa-fast-backward"></i>
|
||||
</button>
|
||||
</a>
|
||||
`: '';
|
||||
`: '';
|
||||
ii++;
|
||||
tbody.append( $(`
|
||||
<tr class="${color}">
|
||||
@ -82,12 +98,7 @@ function updateRequestsList(asAdmin) {
|
||||
<td>${dateStr}</td>
|
||||
<td>${status}</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-danger btn-sm" onClick="if (confirm('Delete request?')) deleteRequest('${reqId}');">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-success btn-sm" onClick="document.location='/request-edit.html?id=${reqId}'; ">
|
||||
<i class="fas fa-pen"></i>
|
||||
</button>
|
||||
${editDelActions}
|
||||
${adminActions}
|
||||
</td>
|
||||
</tr> `
|
||||
|
Loading…
x
Reference in New Issue
Block a user