some work on role and user validation and updates.
This commit is contained in:
@@ -12,8 +12,8 @@ public class RoleCommand {
|
|||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
private String[] notSelectedItems;
|
private String[] notSelectedPermissions;
|
||||||
private String[] selectedItems;
|
private String[] permissions;
|
||||||
|
|
||||||
protected RoleCommand() {
|
protected RoleCommand() {
|
||||||
//
|
//
|
||||||
@@ -22,7 +22,7 @@ public class RoleCommand {
|
|||||||
public RoleCommand(final String name, final String description, final String[] permissionIds) {
|
public RoleCommand(final String name, final String description, final String[] permissionIds) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.selectedItems = permissionIds;
|
this.permissions = permissionIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -49,19 +49,19 @@ public class RoleCommand {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getNotSelectedItems() {
|
public String[] getNotSelectedPermissions() {
|
||||||
return notSelectedItems;
|
return notSelectedPermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotSelectedItems(String... notSelectedItems) {
|
public void setNotSelectedPermissions(String[] notSelectedPermissions) {
|
||||||
this.notSelectedItems = notSelectedItems;
|
this.notSelectedPermissions = notSelectedPermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getSelectedItems() {
|
public String[] getPermissions() {
|
||||||
return selectedItems;
|
return permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedItems(String... selectedItems) {
|
public void setPermissions(String[] permissions) {
|
||||||
this.selectedItems = selectedItems;
|
this.permissions = permissions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,8 +18,8 @@ public class UserCommand implements Serializable {
|
|||||||
private String email;
|
private String email;
|
||||||
private Long officeId;
|
private Long officeId;
|
||||||
|
|
||||||
private String[] notSelectedItems;
|
private String[] notSelectedRoles;
|
||||||
private String[] selectedItems;
|
private String[] roles;
|
||||||
|
|
||||||
public UserCommand() {
|
public UserCommand() {
|
||||||
//
|
//
|
||||||
@@ -85,19 +85,19 @@ public class UserCommand implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getNotSelectedItems() {
|
public String[] getNotSelectedRoles() {
|
||||||
return notSelectedItems;
|
return notSelectedRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotSelectedItems(String... notSelectedItems) {
|
public void setNotSelectedRoles(String... notSelectedRoles) {
|
||||||
this.notSelectedItems = notSelectedItems;
|
this.notSelectedRoles = notSelectedRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getSelectedItems() {
|
public String[] getRoles() {
|
||||||
return selectedItems;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedItems(String... selectedItems) {
|
public void setRoles(String... roles) {
|
||||||
this.selectedItems = selectedItems;
|
this.roles = roles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,9 +10,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<jsp:include page="../common-head.jsp" />
|
<jsp:include page="../common-head.jsp" />
|
||||||
|
|
||||||
<c:url value="/admin/user/all" var="allUsersUrl" />
|
|
||||||
<c:url value="/admin/role/all" var="allRolesUrl" />
|
|
||||||
<c:url value="/admin/permission/all" var="allPermissionsUrl" />
|
|
||||||
<c:url value="/" var="rootContext" />
|
<c:url value="/" var="rootContext" />
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
@@ -169,7 +166,7 @@ $(document).ready(function() {
|
|||||||
o[this.name].push(this.value || '');
|
o[this.name].push(this.value || '');
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (this.name === 'selectedItems' || this.name === 'notSelectedItems') {
|
if (this.name === 'permissions' || this.name === 'notSelectedPermissions' || this.name === 'roles' || this.name === 'notSelectedRoles') {
|
||||||
o[this.name] = new Array();
|
o[this.name] = new Array();
|
||||||
o[this.name].push(this.value || '');
|
o[this.name].push(this.value || '');
|
||||||
} else {
|
} else {
|
||||||
@@ -180,7 +177,7 @@ $(document).ready(function() {
|
|||||||
return o;
|
return o;
|
||||||
};
|
};
|
||||||
|
|
||||||
function popupDialogWithFormView(getUrl, postUrl, submitType, titleCode, templateSelector, width, height, saveSuccessFunction) {
|
function popupDialogWithFormView(getUrl, postUrl, submitType, titleCode, templateSelector, width, height, saveSuccessFunction, roles) {
|
||||||
var dialogDiv = $("<div id='dialog-form'></div>");
|
var dialogDiv = $("<div id='dialog-form'></div>");
|
||||||
var jqxhr = $.ajax({
|
var jqxhr = $.ajax({
|
||||||
url: getUrl,
|
url: getUrl,
|
||||||
@@ -204,13 +201,24 @@ $(document).ready(function() {
|
|||||||
var buttonsOpts = {};
|
var buttonsOpts = {};
|
||||||
buttonsOpts[saveButton] = function() {
|
buttonsOpts[saveButton] = function() {
|
||||||
|
|
||||||
$('#notSelectedItems option').each(function(i) {
|
if (roles) {
|
||||||
$(this).attr("selected", "selected");
|
// used for role form
|
||||||
});
|
$('#notSelectedPermissions option').each(function(i) {
|
||||||
|
$(this).attr("selected", "selected");
|
||||||
|
});
|
||||||
|
|
||||||
$('#selectedItems option').each(function(i) {
|
$('#permissions option').each(function(i) {
|
||||||
$(this).attr("selected", "selected");
|
$(this).attr("selected", "selected");
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
$('#notSelectedRoles option').each(function(i) {
|
||||||
|
$(this).attr("selected", "selected");
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#roles option').each(function(i) {
|
||||||
|
$(this).attr("selected", "selected");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||||
console.log(newFormData);
|
console.log(newFormData);
|
||||||
@@ -223,7 +231,6 @@ $(document).ready(function() {
|
|||||||
data: newFormData,
|
data: newFormData,
|
||||||
cache: false,
|
cache: false,
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function(xhr) {
|
||||||
console.log("base64: " + base64);
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
||||||
},
|
},
|
||||||
success: saveSuccessFunction,
|
success: saveSuccessFunction,
|
||||||
@@ -247,13 +254,23 @@ $(document).ready(function() {
|
|||||||
},
|
},
|
||||||
open: function (event, ui) {
|
open: function (event, ui) {
|
||||||
|
|
||||||
$('#add').click(function() {
|
if (roles) {
|
||||||
return !$('#notSelectedItems option:selected').remove().appendTo('#selectedItems');
|
$('#add').click(function() {
|
||||||
});
|
return !$('#notSelectedPermissions option:selected').remove().appendTo('#permissions');
|
||||||
|
});
|
||||||
|
|
||||||
$('#remove').click(function() {
|
$('#remove').click(function() {
|
||||||
return !$('#selectedItems option:selected').remove().appendTo('#notSelectedItems');
|
return !$('#permissions option:selected').remove().appendTo('#notSelectedPermissions');
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
$('#add').click(function() {
|
||||||
|
return !$('#notSelectedRoles option:selected').remove().appendTo('#roles');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#remove').click(function() {
|
||||||
|
return !$('#roles option:selected').remove().appendTo('#notSelectedRoles');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$('.datepickerfield').datepicker({constrainInput: true, maxDate: 0, dateFormat: 'dd MM yy'});
|
$('.datepickerfield').datepicker({constrainInput: true, maxDate: 0, dateFormat: 'dd MM yy'});
|
||||||
|
|
||||||
@@ -278,7 +295,6 @@ $(document).ready(function() {
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
cache: false,
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function(xhr) {
|
||||||
console.log("base64: " + base64);
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
||||||
},
|
},
|
||||||
success: function(data, textStatus, jqXHR) {
|
success: function(data, textStatus, jqXHR) {
|
||||||
@@ -312,7 +328,6 @@ $(document).ready(function() {
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
cache: false,
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function(xhr) {
|
||||||
console.log("base64: " + base64);
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
||||||
},
|
},
|
||||||
success: function(data, textStatus, jqXHR) {
|
success: function(data, textStatus, jqXHR) {
|
||||||
@@ -353,7 +368,7 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#adduser').click(function(e) {
|
$('#adduser').click(function(e) {
|
||||||
var url = baseApiUrl + 'template';
|
var url = baseApiUrl + 'users/template';
|
||||||
var postUrl = baseApiUrl + "users";
|
var postUrl = baseApiUrl + "users";
|
||||||
var templateSelector = "#userFormTemplate";
|
var templateSelector = "#userFormTemplate";
|
||||||
var width = 1000;
|
var width = 1000;
|
||||||
@@ -364,7 +379,7 @@ $(document).ready(function() {
|
|||||||
refreshUsersView();
|
refreshUsersView();
|
||||||
}
|
}
|
||||||
|
|
||||||
popupDialogWithFormView(url, postUrl, 'POST', 'dialog.title.add.user', templateSelector, width, height, saveSuccessFunction);
|
popupDialogWithFormView(url, postUrl, 'POST', 'dialog.title.add.user', templateSelector, width, height, saveSuccessFunction, false);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -375,7 +390,7 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#addrole').click(function(e) {
|
$('#addrole').click(function(e) {
|
||||||
var url = baseApiUrl +'template';
|
var url = baseApiUrl + 'roles/template';
|
||||||
var postUrl = baseApiUrl + "roles";
|
var postUrl = baseApiUrl + "roles";
|
||||||
var templateSelector = "#roleFormTemplate";
|
var templateSelector = "#roleFormTemplate";
|
||||||
var width = 1000;
|
var width = 1000;
|
||||||
@@ -386,7 +401,7 @@ $(document).ready(function() {
|
|||||||
refreshRolesView();
|
refreshRolesView();
|
||||||
}
|
}
|
||||||
|
|
||||||
popupDialogWithFormView(url, postUrl, 'POST', 'dialog.title.add.role', templateSelector, width, height, saveSuccessFunction);
|
popupDialogWithFormView(url, postUrl, 'POST', 'dialog.title.add.role', templateSelector, width, height, saveSuccessFunction, true);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -409,7 +424,6 @@ $(document).ready(function() {
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
cache: false,
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function(xhr) {
|
||||||
console.log("base64: " + base64);
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
||||||
},
|
},
|
||||||
success: function(data, textStatus, jqXHR) {
|
success: function(data, textStatus, jqXHR) {
|
||||||
@@ -432,7 +446,7 @@ $(document).ready(function() {
|
|||||||
refreshUsersView();
|
refreshUsersView();
|
||||||
}
|
}
|
||||||
|
|
||||||
popupDialogWithFormView(getUrl, putUrl, 'PUT', "dialog.title.edit.details", templateSelector, width, height, saveSuccessFunction);
|
popupDialogWithFormView(getUrl, putUrl, 'PUT', "dialog.title.edit.details", templateSelector, width, height, saveSuccessFunction, false);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -476,7 +490,6 @@ $(document).ready(function() {
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
cache: false,
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function(xhr) {
|
||||||
console.log("base64: " + base64);
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
||||||
},
|
},
|
||||||
success: function(data, textStatus, jqXHR) {
|
success: function(data, textStatus, jqXHR) {
|
||||||
@@ -499,7 +512,7 @@ $(document).ready(function() {
|
|||||||
refreshUsersView();
|
refreshUsersView();
|
||||||
}
|
}
|
||||||
|
|
||||||
popupDialogWithFormView(getUrl, putUrl, 'PUT', "dialog.title.edit.details", templateSelector, width, height, saveSuccessFunction);
|
popupDialogWithFormView(getUrl, putUrl, 'PUT', "dialog.title.edit.details", templateSelector, width, height, saveSuccessFunction, true);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -543,7 +556,6 @@ $(document).ready(function() {
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
cache: false,
|
cache: false,
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function(xhr) {
|
||||||
console.log("base64: " + base64);
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
xhr.setRequestHeader("Authorization", "Basic " + base64);
|
||||||
},
|
},
|
||||||
success: function(data, textStatus, jqXHR) {
|
success: function(data, textStatus, jqXHR) {
|
||||||
|
|||||||
+8
-8
@@ -490,8 +490,8 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<div class="multiselectwidget">
|
<div class="multiselectwidget">
|
||||||
<label for="notSelectedItems"><spring:message code="form.label.user.available.roles"/></label>
|
<label for="notSelectedRoles"><spring:message code="form.label.user.available.roles"/></label>
|
||||||
<select id="notSelectedItems" name="notSelectedItems" title="Available application roles." class="multiselectwidget multiNotSelectedItems" multiple="multiple" style="width:450px;height:125px;">
|
<select id="notSelectedRoles" name="notSelectedRoles" title="Available application roles." class="multiselectwidget multiNotSelectedItems" multiple="multiple" style="width:450px;height:125px;">
|
||||||
{{#each availableRoles}}
|
{{#each availableRoles}}
|
||||||
<option value="{{=id}}">{{=name}}</option>
|
<option value="{{=id}}">{{=name}}</option>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
@@ -500,8 +500,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="multiselectwidget">
|
<div class="multiselectwidget">
|
||||||
<label for="selectedItems"><spring:message code="form.label.user.selected.roles"/></label>
|
<label for="roles"><spring:message code="form.label.user.selected.roles"/></label>
|
||||||
<select id="selectedItems" name="selectedItems" title="User selected roles." class="multiselectwidget multiSelectedItems" multiple="multiple" style="width:450px;height:125px;">
|
<select id="roles" name="roles" title="User selected roles." class="multiselectwidget multiSelectedItems" multiple="multiple" style="width:450px;height:125px;">
|
||||||
{{#each selectedRoles}}
|
{{#each selectedRoles}}
|
||||||
<option value="{{=id}}" selected="selected">{{=name}}</option>
|
<option value="{{=id}}" selected="selected">{{=name}}</option>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
@@ -526,8 +526,8 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<div class="multiselectwidget">
|
<div class="multiselectwidget">
|
||||||
<label for="notSelectedItems"><spring:message code="form.label.role.available.permissions"/></label>
|
<label for="notSelectedPermissions"><spring:message code="form.label.role.available.permissions"/></label>
|
||||||
<select id="notSelectedItems" name="notSelectedItems" title="" class="multiselectwidget multiNotSelectedItems" multiple="multiple" style="width:450px;height:125px;">
|
<select id="notSelectedPermissions" name="notSelectedPermissions" title="" class="multiselectwidget multiNotSelectedItems" multiple="multiple" style="width:450px;height:125px;">
|
||||||
{{#each availablePermissions}}
|
{{#each availablePermissions}}
|
||||||
<option value="{{=id}}" title="{{=description}}">{{=name}}</option>
|
<option value="{{=id}}" title="{{=description}}">{{=name}}</option>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
@@ -536,8 +536,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="multiselectwidget">
|
<div class="multiselectwidget">
|
||||||
<label for="selectedItems"><spring:message code="form.label.role.selected.permissions"/></label>
|
<label for="permissions"><spring:message code="form.label.role.selected.permissions"/></label>
|
||||||
<select id="selectedItems" name="selectedItems" title="" class="multiselectwidget multiSelectedItems" multiple="multiple" style="width:450px;height:125px;">
|
<select id="permissions" name="permissions" title="" class="multiselectwidget multiSelectedItems" multiple="multiple" style="width:450px;height:125px;">
|
||||||
{{#each selectedPermissions}}
|
{{#each selectedPermissions}}
|
||||||
<option value="{{=id}}" title="{{=description}}">{{=name}}</option>
|
<option value="{{=id}}" title="{{=description}}">{{=name}}</option>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.mifosng.data.ApiParameterError;
|
import org.mifosng.data.ApiParameterError;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
public class DataValidatorBuilder {
|
public class DataValidatorBuilder {
|
||||||
|
|
||||||
@@ -113,6 +114,21 @@ public class DataValidatorBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DataValidatorBuilder arrayNotEmpty() {
|
||||||
|
if (value == null && ignoreNullValue) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object[] array = (Object[]) value;
|
||||||
|
if (ObjectUtils.isEmpty(array)) {
|
||||||
|
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".cannot.be.empty");
|
||||||
|
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" cannot be empty. You must select at least one permission.");
|
||||||
|
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter);
|
||||||
|
dataValidationErrors.add(error);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DataValidatorBuilder anyOfNotNull(Object... object) {
|
public DataValidatorBuilder anyOfNotNull(Object... object) {
|
||||||
boolean hasData = false;
|
boolean hasData = false;
|
||||||
for (Object obj : object) {
|
for (Object obj : object) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class RoleApiResource {
|
|||||||
private RoleWritePlatformService roleWritePlatformService;
|
private RoleWritePlatformService roleWritePlatformService;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response retrieveAllRoles() {
|
public Response retrieveAllRoles() {
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ public class RoleApiResource {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("template")
|
@Path("template")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response retrieveNewRoleDetails() {
|
public Response retrieveNewRoleDetails() {
|
||||||
|
|
||||||
@@ -62,8 +62,8 @@ public class RoleApiResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||||
@Produces({ MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response createRole(final RoleCommand command) {
|
public Response createRole(final RoleCommand command) {
|
||||||
|
|
||||||
Long roleId = this.roleWritePlatformService.createRole(command);
|
Long roleId = this.roleWritePlatformService.createRole(command);
|
||||||
@@ -72,7 +72,7 @@ public class RoleApiResource {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{roleId}")
|
@Path("{roleId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response retrieveRole(@PathParam("roleId") final Long roleId) {
|
public Response retrieveRole(@PathParam("roleId") final Long roleId) {
|
||||||
|
|
||||||
@@ -87,8 +87,8 @@ public class RoleApiResource {
|
|||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{roleId}")
|
@Path("{roleId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||||
@Produces({ MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public Response updateRole(@PathParam("roleId") final Long roleId, final RoleCommand command) {
|
public Response updateRole(@PathParam("roleId") final Long roleId, final RoleCommand command) {
|
||||||
|
|
||||||
command.setId(roleId);
|
command.setId(roleId);
|
||||||
|
|||||||
@@ -81,10 +81,19 @@ public class Role extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When updating role details, any parameters with null values are ignored.
|
||||||
|
*/
|
||||||
public void update(String name, String description, List<Permission> selectedPermissions) {
|
public void update(String name, String description, List<Permission> selectedPermissions) {
|
||||||
this.name = name;
|
if (name != null) {
|
||||||
this.description = description;
|
this.name = name;
|
||||||
this.permissions.clear();
|
}
|
||||||
this.permissions = new HashSet<Permission>(selectedPermissions);
|
if (description != null) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
if (selectedPermissions != null) {
|
||||||
|
this.permissions.clear();
|
||||||
|
this.permissions = new HashSet<Permission>(selectedPermissions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+14
-10
@@ -32,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWritePlatformService {
|
public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWritePlatformService {
|
||||||
@@ -66,11 +67,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
|||||||
UserCommandValidator validator = new UserCommandValidator(command);
|
UserCommandValidator validator = new UserCommandValidator(command);
|
||||||
validator.validate();
|
validator.validate();
|
||||||
|
|
||||||
Set<Role> allRoles = new HashSet<Role>();
|
Set<Role> allRoles = assembleSetOfRoles(command.getRoles());
|
||||||
for (String roleId : command.getSelectedItems()) {
|
|
||||||
Role role = this.roleRepository.findOne(Long.valueOf(roleId));
|
|
||||||
allRoles.add(role);
|
|
||||||
}
|
|
||||||
|
|
||||||
Office office = this.officeRepository.findOne(command.getOfficeId());
|
Office office = this.officeRepository.findOne(command.getOfficeId());
|
||||||
|
|
||||||
@@ -117,11 +114,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
|||||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Role> allRoles = new HashSet<Role>();
|
Set<Role> allRoles = assembleSetOfRoles(command.getRoles());
|
||||||
for (String roleId : command.getSelectedItems()) {
|
|
||||||
Role role = this.roleRepository.findOne(Long.valueOf(roleId));
|
|
||||||
allRoles.add(role);
|
|
||||||
}
|
|
||||||
|
|
||||||
Office office = this.officeRepository.findOne(command.getOfficeId());
|
Office office = this.officeRepository.findOne(command.getOfficeId());
|
||||||
if (office == null) {
|
if (office == null) {
|
||||||
@@ -143,6 +136,17 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<Role> assembleSetOfRoles(final String[] rolesArray) {
|
||||||
|
Set<Role> allRoles = new HashSet<Role>();
|
||||||
|
if (!ObjectUtils.isEmpty(rolesArray)) {
|
||||||
|
for (String roleId : rolesArray) {
|
||||||
|
Role role = this.roleRepository.findOne(Long.valueOf(roleId));
|
||||||
|
allRoles.add(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allRoles;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void deleteUser(Long userId) {
|
public void deleteUser(Long userId) {
|
||||||
|
|||||||
+15
-30
@@ -3,11 +3,10 @@ package org.mifosng.platform.user.service;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.mifosng.data.ApiParameterError;
|
import org.mifosng.data.ApiParameterError;
|
||||||
import org.mifosng.data.command.RoleCommand;
|
import org.mifosng.data.command.RoleCommand;
|
||||||
|
import org.mifosng.platform.DataValidatorBuilder;
|
||||||
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
|
|
||||||
public class RoleCommandValidator {
|
public class RoleCommandValidator {
|
||||||
|
|
||||||
@@ -20,7 +19,13 @@ public class RoleCommandValidator {
|
|||||||
public void validateForCreate() {
|
public void validateForCreate() {
|
||||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
|
||||||
validate(dataValidationErrors);
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
|
||||||
|
|
||||||
|
baseDataValidator.reset().parameter("name").value(command.getName()).notBlank();
|
||||||
|
baseDataValidator.reset().parameter("description").value(command.getDescription()).notBlank().notExceedingLengthOf(500);
|
||||||
|
baseDataValidator.reset().parameter("permissions").value(command.getPermissions()).arrayNotEmpty();
|
||||||
|
|
||||||
|
baseDataValidator.reset().anyOfNotNull(command.getName(), command.getDescription(), command.getPermissions());
|
||||||
|
|
||||||
if (!dataValidationErrors.isEmpty()) {
|
if (!dataValidationErrors.isEmpty()) {
|
||||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||||
@@ -30,37 +35,17 @@ public class RoleCommandValidator {
|
|||||||
public void validateForUpdate() {
|
public void validateForUpdate() {
|
||||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
|
||||||
if (command.getId() == null || command.getId() < 1) {
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
|
||||||
ApiParameterError error = ApiParameterError.parameterError("validation.msg.role.id.not.provided", "The parameter id cannot be blank.", "id");
|
|
||||||
dataValidationErrors.add(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
validate(dataValidationErrors);
|
baseDataValidator.reset().parameter("id").value(command.getId()).notNull();
|
||||||
|
baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank();
|
||||||
|
baseDataValidator.reset().parameter("description").value(command.getDescription()).ignoreIfNull().notBlank().notExceedingLengthOf(500);
|
||||||
|
baseDataValidator.reset().parameter("permissions").value(command.getPermissions()).ignoreIfNull().arrayNotEmpty();
|
||||||
|
|
||||||
|
baseDataValidator.reset().anyOfNotNull(command.getName(), command.getDescription(), command.getPermissions());
|
||||||
|
|
||||||
if (!dataValidationErrors.isEmpty()) {
|
if (!dataValidationErrors.isEmpty()) {
|
||||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validate(List<ApiParameterError> dataValidationErrors) {
|
|
||||||
if (StringUtils.isBlank(command.getName())) {
|
|
||||||
ApiParameterError error = ApiParameterError.parameterError("validation.msg.role.name.cannot.be.blank", "The parameter name cannot be blank.", "name");
|
|
||||||
dataValidationErrors.add(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isBlank(command.getDescription())) {
|
|
||||||
ApiParameterError error = ApiParameterError.parameterError("validation.msg.role.description.cannot.be.blank", "The parameter description cannot be blank.", "description");
|
|
||||||
dataValidationErrors.add(error);
|
|
||||||
} else {
|
|
||||||
if (command.getDescription().trim().length() > 500) {
|
|
||||||
ApiParameterError error = ApiParameterError.parameterError("validation.msg.role.description.exceeds.max.length", "The parameter description has data that exceeds its max allowed length of {0}.", "description", 500);
|
|
||||||
dataValidationErrors.add(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ObjectUtils.isEmpty(command.getSelectedItems())) {
|
|
||||||
ApiParameterError error = ApiParameterError.parameterError("validation.msg.role.permissions.cannot.be.empty", "The parameter selectedItems cannot be blank. You must select at least one permission.", "selectedItems");
|
|
||||||
dataValidationErrors.add(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+23
-25
@@ -16,6 +16,7 @@ import org.mifosng.platform.user.domain.RoleRepository;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatformService {
|
public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatformService {
|
||||||
@@ -41,18 +42,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
|||||||
RoleCommandValidator validator = new RoleCommandValidator(command);
|
RoleCommandValidator validator = new RoleCommandValidator(command);
|
||||||
validator.validateForCreate();
|
validator.validateForCreate();
|
||||||
|
|
||||||
List<Long> selectedPermissionIds = new ArrayList<Long>();
|
List<Permission> selectedPermissions = assembleListOfSelectedPermissions(command.getPermissions());
|
||||||
for (String selectedId : command.getSelectedItems()) {
|
|
||||||
selectedPermissionIds.add(Long.valueOf(selectedId));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Permission> selectedPermissions = new ArrayList<Permission>();
|
|
||||||
Collection<Permission> allPermissions = this.permissionRepository.findAll();
|
|
||||||
for (Permission permission : allPermissions) {
|
|
||||||
if (selectedPermissionIds.contains(permission.getId())) {
|
|
||||||
selectedPermissions.add(permission);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Role entity = new Role(currentUser.getOrganisation(), command.getName(), command.getDescription(), selectedPermissions);
|
Role entity = new Role(currentUser.getOrganisation(), command.getName(), command.getDescription(), selectedPermissions);
|
||||||
|
|
||||||
@@ -70,19 +60,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
|||||||
RoleCommandValidator validator = new RoleCommandValidator(command);
|
RoleCommandValidator validator = new RoleCommandValidator(command);
|
||||||
validator.validateForUpdate();
|
validator.validateForUpdate();
|
||||||
|
|
||||||
List<Long> selectedPermissionIds = new ArrayList<Long>();
|
List<Permission> selectedPermissions = assembleListOfSelectedPermissions(command.getPermissions());
|
||||||
for (String selectedId : command.getSelectedItems()) {
|
|
||||||
selectedPermissionIds.add(Long.valueOf(selectedId));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Permission> selectedPermissions = new ArrayList<Permission>();
|
|
||||||
Collection<Permission> allPermissions = this.permissionRepository
|
|
||||||
.findAll();
|
|
||||||
for (Permission permission : allPermissions) {
|
|
||||||
if (selectedPermissionIds.contains(permission.getId())) {
|
|
||||||
selectedPermissions.add(permission);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Role role = this.roleRepository.findOne(rolesThatMatch(currentUser.getOrganisation(), command.getId()));
|
Role role = this.roleRepository.findOne(rolesThatMatch(currentUser.getOrganisation(), command.getId()));
|
||||||
role.update(command.getName(), command.getDescription(), selectedPermissions);
|
role.update(command.getName(), command.getDescription(), selectedPermissions);
|
||||||
@@ -91,4 +69,24 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
|||||||
|
|
||||||
return role.getId();
|
return role.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Permission> assembleListOfSelectedPermissions(final String[] selectedPermissionsArray) {
|
||||||
|
List<Long> selectedPermissionIds = new ArrayList<Long>();
|
||||||
|
List<Permission> selectedPermissions = new ArrayList<Permission>();
|
||||||
|
|
||||||
|
if (!ObjectUtils.isEmpty(selectedPermissionsArray)) {
|
||||||
|
for (String selectedId : selectedPermissionsArray) {
|
||||||
|
selectedPermissionIds.add(Long.valueOf(selectedId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Collection<Permission> allPermissions = this.permissionRepository.findAll();
|
||||||
|
for (Permission permission : allPermissions) {
|
||||||
|
if (selectedPermissionIds.contains(permission.getId())) {
|
||||||
|
selectedPermissions.add(permission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selectedPermissions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+21
-1
@@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.mifosng.data.ApiParameterError;
|
import org.mifosng.data.ApiParameterError;
|
||||||
import org.mifosng.data.command.UserCommand;
|
import org.mifosng.data.command.UserCommand;
|
||||||
|
import org.mifosng.platform.DataValidatorBuilder;
|
||||||
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
@@ -17,6 +18,25 @@ public class UserCommandValidator {
|
|||||||
this.command = command;
|
this.command = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void validateForUpdate() {
|
||||||
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
|
|
||||||
|
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
|
||||||
|
|
||||||
|
baseDataValidator.reset().parameter("id").value(command.getId()).notNull();
|
||||||
|
baseDataValidator.reset().parameter("firstname").value(command.getFirstname()).ignoreIfNull().notBlank();
|
||||||
|
baseDataValidator.reset().parameter("lastname").value(command.getLastname()).ignoreIfNull().notBlank();
|
||||||
|
baseDataValidator.reset().parameter("email").value(command.getEmail()).ignoreIfNull().notBlank();
|
||||||
|
baseDataValidator.reset().parameter("roles").value(command.getRoles()).ignoreIfNull().arrayNotEmpty();
|
||||||
|
|
||||||
|
baseDataValidator.reset().parameter("password").value(command.getPassword()).ignoreIfNull().notBlank();
|
||||||
|
baseDataValidator.reset().parameter("passwordRepeat").value(command.getPassword()).ignoreIfNull().notBlank();
|
||||||
|
|
||||||
|
if (!dataValidationErrors.isEmpty()) {
|
||||||
|
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void validate() {
|
public void validate() {
|
||||||
|
|
||||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||||
@@ -28,7 +48,7 @@ public class UserCommandValidator {
|
|||||||
dataValidationErrors.add(error);
|
dataValidationErrors.add(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ObjectUtils.isEmpty(command.getSelectedItems())) {
|
if (ObjectUtils.isEmpty(command.getRoles())) {
|
||||||
ApiParameterError error = ApiParameterError.parameterError("validation.msg.user.roles.cannot.be.blank", "The parameter selectedItems cannot be blank.", "selectedItems");
|
ApiParameterError error = ApiParameterError.parameterError("validation.msg.user.roles.cannot.be.blank", "The parameter selectedItems cannot be blank.", "selectedItems");
|
||||||
dataValidationErrors.add(error);
|
dataValidationErrors.add(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user