first steps around moving users to new approach.
This commit is contained in:
+1
-14
@@ -33,25 +33,12 @@ public interface CommonRestOperations {
|
||||
|
||||
void logout(String accessToken);
|
||||
|
||||
void updateProtectedResource(
|
||||
ProtectedResourceDetails loadProtectedResourceDetailsById);
|
||||
|
||||
Collection<AppUserData> retrieveAllUsers();
|
||||
|
||||
AppUserData retrieveNewUserDetails();
|
||||
|
||||
AppUserData retrieveUser(Long userId);
|
||||
void updateProtectedResource(ProtectedResourceDetails loadProtectedResourceDetailsById);
|
||||
|
||||
AppUserData retrieveCurrentUser();
|
||||
|
||||
EntityIdentifier createUser(UserCommand command);
|
||||
|
||||
EntityIdentifier updateUser(UserCommand command);
|
||||
|
||||
EntityIdentifier updateCurrentUserPassword(ChangePasswordCommand command);
|
||||
|
||||
void deleteUser(Long userId);
|
||||
|
||||
Collection<RoleData> retrieveAllRoles();
|
||||
|
||||
RoleData retrieveRole(Long roleId);
|
||||
|
||||
-84
@@ -27,7 +27,6 @@ import org.mifosng.data.PermissionData;
|
||||
import org.mifosng.data.PermissionList;
|
||||
import org.mifosng.data.RoleData;
|
||||
import org.mifosng.data.RoleList;
|
||||
import org.mifosng.data.UserList;
|
||||
import org.mifosng.data.command.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.data.command.CalculateLoanScheduleCommand;
|
||||
import org.mifosng.data.command.ChangePasswordCommand;
|
||||
@@ -531,41 +530,6 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
requestHeaders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier createUser(final UserCommand command) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/admin/user/new"));
|
||||
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
|
||||
.postForEntity(restUri, createUserRequest(command),
|
||||
EntityIdentifier.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier updateUser(UserCommand command) {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/admin/user/").concat(
|
||||
command.getId().toString()));
|
||||
|
||||
ResponseEntity<EntityIdentifier> s = this.oauthRestServiceTemplate
|
||||
.postForEntity(restUri, createUserRequest(command),
|
||||
EntityIdentifier.class);
|
||||
|
||||
return s.getBody();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityIdentifier updateCurrentUserDetails(UserCommand command) {
|
||||
try {
|
||||
@@ -602,14 +566,6 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUser(Long userId) {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/admin/user/").concat(userId.toString()));
|
||||
|
||||
this.oauthRestServiceTemplate.delete(restUri);
|
||||
}
|
||||
|
||||
private HttpEntity<UserCommand> createUserRequest(final UserCommand command) {
|
||||
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
@@ -644,46 +600,6 @@ public class CommonRestOperationsImpl implements CommonRestOperations {
|
||||
return requestEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AppUserData> retrieveAllUsers() {
|
||||
try {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/admin/user/all"));
|
||||
|
||||
ResponseEntity<UserList> s = this.oauthRestServiceTemplate
|
||||
.exchange(restUri, HttpMethod.GET, emptyRequest(),
|
||||
UserList.class);
|
||||
|
||||
return s.getBody().getUsers();
|
||||
} catch (HttpStatusCodeException e) {
|
||||
ErrorResponseList errorList = parseErrors(e);
|
||||
throw new ClientValidationException(errorList.getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserData retrieveNewUserDetails() {
|
||||
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/admin/user/new"));
|
||||
|
||||
ResponseEntity<AppUserData> s = this.oauthRestServiceTemplate.exchange(
|
||||
restUri, HttpMethod.GET, emptyRequest(), AppUserData.class);
|
||||
|
||||
return s.getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserData retrieveUser(Long userId) {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
"api/protected/admin/user/").concat(userId.toString()));
|
||||
|
||||
ResponseEntity<AppUserData> s = this.oauthRestServiceTemplate.exchange(
|
||||
restUri, HttpMethod.GET, emptyRequest(), AppUserData.class);
|
||||
|
||||
return s.getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserData retrieveCurrentUser() {
|
||||
URI restUri = URI.create(getBaseServerUrl().concat(
|
||||
|
||||
+5
-1
@@ -78,7 +78,11 @@ public class AdministrationController {
|
||||
@RequestParam(value="lastname", required=false) String lastname,
|
||||
@RequestParam(value="email", required=false) String email) {
|
||||
|
||||
UserCommand command = new UserCommand(username, firstname, lastname, email);
|
||||
UserCommand command = new UserCommand();
|
||||
command.setUsername(username);
|
||||
command.setFirstname(firstname);
|
||||
command.setLastname(lastname);
|
||||
command.setEmail(email);
|
||||
|
||||
return this.commonRestOperations.updateCurrentUserDetails(command);
|
||||
}
|
||||
|
||||
-59
@@ -4,13 +4,11 @@ import java.util.Collection;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.mifosng.data.AppUserData;
|
||||
import org.mifosng.data.EntityIdentifier;
|
||||
import org.mifosng.data.ErrorResponse;
|
||||
import org.mifosng.data.PermissionData;
|
||||
import org.mifosng.data.RoleData;
|
||||
import org.mifosng.data.command.RoleCommand;
|
||||
import org.mifosng.data.command.UserCommand;
|
||||
import org.mifosng.ui.CommonRestOperations;
|
||||
import org.mifosng.ui.loanproduct.ClientValidationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -83,63 +81,6 @@ public class AppUserController {
|
||||
return this.commonRestOperations.updateRole(command);
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/json", produces="application/json", value = "/admin/user/all", method = RequestMethod.GET)
|
||||
public @ResponseBody Collection<AppUserData> viewAllUsers() {
|
||||
|
||||
return this.commonRestOperations.retrieveAllUsers();
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/json", produces="application/json", value = "/admin/user/new", method = RequestMethod.GET)
|
||||
public @ResponseBody AppUserData viewUser() {
|
||||
|
||||
return this.commonRestOperations.retrieveNewUserDetails();
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/admin/user/new", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public @ResponseBody EntityIdentifier createNewUser(@RequestParam(value="selectedItems", required=false) String[] selectedRoles,
|
||||
@RequestParam(value="username") String username,
|
||||
@RequestParam(value="firstname") String firstname,
|
||||
@RequestParam(value="lastname") String lastname,
|
||||
@RequestParam(value="email") String email,
|
||||
@RequestParam(value="officeId") Long officeId) {
|
||||
|
||||
UserCommand command = new UserCommand(username, firstname, lastname, "", email, selectedRoles, officeId);
|
||||
|
||||
return this.commonRestOperations.createUser(command);
|
||||
}
|
||||
|
||||
@RequestMapping(consumes = "application/json", produces = "application/json", value = "/admin/user/{userId}", method = RequestMethod.DELETE)
|
||||
public @ResponseBody
|
||||
EntityIdentifier attemptToDeleteUser(@PathVariable("userId") Long userId) {
|
||||
|
||||
this.commonRestOperations.deleteUser(userId);
|
||||
|
||||
return new EntityIdentifier(Long.valueOf(1));
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/json", produces="application/json", value = "/admin/user/{userId}", method = RequestMethod.GET)
|
||||
public @ResponseBody AppUserData viewUser(@PathVariable("userId") Long userId) {
|
||||
|
||||
return this.commonRestOperations.retrieveUser(userId);
|
||||
}
|
||||
|
||||
@RequestMapping(consumes="application/x-www-form-urlencoded", produces="application/json", value = "/admin/user/{userId}", method = RequestMethod.POST)
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public @ResponseBody EntityIdentifier updateUser(@PathVariable("userId") Long userId,
|
||||
@RequestParam(value="selectedItems", required=false) String[] selectedRoles,
|
||||
@RequestParam(value="username") String username,
|
||||
@RequestParam(value="firstname") String firstname,
|
||||
@RequestParam(value="lastname") String lastname,
|
||||
@RequestParam(value="email") String email,
|
||||
@RequestParam(value="officeId") Long officeId) {
|
||||
|
||||
UserCommand command = new UserCommand(username, firstname, lastname, "", email, selectedRoles, officeId);
|
||||
command.setId(userId);
|
||||
|
||||
return this.commonRestOperations.updateUser(command);
|
||||
}
|
||||
|
||||
@ExceptionHandler(ClientValidationException.class)
|
||||
public @ResponseBody Collection<ErrorResponse> validationException(ClientValidationException ex, HttpServletResponse response) {
|
||||
|
||||
|
||||
@@ -220,13 +220,10 @@
|
||||
$('#selectedItems option').each(function(i) {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
|
||||
|
||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(newFormData);
|
||||
|
||||
var form_data = $('#entityform').serialize();
|
||||
|
||||
var jqxhr = $.ajax({
|
||||
url: postUrl,
|
||||
type: submitType,
|
||||
|
||||
@@ -55,9 +55,9 @@ $(document).ready(function() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
globalDate: function(dateParts) {
|
||||
globalDate: function(localDateAsISOString) {
|
||||
try {
|
||||
|
||||
var dateParts = localDateAsISOString.split("-")
|
||||
var year = dateParts[0];
|
||||
var month = parseInt(dateParts[1]) - 1; // month is zero indexed
|
||||
var day = dateParts[2];
|
||||
@@ -70,9 +70,9 @@ $(document).ready(function() {
|
||||
return "??";
|
||||
}
|
||||
},
|
||||
globalDateTime: function(dateParts) {
|
||||
globalDateTime: function(dateInMillis) {
|
||||
try {
|
||||
var d = new Date(dateParts);
|
||||
var d = new Date(dateInMillis);
|
||||
|
||||
return Globalize.format(d,"F");
|
||||
} catch(e) {
|
||||
@@ -114,17 +114,28 @@ $(document).ready(function() {
|
||||
removeErrors(placeholderDiv);
|
||||
|
||||
var jsonErrors = JSON.parse(jqXHR.responseText);
|
||||
|
||||
console.log(jsonErrors);
|
||||
var valErrors = jsonErrors.errors;
|
||||
console.log(valErrors);
|
||||
var errorArray = new Array();
|
||||
var arrayIndex = 0;
|
||||
$.each(jsonErrors, function() {
|
||||
var fieldId = '#' + this.field;
|
||||
$.each(valErrors, function() {
|
||||
var fieldId = '#' + this.parameterName;
|
||||
$(fieldId).addClass("ui-state-error");
|
||||
|
||||
var errorObj = new Object();
|
||||
errorObj.field = this.field;
|
||||
errorObj.code = this.code;
|
||||
errorObj.message = jQuery.i18n.prop(this.code, this.args);
|
||||
errorObj.field = this.parameterName;
|
||||
errorObj.code = this.userMessageGlobalisationCode;
|
||||
|
||||
var argArray = new Array();
|
||||
var argArrayIndex = 0;
|
||||
$.each(this.args, function() {
|
||||
argArray[argArrayIndex] = this.value;
|
||||
argArrayIndex++;
|
||||
});
|
||||
console.log(argArray);
|
||||
// hardcoded support for six arguments
|
||||
errorObj.message = jQuery.i18n.prop(this.userMessageGlobalisationCode, argArray[0], argArray[1], argArray[2], argArray[3], argArray[4], argArray[5]);
|
||||
errorObj.value = this.value;
|
||||
|
||||
errorArray[arrayIndex] = errorObj;
|
||||
@@ -144,17 +155,33 @@ $(document).ready(function() {
|
||||
}
|
||||
}
|
||||
|
||||
function popupDialogWithFormView(url, titleCode, templateSelector, width, height, saveSuccessFunction) {
|
||||
$.fn.serializeObject = function()
|
||||
{
|
||||
var o = {};
|
||||
var a = this.serializeArray();
|
||||
$.each(a, function() {
|
||||
if (o[this.name] !== undefined) {
|
||||
if (!o[this.name].push) {
|
||||
o[this.name] = [o[this.name]];
|
||||
}
|
||||
o[this.name].push(this.value || '');
|
||||
} else {
|
||||
o[this.name] = this.value || '';
|
||||
}
|
||||
});
|
||||
return o;
|
||||
};
|
||||
|
||||
function popupDialogWithFormView(getUrl, postUrl, submitType, titleCode, templateSelector, width, height, saveSuccessFunction) {
|
||||
var dialogDiv = $("<div id='dialog-form'></div>");
|
||||
|
||||
var jqxhr = $.ajax({
|
||||
url: url,
|
||||
url: getUrl,
|
||||
type: 'GET',
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
|
||||
console.log(data);
|
||||
var formHtml = $(templateSelector).render(data);
|
||||
|
||||
dialogDiv.append(formHtml);
|
||||
@@ -173,17 +200,20 @@ $(document).ready(function() {
|
||||
$(this).attr("selected", "selected");
|
||||
});
|
||||
|
||||
var form_data = $('#entityform').serialize();
|
||||
|
||||
|
||||
var newFormData = JSON.stringify($('#entityform').serializeObject());
|
||||
console.log(newFormData);
|
||||
|
||||
var jqxhr = $.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: form_data,
|
||||
success: saveSuccessFunction
|
||||
});
|
||||
|
||||
jqxhr.error(function(jqXHR, textStatus, errorThrown) {
|
||||
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
|
||||
url: postUrl,
|
||||
type: submitType,
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
data: newFormData,
|
||||
success: saveSuccessFunction,
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -197,7 +227,7 @@ $(document).ready(function() {
|
||||
buttons: buttonsOpts,
|
||||
close: function() {
|
||||
// if i dont do this, theres a problem with errors being appended to dialog view second time round
|
||||
$(this).dialog("destroy").remove();
|
||||
$(this).remove();
|
||||
},
|
||||
open: function (event, ui) {
|
||||
|
||||
@@ -232,11 +262,8 @@ $(document).ready(function() {
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
|
||||
var tableObj = new Object();
|
||||
tableObj.items = data;
|
||||
|
||||
var tableHtml = $(templateSelector).render(tableObj);
|
||||
console.log(data);
|
||||
var tableHtml = $(templateSelector).render(data);
|
||||
|
||||
$(displayAreaDivSelector).html("");
|
||||
$(displayAreaDivSelector).html(tableHtml);
|
||||
@@ -248,7 +275,7 @@ $(document).ready(function() {
|
||||
|
||||
var width = 1000;
|
||||
var height = 550;
|
||||
popupDialogWithFormView(url, 'dialog.title.edit.details', singleEntityTemplateSelector, width, height, saveSuccessFunction);
|
||||
popupDialogWithFormView(url, url, 'PUT', 'dialog.title.edit.details', singleEntityTemplateSelector, width, height, saveSuccessFunction);
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
@@ -295,46 +322,24 @@ $(document).ready(function() {
|
||||
}
|
||||
|
||||
$('#listusers').click(function(e) {
|
||||
var listUrl = "${allUsersUrl}";
|
||||
var templateSelector = "#usersListTemplate";
|
||||
var displayAreaDivSelector = "#contentplaceholder";
|
||||
var singleEntityPrefixUrl = '${rootContext}admin/user/';
|
||||
var singleEntityTemplateSelector = "#userFormTemplate";
|
||||
|
||||
var saveSuccessFunction = function(data, textStatus, jqXHR) {
|
||||
$("#dialog-form").dialog("destroy").remove();
|
||||
var listUrl = "${allUsersUrl}";
|
||||
var templateSelector = "#usersListTemplate";
|
||||
var displayAreaDivSelector = "#contentplaceholder";
|
||||
var singleEntityPrefixUrl = '${rootContext}admin/user/';
|
||||
var singleEntityTemplateSelector = "#userFormTemplate";
|
||||
|
||||
displayListView(listUrl, templateSelector, displayAreaDivSelector, singleEntityPrefixUrl, singleEntityTemplateSelector);
|
||||
}
|
||||
|
||||
displayListView(listUrl, templateSelector, displayAreaDivSelector, singleEntityPrefixUrl, singleEntityTemplateSelector, saveSuccessFunction);
|
||||
|
||||
var listUrl = "http://localhost:8085/mifosng-provider/api/v1/users";
|
||||
refreshUsersView();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$('#adduser').click(function(e) {
|
||||
var url = '${rootContext}admin/user/new';
|
||||
var url = 'http://localhost:8085/mifosng-provider/api/v1/users/template';
|
||||
var postUrl = "http://localhost:8085/mifosng-provider/api/v1/users";
|
||||
var templateSelector = "#userFormTemplate";
|
||||
var width = 1000;
|
||||
var height = 550;
|
||||
|
||||
var saveSuccessFunction = function(data, textStatus, jqXHR) {
|
||||
$("#dialog-form").dialog("close");
|
||||
var listUrl = "${allUsersUrl}";
|
||||
var templateSelector = "#usersListTemplate";
|
||||
var displayAreaDivSelector = "#contentplaceholder";
|
||||
var singleEntityPrefixUrl = '${rootContext}admin/user/';
|
||||
var singleEntityTemplateSelector = "#userFormTemplate";
|
||||
|
||||
displayListView(listUrl, templateSelector, displayAreaDivSelector, singleEntityPrefixUrl, singleEntityTemplateSelector);
|
||||
$("#dialog-form").dialog("close");
|
||||
refreshUsersView();
|
||||
}
|
||||
|
||||
popupDialogWithFormView(url, 'dialog.title.add.user', templateSelector, width, height, saveSuccessFunction);
|
||||
popupDialogWithFormView(url, postUrl, 'POST', 'dialog.title.add.user', templateSelector, width, height, saveSuccessFunction);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
@@ -397,6 +402,71 @@ $(document).ready(function() {
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
function refreshUsersView() {
|
||||
|
||||
var listUrl = 'http://localhost:8085/mifosng-provider/api/v1/users';
|
||||
var templateSelector = "#usersListTemplate";
|
||||
var displayAreaDivSelector = "#contentplaceholder";
|
||||
var singleEntityPrefixUrl = 'http://localhost:8085/mifosng-provider/api/v1/users/';
|
||||
var singleEntityTemplateSelector = "#userFormTemplate";
|
||||
|
||||
var jqxhr = $.ajax({
|
||||
url: listUrl,
|
||||
type: 'GET',
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
console.log(data);
|
||||
var officeListHtml = $(templateSelector).render(data);
|
||||
$(displayAreaDivSelector).html(officeListHtml);
|
||||
|
||||
$("a.edit").click( function(e) {
|
||||
var linkId = this.id;
|
||||
var entityId = linkId.replace("edit", "");
|
||||
var getUrl = 'http://localhost:8085/mifosng-provider/api/v1/users/' + entityId;
|
||||
var putUrl = 'http://localhost:8085/mifosng-provider/api/v1/users/' + entityId;
|
||||
|
||||
var templateSelector = "#userFormTemplate";
|
||||
var width = 600;
|
||||
var height = 400;
|
||||
|
||||
var saveSuccessFunction = function(data, textStatus, jqXHR) {
|
||||
$("#dialog-form").dialog("close");
|
||||
refreshUsersView();
|
||||
}
|
||||
|
||||
popupDialogWithFormView(getUrl, putUrl, 'PUT', "dialog.title.edit.details", templateSelector, width, height, saveSuccessFunction);
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("a.delete").click( function(e) {
|
||||
var linkId = this.id;
|
||||
var entityId = linkId.replace("delete", "");
|
||||
var url = 'http://localhost:8085/mifosng-provider/api/v1/users/' + entityId;
|
||||
showNotAvailableDialog('dialog.title.functionality.not.available');
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
var oTable = $("#entitytable").dataTable( {
|
||||
"bSort": true,
|
||||
"bInfo": true,
|
||||
"bJQueryUI": true,
|
||||
"bRetrieve": false,
|
||||
"bScrollCollapse": false,
|
||||
"bPaginate": false,
|
||||
"bLengthChange": false,
|
||||
"bFilter": false,
|
||||
"bAutoWidth": false,
|
||||
} );
|
||||
}
|
||||
});
|
||||
|
||||
jqxhr.error(function(jqXHR, textStatus, errorThrown) {
|
||||
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
|
||||
});
|
||||
}
|
||||
// end of document.ready
|
||||
});
|
||||
</script>
|
||||
|
||||
+1
-1
@@ -440,7 +440,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each items}}
|
||||
{{#each users}}
|
||||
<tr>
|
||||
<td>{{=officeName}}</td>
|
||||
<td>{{=username}}</td>
|
||||
|
||||
Reference in New Issue
Block a user