Skip to content

Commit

Permalink
Fix AUP validator and dashboard usability
Browse files Browse the repository at this point in the history
- when signatureValidityInDays is 0: hide the AUP reminders from the interface, send null from dashboard
- change validator and return proper error messages
  • Loading branch information
rmiccoli authored Aug 29, 2024
1 parent 6fe5982 commit ada2c24
Show file tree
Hide file tree
Showing 7 changed files with 420 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public IamAup entityFromDto(AupDTO dto) {
aup.setSignatureValidityInDays(dto.getSignatureValidityInDays());
aup.setUrl(dto.getUrl());
aup.setText(dto.getText());
aup.setAupRemindersInDays(dto.getAupRemindersInDays());
if (dto.getAupRemindersInDays() == null) {
aup.setAupRemindersInDays("");
} else {
aup.setAupRemindersInDays(dto.getAupRemindersInDays());
}
return aup;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class AupRemindersAndSignatureValidator implements ConstraintValidator<AupRemindersAndSignature, AupDTO> {
public class AupRemindersAndSignatureValidator
implements ConstraintValidator<AupRemindersAndSignature, AupDTO> {

@Override
public boolean isValid(AupDTO value, ConstraintValidatorContext context) {
Expand All @@ -50,11 +51,22 @@ public boolean isValid(AupDTO value, ConstraintValidatorContext context) {
return false;
}

if (aupRemindersInDays == null || aupRemindersInDays.isEmpty()) {
if (signatureValidityInDays == 0) {
if (aupRemindersInDays != null && !aupRemindersInDays.isEmpty()) {
context.disableDefaultConstraintViolation();
context
.buildConstraintViolationWithTemplate(
"Invalid AUP: aupRemindersInDays cannot be set if signatureValidityInDays is 0")
.addConstraintViolation();
return false;
}
return true;
}

if (aupRemindersInDays == null) {
context.disableDefaultConstraintViolation();
context
.buildConstraintViolationWithTemplate(
"Invalid AUP: aupRemindersInDays cannot be empty or null")
context.buildConstraintViolationWithTemplate(
"Invalid AUP: aupRemindersInDays must be set when signatureValidityInDays is greater than 0")
.addConstraintViolation();
return false;
}
Expand Down Expand Up @@ -87,15 +99,18 @@ public boolean isValid(AupDTO value, ConstraintValidatorContext context) {
if (uniqueNumbers.size() != numbers.size()) {
context.disableDefaultConstraintViolation();
context
.buildConstraintViolationWithTemplate("Invalid AUP: duplicate values for reminders are not allowed")
.buildConstraintViolationWithTemplate(
"Invalid AUP: duplicate values for reminders are not allowed")
.addConstraintViolation();
return false;
}

return true;
} catch (NumberFormatException e) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("Invalid AUP: non-integer value found")
context
.buildConstraintViolationWithTemplate(
"Invalid AUP: non-integer value found for aupRemindersInDays")
.addConstraintViolation();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h1>
If set to zero, the AUP signature will be asked only at registration time.
</span>
</div>
<div class="form-group">
<div class="form-group" ng-if="$ctrl.aup.data.signatureValidityInDays > 0">
<label>AUP reminders (in days)</label>
<p class="aup-text">
{{$ctrl.aup.data.aupRemindersInDays}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
self.doSaveAup = function() {
self.error = undefined;
self.enabled = false;
if(self.aupVal.signatureValidityInDays == 0 || !self.aupVal.aupRemindersInDays) {
self.aupVal.aupRemindersInDays = "";
}
AupService.updateAup(self.aupVal)
.then(function(res) {
$uibModalInstance.close('AUP updated succesfully');
Expand All @@ -106,7 +109,7 @@
self.aupVal = {
url: "",
signatureValidityInDays: 0,
aupRemindersInDays: "30,15,1"
aupRemindersInDays: ""
};
};

Expand All @@ -115,6 +118,9 @@
self.doCreateAup = function() {
self.error = undefined;
self.enabled = false;
if(self.aupVal.signatureValidityInDays == 0 || !self.aupVal.aupRemindersInDays) {
self.aupVal.aupRemindersInDays = "";
}
AupService.createAup(self.aupVal)
.then(function(res) {
$uibModalInstance.close('AUP created succesfully');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@ <h3 class="modal-title">
</div>
<div class="modal-body">
<form name="createAup">
<div class="form-group" ng-class="{'has-error': $ctrl.error || createAup.url.$dirty && !createAup.url.$valid}">
<div class="form-group has-error" ng-if="$ctrl.error">
<span class="help-block">
{{ $ctrl.error }}
</span>
</div>
<div class="form-group">
<label>Acceptable Usage Policy URL</label>
<input name="url" class="form-control" type="url" value="http://" ng-model="$ctrl.aupVal.url" required="true">
<input name="url" class="form-control" value="http://" ng-model="$ctrl.aupVal.url" required="true">
<span class="help-block">
The URL above is presented to users at registration time or periodically
if the AUP is configured for periodic reacceptance
</span>
<span class="help-block" ng-if="createAup.url.$dirty && createAup.url.$error.required">
Please provide a valid URL for the AUP
</span>
<span class="help-block" ng-if="$ctrl.error">
{{ $ctrl.error }}
</span>
<div class="form-group has-error" ng-if="createAup.url.$dirty && createAup.url.$error.required">
<span class="help-block">
Please provide a valid URL for the AUP
</span>
</div>
</div>
<div class="form-group">
<label>AUP signature validity (in days)</label>
Expand All @@ -45,20 +49,22 @@ <h3 class="modal-title">
If set to zero, the AUP signature will be asked only at registration time.
</span>
</div>
<div class="form-group" ng-class="{'has-error': $ctrl.error || createAup.aupReminder.$dirty && !createAup.aupReminder.$valid}">
<div class="form-group" ng-if="$ctrl.aupVal.signatureValidityInDays > 0">
<label>AUP signature reminders (in days)</label>
<input name="aupReminder" class="form-control" type="text" ng-model="$ctrl.aupVal.aupRemindersInDays" placeholder="30,15,1" required="true">
<input name="aupReminder" class="form-control" type="text" ng-model="$ctrl.aupVal.aupRemindersInDays" placeholder="30,15,1" ng-required="$ctrl.aupVal.signatureValidityInDays > 0">
<span class="help-block">
Indicate a sequence of comma-separated numbers representing how many days before the AUP expiration reminder messages must be sent.
</span>
<span class="help-block" ng-if="createAup.aupReminder.$dirty && createAup.aupReminder.$error.required">
Required input
</span>
<div class="form-group has-error" ng-if="createAup.aupReminder.$dirty && createAup.aupReminder.$error.required">
<span class="help-block">
Required input
</span>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" id="modal-btn-confirm" ng-disabled="!$ctrl.aupVal.url || !$ctrl.aupVal.aupRemindersInDays || !$ctrl.enabled" ng-click="$ctrl.doCreateAup()">Create AUP</button>
<button class="btn btn-primary" type="button" id="modal-btn-confirm" ng-disabled="!$ctrl.enabled" ng-click="$ctrl.doCreateAup()">Create AUP</button>

<button class="btn btn-warning" type="button" id="modal-btn-reset" ng-click="$ctrl.reset()">Reset form</button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ <h3 class="modal-title">
</div>
<div class="modal-body">
<form name="createAup">
<div class="form-group" ng-class="{'has-error': $ctrl.error || createAup.url.$dirty && !createAup.url.$valid}">
<div class="form-group has-error" ng-if="$ctrl.error">
<span class="help-block">
{{ $ctrl.error }}
</span>
</div>
<div class="form-group">
<label>Acceptable Usage Policy URL</label>
<input name="url" class="form-control" type="url" value="http://" ng-model="$ctrl.aupVal.url"
<input name="url" class="form-control" value="http://" ng-model="$ctrl.aupVal.url"
required="true">
<span class="help-block" ng-if="$ctrl.aup.text">
Since v1.6.0, IAM has moved to external AUP documents. Please provide a valid URL pointing to your AUP
Expand All @@ -34,14 +39,12 @@ <h3 class="modal-title">
The URL above is presented to users at registration time or periodically
if the AUP is configured for periodic reacceptance
</span>
<span class="help-block" ng-if="createAup.url.$dirty && createAup.url.$error.required">
Please provide a valid URL pointing to your AUP document.
</span>
<span class="help-block" ng-if="$ctrl.error">
{{ $ctrl.error }}
</span>
<div class="form-group has-error" ng-if="createAup.url.$dirty && createAup.url.$error.required">
<span class="help-block">
Please provide a valid URL for the AUP
</span>
</div>
</div>

<div class="form-group">
<label>AUP signature validity (in days)</label>
<input name="signatureValidity" class="form-control" type="number" value="365"
Expand All @@ -52,15 +55,17 @@ <h3 class="modal-title">
If set to zero, the AUP signature will be asked only at registration time.
</span>
</div>
<div class="form-group" ng-class="{'has-error': $ctrl.error || createAup.aupReminder.$dirty && !createAup.aupReminder.$valid}">
<div class="form-group" ng-if="$ctrl.aupVal.signatureValidityInDays > 0">
<label>AUP signature reminders (in days)</label>
<input name="aupReminder" class="form-control" type="text" ng-model="$ctrl.aupVal.aupRemindersInDays" placeholder="30,15,1" required="true">
<input name="aupReminder" class="form-control" type="text" ng-model="$ctrl.aupVal.aupRemindersInDays" placeholder="30,15,1" ng-required="$ctrl.aupVal.signatureValidityInDays > 0">
<span class="help-block">
Indicate a sequence of comma-separated numbers representing how many days before the AUP expiration reminder messages must be sent.
</span>
<span class="help-block" ng-if="createAup.aupReminder.$dirty && createAup.aupReminder.$error.required">
Required input
</span>
<div class="form-group has-error" ng-if="createAup.aupReminder.$dirty && createAup.aupReminder.$error.required">
<span class="help-block">
Required input
</span>
</div>
</div>
<div class="form-group">
<div class="bs-callout bs-callout-primary">
Expand All @@ -74,7 +79,7 @@ <h4>Editing the AUP will <strong>not</strong> trigger an AUP signature
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" id="modal-btn-confirm"
ng-disabled="!$ctrl.aupVal.url || !$ctrl.enabled" ng-click="$ctrl.doSaveAup()">Edit AUP</button>
ng-disabled="!$ctrl.enabled" ng-click="$ctrl.doSaveAup()">Edit AUP</button>

<button class="btn btn-warning" type="button" id="modal-btn-reset" ng-click="$ctrl.reset()">Reset form</button>

Expand Down
Loading

0 comments on commit ada2c24

Please sign in to comment.