Continue tidy up of DDL and reference data, focusing on user admin area correcting api and implementation details.
This commit is contained in:
@@ -4,28 +4,27 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.audit.api.ProcessingResultLookup;
|
||||
import org.mifosplatform.useradministration.data.AppUserLookup;
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
|
||||
/**
|
||||
* Immutable data object representing client data.
|
||||
* Immutable data object representing audit search results.
|
||||
*/
|
||||
public final class AuditSearchData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<AppUserLookup> appUsers;
|
||||
@SuppressWarnings("unused")
|
||||
private final List<String> actionNames;
|
||||
@SuppressWarnings("unused")
|
||||
private final List<String> entityNames;
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<ProcessingResultLookup> processingResults;
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<AppUserData> appUsers;
|
||||
@SuppressWarnings("unused")
|
||||
private final List<String> actionNames;
|
||||
@SuppressWarnings("unused")
|
||||
private final List<String> entityNames;
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<ProcessingResultLookup> processingResults;
|
||||
|
||||
public AuditSearchData(final Collection<AppUserLookup> appUsers,
|
||||
final List<String> apiOperations, final List<String> resources,
|
||||
final Collection<ProcessingResultLookup> processingResults) {
|
||||
this.appUsers = appUsers;
|
||||
this.actionNames = apiOperations;
|
||||
this.entityNames = resources;
|
||||
this.processingResults = processingResults;
|
||||
}
|
||||
public AuditSearchData(final Collection<AppUserData> appUsers, final List<String> apiOperations, final List<String> resources,
|
||||
final Collection<ProcessingResultLookup> processingResults) {
|
||||
this.appUsers = appUsers;
|
||||
this.actionNames = apiOperations;
|
||||
this.entityNames = resources;
|
||||
this.processingResults = processingResults;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -13,7 +13,7 @@ import org.mifosplatform.audit.data.AuditSearchData;
|
||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.useradministration.data.AppUserLookup;
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
import org.mifosplatform.useradministration.service.AppUserReadPlatformService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -104,7 +104,7 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
|
||||
|
||||
@Override
|
||||
public AuditSearchData retrieveSearchTemplate() {
|
||||
Collection<AppUserLookup> appUsers = appUserReadPlatformService.retrieveSearchTemplate();
|
||||
final Collection<AppUserData> appUsers = appUserReadPlatformService.retrieveSearchTemplate();
|
||||
|
||||
ActionNamesMapper mapper = new ActionNamesMapper();
|
||||
List<String> actionNames = this.jdbcTemplate.query(mapper.schema(), mapper, new Object[] {});
|
||||
|
||||
+6
-2
@@ -21,13 +21,17 @@ public class OfficeData {
|
||||
@SuppressWarnings("unused")
|
||||
private final List<OfficeLookup> allowedParents;
|
||||
|
||||
public static OfficeData dropdown(final Long id, final String name, final String nameDecorated) {
|
||||
return new OfficeData(id, name, nameDecorated, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public static OfficeData template(final List<OfficeLookup> parentLookups, final LocalDate defaultOpeningDate) {
|
||||
return new OfficeData(null, null, null, null, defaultOpeningDate, null, null, null, parentLookups);
|
||||
}
|
||||
|
||||
public static OfficeData appendedTemplate(final OfficeData office, final List<OfficeLookup> allowedParents) {
|
||||
return new OfficeData(office.id, office.name, office.nameDecorated, office.externalId, office.openingDate,
|
||||
office.hierarchy, office.parentId, office.parentName, allowedParents);
|
||||
return new OfficeData(office.id, office.name, office.nameDecorated, office.externalId, office.openingDate, office.hierarchy,
|
||||
office.parentId, office.parentName, allowedParents);
|
||||
}
|
||||
|
||||
public OfficeData(final Long id, final String name, final String nameDecorated, final String externalId, final LocalDate openingDate,
|
||||
|
||||
+2
@@ -11,6 +11,8 @@ public interface OfficeReadPlatformService {
|
||||
|
||||
Collection<OfficeData> retrieveAllOffices();
|
||||
|
||||
Collection<OfficeData> retrieveAllOfficesForDropdown();
|
||||
|
||||
Collection<OfficeLookup> retrieveAllOfficesForLookup();
|
||||
|
||||
OfficeData retrieveOffice(Long officeId);
|
||||
|
||||
+30
-1
@@ -66,6 +66,23 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
}
|
||||
}
|
||||
|
||||
private static final class OfficeDropdownMapper implements RowMapper<OfficeData> {
|
||||
|
||||
public String schema() {
|
||||
return " o.id as id, " + nameDecoratedBaseOnHierarchy + " as nameDecorated, o.name as name from m_office o ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long id = rs.getLong("id");
|
||||
final String name = rs.getString("name");
|
||||
final String nameDecorated = rs.getString("nameDecorated");
|
||||
|
||||
return OfficeData.dropdown(id, name, nameDecorated);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class OfficeLookupMapper implements RowMapper<OfficeLookup> {
|
||||
|
||||
public String officeLookupSchema() {
|
||||
@@ -137,6 +154,19 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<OfficeData> retrieveAllOfficesForDropdown() {
|
||||
final AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
final String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
final String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
final OfficeDropdownMapper rm = new OfficeDropdownMapper();
|
||||
final String sql = "select " + rm.schema() + "where o.hierarchy like ? order by o.hierarchy";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<OfficeLookup> retrieveAllOfficesForLookup() {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
@@ -226,5 +256,4 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
|
||||
return new OfficeTransactionData(new LocalDate(), parentLookups, currencyOptions);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -22,7 +22,7 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.useradministration.data.PermissionUsageData;
|
||||
import org.mifosplatform.useradministration.data.PermissionData;
|
||||
import org.mifosplatform.useradministration.service.PermissionReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -39,13 +39,13 @@ public class PermissionsApiResource {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final PermissionReadPlatformService permissionReadPlatformService;
|
||||
private final DefaultToApiJsonSerializer<PermissionUsageData> toApiJsonSerializer;
|
||||
private final DefaultToApiJsonSerializer<PermissionData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public PermissionsApiResource(final PlatformSecurityContext context, final PermissionReadPlatformService readPlatformService,
|
||||
final DefaultToApiJsonSerializer<PermissionUsageData> toApiJsonSerializer,
|
||||
final DefaultToApiJsonSerializer<PermissionData> toApiJsonSerializer,
|
||||
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
@@ -64,7 +64,7 @@ public class PermissionsApiResource {
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
Collection<PermissionUsageData> permissions = null;
|
||||
Collection<PermissionData> permissions = null;
|
||||
if (settings.isMakerCheckerable()) {
|
||||
permissions = this.permissionReadPlatformService.retrieveAllMakerCheckerablePermissions();
|
||||
} else {
|
||||
|
||||
+7
-8
@@ -22,7 +22,6 @@ import org.mifosplatform.commands.domain.CommandWrapper;
|
||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService;
|
||||
import org.mifosplatform.infrastructure.codes.data.CodeData;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
@@ -30,7 +29,7 @@ import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSeria
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.mifosplatform.useradministration.data.PermissionUsageData;
|
||||
import org.mifosplatform.useradministration.data.PermissionData;
|
||||
import org.mifosplatform.useradministration.data.RoleData;
|
||||
import org.mifosplatform.useradministration.data.RolePermissionsData;
|
||||
import org.mifosplatform.useradministration.serialization.PermissionsCommandFromApiJsonDeserializer;
|
||||
@@ -47,13 +46,13 @@ import org.springframework.stereotype.Component;
|
||||
public class RolesApiResource {
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link CodeData}
|
||||
* The set of parameters that are supported in response for {@link RoleData}
|
||||
*/
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
|
||||
"availablePermissions", "selectedPermissions"));
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link CodeData}
|
||||
* The set of parameters that are supported in response for {@link RoleData}
|
||||
*/
|
||||
private final Set<String> PERMISSIONS_RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
|
||||
"permissionUsageData"));
|
||||
@@ -169,15 +168,15 @@ public class RolesApiResource {
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
final RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
||||
final Collection<PermissionUsageData> permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
|
||||
Collection<PermissionUsageData> currentChanges = null;
|
||||
final Collection<PermissionData> permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
|
||||
Collection<PermissionData> currentChanges = null;
|
||||
|
||||
if (settings.isCommandIdPassed()) {
|
||||
final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(settings.getCommandId());
|
||||
PermissionsCommand command = permissionsFromApiJsonDeserializer.commandFromApiJson(entry.json());
|
||||
currentChanges = new ArrayList<PermissionUsageData>();
|
||||
currentChanges = new ArrayList<PermissionData>();
|
||||
for (String key : command.getPermissions().keySet()) {
|
||||
currentChanges.add(PermissionUsageData.from(key, command.getPermissions().get(key)));
|
||||
currentChanges.add(PermissionData.from(key, command.getPermissions().get(key)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -1,10 +1,8 @@
|
||||
package org.mifosplatform.useradministration.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
@@ -27,7 +25,7 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.data.OfficeLookup;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
import org.mifosplatform.useradministration.service.AppUserReadPlatformService;
|
||||
@@ -94,8 +92,8 @@ public class UsersApiResource {
|
||||
|
||||
AppUserData user = this.readPlatformService.retrieveUser(userId);
|
||||
if (settings.isTemplate()) {
|
||||
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(this.officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||
user = new AppUserData(user, offices);
|
||||
final Collection<OfficeData> offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
|
||||
user = AppUserData.template(user, offices);
|
||||
}
|
||||
|
||||
return this.toApiJsonSerializer.serialize(settings, user, RESPONSE_DATA_PARAMETERS);
|
||||
@@ -153,7 +151,7 @@ public class UsersApiResource {
|
||||
public String deleteUser(@PathParam("userId") final Long userId) {
|
||||
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
|
||||
.updateUser(userId) //
|
||||
.deleteUser(userId) //
|
||||
.build();
|
||||
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
|
||||
-33
@@ -1,12 +1,5 @@
|
||||
package org.mifosplatform.useradministration.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
|
||||
/**
|
||||
* Immutable command for creating or updating details of a role.
|
||||
*/
|
||||
@@ -27,30 +20,4 @@ public class RoleCommand {
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void validateForCreate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
|
||||
|
||||
baseDataValidator.reset().parameter("name").value(this.name).notBlank();
|
||||
baseDataValidator.reset().parameter("description").value(this.description).notBlank().notExceedingLengthOf(500);
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public void validateForUpdate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
|
||||
|
||||
baseDataValidator.reset().parameter("name").value(this.name).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("description").value(this.description).ignoreIfNull().notBlank().notExceedingLengthOf(500);
|
||||
|
||||
baseDataValidator.reset().anyOfNotNull(this.name, this.description);
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
}
|
||||
-113
@@ -1,113 +0,0 @@
|
||||
package org.mifosplatform.useradministration.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
|
||||
/**
|
||||
* Immutable command for creating or updating details of a User.
|
||||
*/
|
||||
public class UserCommand {
|
||||
|
||||
private final String username;
|
||||
private final String firstname;
|
||||
private final String lastname;
|
||||
private final String password;
|
||||
private final String repeatPassword;
|
||||
private final String email;
|
||||
private final Long officeId;
|
||||
private final String[] notSelectedRoles;
|
||||
private final String[] roles;
|
||||
|
||||
public UserCommand(final String username, final String firstname, final String lastname, final String password,
|
||||
final String repeatPassword, final String email, final Long officeId, final String[] notSelectedRoles, final String[] roles) {
|
||||
this.username = username;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.password = password;
|
||||
this.repeatPassword = repeatPassword;
|
||||
this.email = email;
|
||||
this.officeId = officeId;
|
||||
this.notSelectedRoles = notSelectedRoles;
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getRepeatPassword() {
|
||||
return repeatPassword;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public Long getOfficeId() {
|
||||
return officeId;
|
||||
}
|
||||
|
||||
public String[] getNotSelectedRoles() {
|
||||
return notSelectedRoles;
|
||||
}
|
||||
|
||||
public String[] getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void validateForCreate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("user");
|
||||
|
||||
baseDataValidator.reset().parameter("username").value(this.username).notBlank();
|
||||
baseDataValidator.reset().parameter("firstname").value(this.firstname).notBlank();
|
||||
baseDataValidator.reset().parameter("lastname").value(this.lastname).notBlank();
|
||||
baseDataValidator.reset().parameter("email").value(this.email).notBlank();
|
||||
baseDataValidator.reset().parameter("officeId").value(this.officeId).notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("roles").value(this.roles).arrayNotEmpty();
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public void validateForUpdate() {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("user");
|
||||
|
||||
baseDataValidator.reset().parameter("username").value(this.username).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("firstname").value(this.firstname).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("lastname").value(this.lastname).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("email").value(this.email).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("officeId").value(this.officeId).ignoreIfNull().notNull().integerGreaterThanZero();
|
||||
baseDataValidator.reset().parameter("roles").value(this.roles).ignoreIfNull().arrayNotEmpty();
|
||||
|
||||
baseDataValidator.reset().parameter("password").value(this.password).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("passwordRepeat").value(this.repeatPassword).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("password").value(this.password).ignoreIfNull()
|
||||
.equalToParameter("repeatPassword", this.repeatPassword);
|
||||
|
||||
baseDataValidator.reset().anyOfNotNull(this.username, this.firstname, this.lastname, this.email, this.officeId, this.roles,
|
||||
this.password, this.repeatPassword);
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
}
|
||||
+28
-38
@@ -1,9 +1,8 @@
|
||||
package org.mifosplatform.useradministration.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.organisation.office.data.OfficeLookup;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
|
||||
/**
|
||||
* Immutable data object for application user data.
|
||||
@@ -19,12 +18,32 @@ public class AppUserData {
|
||||
private final String email;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final List<OfficeLookup> allowedOffices;
|
||||
private final List<RoleData> availableRoles;
|
||||
private final List<RoleData> selectedRoles;
|
||||
private final Collection<OfficeData> allowedOffices;
|
||||
private final Collection<RoleData> availableRoles;
|
||||
private final Collection<RoleData> selectedRoles;
|
||||
|
||||
public AppUserData(final Long id, final String username, final String email, final Long officeId, final String officeName,
|
||||
final String firstname, final String lastname, final List<RoleData> availableRoles, final List<RoleData> selectedRoles) {
|
||||
public static AppUserData template(AppUserData user, Collection<OfficeData> officesForDropdown) {
|
||||
return new AppUserData(user.id, user.username, user.email, user.officeId, user.officeName, user.firstname, user.lastname,
|
||||
user.availableRoles, user.selectedRoles, officesForDropdown);
|
||||
}
|
||||
|
||||
public static AppUserData template(final Collection<OfficeData> offices, final Collection<RoleData> availableRoles) {
|
||||
return new AppUserData(null, null, null, null, null, null, null, availableRoles, null, offices);
|
||||
}
|
||||
|
||||
public static AppUserData dropdown(final Long id, final String username) {
|
||||
return new AppUserData(id, username, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public static AppUserData instance(final Long id, final String username, final String email, final Long officeId,
|
||||
final String officeName, final String firstname, final String lastname, final Collection<RoleData> availableRoles,
|
||||
final Collection<RoleData> selectedRoles) {
|
||||
return new AppUserData(id, username, email, officeId, officeName, firstname, lastname, availableRoles, selectedRoles, null);
|
||||
}
|
||||
|
||||
private AppUserData(final Long id, final String username, final String email, final Long officeId, final String officeName,
|
||||
final String firstname, final String lastname, final Collection<RoleData> availableRoles,
|
||||
final Collection<RoleData> selectedRoles, final Collection<OfficeData> allowedOffices) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.officeId = officeId;
|
||||
@@ -32,40 +51,11 @@ public class AppUserData {
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.email = email;
|
||||
|
||||
this.allowedOffices = new ArrayList<OfficeLookup>();
|
||||
this.allowedOffices = allowedOffices;
|
||||
this.availableRoles = availableRoles;
|
||||
this.selectedRoles = selectedRoles;
|
||||
}
|
||||
|
||||
public AppUserData(final AppUserData user, final List<OfficeLookup> allowedOffices) {
|
||||
this.id = user.id;
|
||||
this.username = user.username;
|
||||
this.officeId = user.officeId;
|
||||
this.officeName = user.officeName;
|
||||
this.firstname = user.firstname;
|
||||
this.lastname = user.lastname;
|
||||
this.email = user.email;
|
||||
|
||||
this.allowedOffices = allowedOffices;
|
||||
this.availableRoles = user.availableRoles;
|
||||
this.selectedRoles = user.selectedRoles;
|
||||
}
|
||||
|
||||
public AppUserData(final List<OfficeLookup> allowedOffices, final List<RoleData> availableRoles) {
|
||||
this.id = null;
|
||||
this.username = null;
|
||||
this.officeId = null;
|
||||
this.officeName = null;
|
||||
this.firstname = null;
|
||||
this.lastname = null;
|
||||
this.email = null;
|
||||
|
||||
this.allowedOffices = allowedOffices;
|
||||
this.availableRoles = availableRoles;
|
||||
this.selectedRoles = new ArrayList<RoleData>();
|
||||
}
|
||||
|
||||
public boolean hasIdentifyOf(final Long createdById) {
|
||||
return this.id.equals(createdById);
|
||||
}
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package org.mifosplatform.useradministration.data;
|
||||
|
||||
/**
|
||||
* Immutable data object for application user data.
|
||||
*/
|
||||
public class AppUserLookup {
|
||||
|
||||
private final Long id;
|
||||
private final String username;
|
||||
|
||||
public AppUserLookup(final Long id, final String username) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
}
|
||||
+9
-4
@@ -3,7 +3,7 @@ package org.mifosplatform.useradministration.data;
|
||||
/**
|
||||
* Immutable representation of permissions
|
||||
*/
|
||||
public class PermissionUsageData {
|
||||
public class PermissionData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String grouping;
|
||||
@@ -16,11 +16,16 @@ public class PermissionUsageData {
|
||||
@SuppressWarnings("unused")
|
||||
private final Boolean selected;
|
||||
|
||||
public static PermissionUsageData from(final String permissionCode, final boolean isSelected) {
|
||||
return new PermissionUsageData(null, permissionCode, null, null, isSelected);
|
||||
public static PermissionData from(final String permissionCode, final boolean isSelected) {
|
||||
return new PermissionData(null, permissionCode, null, null, isSelected);
|
||||
}
|
||||
|
||||
public PermissionUsageData(final String grouping, final String code, final String entityName, final String actionName,
|
||||
public static PermissionData instance(final String grouping, final String code, final String entityName, final String actionName,
|
||||
final Boolean selected) {
|
||||
return new PermissionData(grouping, code, entityName, actionName, selected);
|
||||
}
|
||||
|
||||
private PermissionData(final String grouping, final String code, final String entityName, final String actionName,
|
||||
final Boolean selected) {
|
||||
this.grouping = grouping;
|
||||
this.code = code;
|
||||
+7
-6
@@ -12,11 +12,16 @@ public class RoleData {
|
||||
private final String description;
|
||||
@SuppressWarnings("unused")
|
||||
private final RoleData currentChanges;
|
||||
|
||||
|
||||
public RolePermissionsData toRolePermissionData(final Collection<PermissionData> permissionUsageData,
|
||||
final Collection<PermissionData> currentChanges) {
|
||||
return new RolePermissionsData(id, name, description, permissionUsageData, currentChanges);
|
||||
}
|
||||
|
||||
public static RoleData changes(final String name, final String description) {
|
||||
return new RoleData(null, name, description, null);
|
||||
}
|
||||
|
||||
|
||||
public static RoleData integrateChanges(final RoleData role, final RoleData currentChanges) {
|
||||
return new RoleData(role.id, role.name, role.description, currentChanges);
|
||||
}
|
||||
@@ -38,8 +43,4 @@ public class RoleData {
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
public RolePermissionsData toRolePermissionData(final Collection<PermissionUsageData> permissionUsageData, final Collection<PermissionUsageData> currentChanges) {
|
||||
return new RolePermissionsData(id, name, description, permissionUsageData, currentChanges);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -15,12 +15,12 @@ public class RolePermissionsData {
|
||||
private final String description;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<PermissionUsageData> permissionUsageData;
|
||||
private final Collection<PermissionData> permissionUsageData;
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<PermissionUsageData> currentChanges;
|
||||
private final Collection<PermissionData> currentChanges;
|
||||
|
||||
public RolePermissionsData(final Long id, final String name, final String description,
|
||||
final Collection<PermissionUsageData> permissionUsageData, final Collection<PermissionUsageData> currentChanges) {
|
||||
final Collection<PermissionData> permissionUsageData, final Collection<PermissionData> currentChanges) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
|
||||
+6
-7
@@ -20,20 +20,20 @@ import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
||||
import org.mifosplatform.infrastructure.security.domain.PlatformUser;
|
||||
import org.mifosplatform.infrastructure.security.exception.NoAuthorizationException;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformPasswordEncoder;
|
||||
import org.mifosplatform.organisation.office.domain.Office;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_appuser", uniqueConstraints = @UniqueConstraint(columnNames = { "username" }, name = "username_org"))
|
||||
public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements PlatformUser {
|
||||
public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(AppUser.class);
|
||||
|
||||
@@ -365,7 +365,7 @@ public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements P
|
||||
String matchPermission = "READ_" + entityType.toUpperCase();
|
||||
|
||||
if (!(hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", matchPermission))) return;
|
||||
|
||||
|
||||
throw new NoAuthorizationException(authorizationMessage);
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements P
|
||||
}
|
||||
return hasPermission;
|
||||
}
|
||||
|
||||
|
||||
private boolean hasAllFunctionsPermission() {
|
||||
boolean match = false;
|
||||
for (Role role : this.roles) {
|
||||
@@ -443,8 +443,7 @@ public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements P
|
||||
}
|
||||
|
||||
public void validateHasDatatableReadPermission(final String datatable) {
|
||||
if (hasNotPermissionForDatatable(datatable, "READ")) {
|
||||
throw new NoAuthorizationException("Not authorised to read datatable: " + datatable);
|
||||
}
|
||||
if (hasNotPermissionForDatatable(datatable, "READ")) { throw new NoAuthorizationException("Not authorised to read datatable: "
|
||||
+ datatable); }
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -15,12 +15,12 @@ import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
||||
import org.mifosplatform.useradministration.data.RoleData;
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_role")
|
||||
public class Role extends AbstractAuditableCustom<AppUser, Long> {
|
||||
public class Role extends AbstractPersistable<Long> {
|
||||
|
||||
@Column(name = "name", nullable = false, length = 100)
|
||||
private String name;
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN
|
||||
*/
|
||||
public class RoleNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public RoleNotFoundException(Long id) {
|
||||
super("error.msg.role.id.invalid", "Role with identifier " + id + " does not exist", id);
|
||||
}
|
||||
public RoleNotFoundException(Long id) {
|
||||
super("error.msg.role.id.invalid", "Role with identifier " + id + " does not exist", id);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -7,7 +7,7 @@ import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceN
|
||||
*/
|
||||
public class UserNotFoundException extends AbstractPlatformResourceNotFoundException {
|
||||
|
||||
public UserNotFoundException(Long id) {
|
||||
super("error.msg.user.id.invalid", "User with identifier " + id + " does not exist", id);
|
||||
}
|
||||
public UserNotFoundException(Long id) {
|
||||
super("error.msg.user.id.invalid", "User with identifier " + id + " does not exist", id);
|
||||
}
|
||||
}
|
||||
+2
-15
@@ -3,8 +3,6 @@ package org.mifosplatform.useradministration.handler;
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.mifosplatform.useradministration.service.AppUserWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -14,11 +12,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class UpdateUserCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final AppUserWritePlatformService writePlatformService;
|
||||
private final PlatformSecurityContext context;
|
||||
|
||||
@Autowired
|
||||
public UpdateUserCommandHandler(final PlatformSecurityContext context, final AppUserWritePlatformService writePlatformService) {
|
||||
this.context = context;
|
||||
public UpdateUserCommandHandler(final AppUserWritePlatformService writePlatformService) {
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@@ -26,16 +22,7 @@ public class UpdateUserCommandHandler implements NewCommandSourceHandler {
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
|
||||
final AppUser loggedInUser = context.authenticatedUser();
|
||||
|
||||
final Long userId = command.entityId();
|
||||
CommandProcessingResult result = null;
|
||||
if (loggedInUser.hasIdOf(userId)) {
|
||||
result = this.writePlatformService.updateUsersOwnAccountDetails(userId, command);
|
||||
} else {
|
||||
result = this.writePlatformService.updateUser(userId, command);
|
||||
}
|
||||
|
||||
return result;
|
||||
return this.writePlatformService.updateUser(userId, command);
|
||||
}
|
||||
}
|
||||
+54
@@ -1,13 +1,18 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
@@ -50,4 +55,53 @@ public final class RoleCommandFromApiJsonDeserializer extends AbstractFromApiJso
|
||||
|
||||
return new RoleCommand(name, description);
|
||||
}
|
||||
|
||||
public void validateForCreate(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
|
||||
final String name = fromApiJsonHelper.extractStringNamed("name", element);
|
||||
baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(100);
|
||||
|
||||
final String description = fromApiJsonHelper.extractStringNamed("description", element);
|
||||
baseDataValidator.reset().parameter("description").value(description).notBlank().notExceedingLengthOf(500);
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
public void validateForUpdate(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("role");
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("name", element)) {
|
||||
final String username = fromApiJsonHelper.extractStringNamed("name", element);
|
||||
baseDataValidator.reset().parameter("name").value(username).notBlank().notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("description", element)) {
|
||||
final String description = fromApiJsonHelper.extractStringNamed("description", element);
|
||||
baseDataValidator.reset().parameter("description").value(description).notBlank().notExceedingLengthOf(500);
|
||||
}
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link UserCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class UserCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer<UserCommand> {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("username", "firstname", "lastname", "password",
|
||||
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public UserCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserCommand commandFromApiJson(final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
|
||||
final String username = fromApiJsonHelper.extractStringNamed("username", element);
|
||||
final String firstname = fromApiJsonHelper.extractStringNamed("firstname", element);
|
||||
final String lastname = fromApiJsonHelper.extractStringNamed("lastname", element);
|
||||
final String password = fromApiJsonHelper.extractStringNamed("password", element);
|
||||
final String repeatPassword = fromApiJsonHelper.extractStringNamed("repeatPassword", element);
|
||||
final String email = fromApiJsonHelper.extractStringNamed("email", element);
|
||||
final Long officeId = fromApiJsonHelper.extractLongNamed("officeId", element);
|
||||
|
||||
final String[] notSelectedRoles = fromApiJsonHelper.extractArrayNamed("notSelectedRoles", element);
|
||||
final String[] roles = fromApiJsonHelper.extractArrayNamed("roles", element);
|
||||
|
||||
return new UserCommand(username, firstname, lastname, password, repeatPassword, email, officeId, notSelectedRoles, roles);
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation for deserializing users {@link JsonCommand} for validation.
|
||||
*/
|
||||
@Component
|
||||
public final class UserCommandFromApiJsonDeserializerHelper {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("username", "firstname", "lastname", "password",
|
||||
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public UserCommandFromApiJsonDeserializerHelper(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
public void validateForCreate(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("user");
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
|
||||
final String username = fromApiJsonHelper.extractStringNamed("username", element);
|
||||
baseDataValidator.reset().parameter("username").value(username).notBlank().notExceedingLengthOf(100);
|
||||
|
||||
final String firstname = fromApiJsonHelper.extractStringNamed("firstname", element);
|
||||
baseDataValidator.reset().parameter("firstname").value(firstname).notBlank().notExceedingLengthOf(100);
|
||||
|
||||
final String lastname = fromApiJsonHelper.extractStringNamed("lastname", element);
|
||||
baseDataValidator.reset().parameter("lastname").value(lastname).notBlank().notExceedingLengthOf(100);
|
||||
|
||||
final String email = fromApiJsonHelper.extractStringNamed("email", element);
|
||||
baseDataValidator.reset().parameter("email").value(email).notBlank().notExceedingLengthOf(100);
|
||||
|
||||
final Long officeId = fromApiJsonHelper.extractLongNamed("officeId", element);
|
||||
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
|
||||
|
||||
final String[] roles = fromApiJsonHelper.extractArrayNamed("roles", element);
|
||||
baseDataValidator.reset().parameter("roles").value(roles).arrayNotEmpty();
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public void validateForUpdate(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("user");
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("officeId", element)) {
|
||||
final Long officeId = fromApiJsonHelper.extractLongNamed("officeId", element);
|
||||
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("username", element)) {
|
||||
final String username = fromApiJsonHelper.extractStringNamed("username", element);
|
||||
baseDataValidator.reset().parameter("username").value(username).notBlank().notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("firstname", element)) {
|
||||
final String firstname = fromApiJsonHelper.extractStringNamed("firstname", element);
|
||||
baseDataValidator.reset().parameter("firstname").value(firstname).notBlank().notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("lastname", element)) {
|
||||
final String lastname = fromApiJsonHelper.extractStringNamed("lastname", element);
|
||||
baseDataValidator.reset().parameter("lastname").value(lastname).notBlank().notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("email", element)) {
|
||||
final String email = fromApiJsonHelper.extractStringNamed("email", element);
|
||||
baseDataValidator.reset().parameter("email").value(email).notBlank().notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("roles", element)) {
|
||||
final String[] roles = fromApiJsonHelper.extractArrayNamed("roles", element);
|
||||
baseDataValidator.reset().parameter("roles").value(roles).arrayNotEmpty();
|
||||
}
|
||||
|
||||
if (fromApiJsonHelper.parameterExists("password", element)) {
|
||||
final String password = fromApiJsonHelper.extractStringNamed("password", element);
|
||||
final String repeatPassword = fromApiJsonHelper.extractStringNamed("repeatPassword", element);
|
||||
baseDataValidator.reset().parameter("password").value(password).notBlank().notExceedingLengthOf(50);
|
||||
if (StringUtils.isNotBlank(password)) {
|
||||
baseDataValidator.reset().parameter("password").value(password).equalToParameter("repeatPassword", repeatPassword);
|
||||
}
|
||||
}
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -3,13 +3,12 @@ package org.mifosplatform.useradministration.service;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
import org.mifosplatform.useradministration.data.AppUserLookup;
|
||||
|
||||
public interface AppUserReadPlatformService {
|
||||
|
||||
Collection<AppUserData> retrieveAllUsers();
|
||||
|
||||
Collection<AppUserLookup> retrieveSearchTemplate();
|
||||
|
||||
Collection<AppUserData> retrieveSearchTemplate();
|
||||
|
||||
AppUserData retrieveNewUserDetails();
|
||||
|
||||
|
||||
+86
-120
@@ -4,16 +4,14 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.data.OfficeLookup;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
import org.mifosplatform.useradministration.data.AppUserLookup;
|
||||
import org.mifosplatform.useradministration.data.RoleData;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.mifosplatform.useradministration.domain.AppUserRepository;
|
||||
@@ -25,151 +23,119 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AppUserReadPlatformServiceImpl implements
|
||||
AppUserReadPlatformService {
|
||||
public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final OfficeReadPlatformService officeReadPlatformService;
|
||||
private final RoleReadPlatformService roleReadPlatformService;
|
||||
private final AppUserRepository appUserRepository;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final OfficeReadPlatformService officeReadPlatformService;
|
||||
private final RoleReadPlatformService roleReadPlatformService;
|
||||
private final AppUserRepository appUserRepository;
|
||||
|
||||
@Autowired
|
||||
public AppUserReadPlatformServiceImpl(
|
||||
final PlatformSecurityContext context,
|
||||
final TenantAwareRoutingDataSource dataSource,
|
||||
final OfficeReadPlatformService officeReadPlatformService,
|
||||
final RoleReadPlatformService roleReadPlatformService,
|
||||
final AppUserRepository appUserRepository) {
|
||||
this.context = context;
|
||||
this.officeReadPlatformService = officeReadPlatformService;
|
||||
this.roleReadPlatformService = roleReadPlatformService;
|
||||
this.appUserRepository = appUserRepository;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
@Autowired
|
||||
public AppUserReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
|
||||
final OfficeReadPlatformService officeReadPlatformService, final RoleReadPlatformService roleReadPlatformService,
|
||||
final AppUserRepository appUserRepository) {
|
||||
this.context = context;
|
||||
this.officeReadPlatformService = officeReadPlatformService;
|
||||
this.roleReadPlatformService = roleReadPlatformService;
|
||||
this.appUserRepository = appUserRepository;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AppUserData> retrieveAllUsers() {
|
||||
@Override
|
||||
public Collection<AppUserData> retrieveAllUsers() {
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
AppUserMapper mapper = new AppUserMapper();
|
||||
String sql = "select " + mapper.schema() ;
|
||||
AppUserMapper mapper = new AppUserMapper();
|
||||
String sql = "select " + mapper.schema();
|
||||
|
||||
return this.jdbcTemplate.query(sql, mapper,
|
||||
new Object[] { hierarchySearchString });
|
||||
}
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] { hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AppUserLookup> retrieveSearchTemplate() {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
@Override
|
||||
public Collection<AppUserData> retrieveSearchTemplate() {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
AppUserLookupMapper mapper = new AppUserLookupMapper();
|
||||
String sql = "select " + mapper.schema();
|
||||
AppUserLookupMapper mapper = new AppUserLookupMapper();
|
||||
String sql = "select " + mapper.schema();
|
||||
|
||||
return this.jdbcTemplate.query(sql, mapper,
|
||||
new Object[] { hierarchySearchString });
|
||||
}
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] { hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserData retrieveNewUserDetails() {
|
||||
@Override
|
||||
public AppUserData retrieveNewUserDetails() {
|
||||
|
||||
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(
|
||||
officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||
final Collection<OfficeData> offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
|
||||
final Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAllRoles();
|
||||
|
||||
List<RoleData> availableRoles = new ArrayList<RoleData>(
|
||||
this.roleReadPlatformService.retrieveAllRoles());
|
||||
return AppUserData.template(offices, availableRoles);
|
||||
}
|
||||
|
||||
AppUserData userData = new AppUserData(offices, availableRoles);
|
||||
@Override
|
||||
public AppUserData retrieveUser(final Long userId) {
|
||||
|
||||
return userData;
|
||||
}
|
||||
context.authenticatedUser();
|
||||
|
||||
@Override
|
||||
public AppUserData retrieveUser(final Long userId) {
|
||||
final AppUser user = this.appUserRepository.findOne(userId);
|
||||
if (user == null || user.isDeleted()) { throw new UserNotFoundException(userId); }
|
||||
|
||||
context.authenticatedUser();
|
||||
Collection<RoleData> availableRoles = this.roleReadPlatformService.retrieveAllRoles();
|
||||
|
||||
AppUser user = this.appUserRepository.findOne(userId);
|
||||
if (user == null || user.isDeleted()) {
|
||||
throw new UserNotFoundException(userId);
|
||||
}
|
||||
Collection<RoleData> selectedUserRoles = new ArrayList<RoleData>();
|
||||
Set<Role> userRoles = user.getRoles();
|
||||
for (Role role : userRoles) {
|
||||
selectedUserRoles.add(role.toData());
|
||||
}
|
||||
|
||||
List<RoleData> availableRoles = new ArrayList<RoleData>(
|
||||
this.roleReadPlatformService.retrieveAllRoles());
|
||||
availableRoles.removeAll(selectedUserRoles);
|
||||
|
||||
List<RoleData> selectedUserRoles = new ArrayList<RoleData>();
|
||||
Set<Role> userRoles = user.getRoles();
|
||||
for (Role role : userRoles) {
|
||||
selectedUserRoles.add(role.toData());
|
||||
}
|
||||
return AppUserData.instance(user.getId(), user.getUsername(), user.getEmail(), user.getOffice().getId(),
|
||||
user.getOffice().getName(), user.getFirstname(), user.getLastname(), availableRoles, selectedUserRoles);
|
||||
}
|
||||
|
||||
availableRoles.removeAll(selectedUserRoles);
|
||||
private static final class AppUserMapper implements RowMapper<AppUserData> {
|
||||
|
||||
AppUserData userData = new AppUserData(user.getId(),
|
||||
user.getUsername(), user.getEmail(), user.getOffice().getId(),
|
||||
user.getOffice().getName(), user.getFirstname(),
|
||||
user.getLastname(), availableRoles, selectedUserRoles);
|
||||
@Override
|
||||
public AppUserData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
return userData;
|
||||
}
|
||||
final Long id = rs.getLong("id");
|
||||
final String username = rs.getString("username");
|
||||
final String firstname = rs.getString("firstname");
|
||||
final String lastname = rs.getString("lastname");
|
||||
final String email = rs.getString("email");
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
|
||||
private static final class AppUserMapper implements RowMapper<AppUserData> {
|
||||
return AppUserData.instance(id, username, email, officeId, officeName, firstname, lastname, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserData mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
public String schema() {
|
||||
return " u.id as id, u.username as username, u.firstname as firstname, u.lastname as lastname, u.email as email,"
|
||||
+ " u.office_id as officeId, o.name as officeName from m_appuser u "
|
||||
+ " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username";
|
||||
}
|
||||
|
||||
Long id = rs.getLong("id");
|
||||
String username = rs.getString("username");
|
||||
String firstname = rs.getString("firstname");
|
||||
String lastname = rs.getString("lastname");
|
||||
String email = rs.getString("email");
|
||||
Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
}
|
||||
|
||||
String officeName = rs.getString("officeName");
|
||||
private static final class AppUserLookupMapper implements RowMapper<AppUserData> {
|
||||
|
||||
AppUserData user = new AppUserData(id, username, email, officeId,
|
||||
officeName, firstname, lastname, new ArrayList<RoleData>(),
|
||||
new ArrayList<RoleData>());
|
||||
@Override
|
||||
public AppUserData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
return user;
|
||||
}
|
||||
final Long id = rs.getLong("id");
|
||||
final String username = rs.getString("username");
|
||||
|
||||
public String schema() {
|
||||
return " u.id as id, u.username as username, u.firstname as firstname, u.lastname as lastname, u.email as email,"
|
||||
+ " u.office_id as officeId, o.name as officeName from m_appuser u "
|
||||
+ " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class AppUserLookupMapper implements
|
||||
RowMapper<AppUserLookup> {
|
||||
|
||||
@Override
|
||||
public AppUserLookup mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
|
||||
Long id = rs.getLong("id");
|
||||
String username = rs.getString("username");
|
||||
|
||||
AppUserLookup user = new AppUserLookup(id, username);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " u.id as id, u.username as username from m_appuser u "
|
||||
+ " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username";
|
||||
}
|
||||
|
||||
}
|
||||
return AppUserData.dropdown(id, username);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " u.id as id, u.username as username from m_appuser u "
|
||||
+ " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username";
|
||||
}
|
||||
}
|
||||
}
|
||||
-4
@@ -10,8 +10,4 @@ public interface AppUserWritePlatformService {
|
||||
CommandProcessingResult updateUser(Long userId, JsonCommand command);
|
||||
|
||||
CommandProcessingResult deleteUser(Long userId);
|
||||
|
||||
// we dont put any permissions on this e.g. a user with no admin rights can
|
||||
// change their own details (email, username, password etc).
|
||||
CommandProcessingResult updateUsersOwnAccountDetails(Long userId, JsonCommand command);
|
||||
}
|
||||
+15
-58
@@ -18,7 +18,6 @@ import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext
|
||||
import org.mifosplatform.organisation.office.domain.Office;
|
||||
import org.mifosplatform.organisation.office.domain.OfficeRepository;
|
||||
import org.mifosplatform.organisation.office.exception.OfficeNotFoundException;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.mifosplatform.useradministration.domain.AppUserRepository;
|
||||
import org.mifosplatform.useradministration.domain.Role;
|
||||
@@ -26,7 +25,7 @@ import org.mifosplatform.useradministration.domain.RoleRepository;
|
||||
import org.mifosplatform.useradministration.domain.UserDomainService;
|
||||
import org.mifosplatform.useradministration.exception.RoleNotFoundException;
|
||||
import org.mifosplatform.useradministration.exception.UserNotFoundException;
|
||||
import org.mifosplatform.useradministration.serialization.UserCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.useradministration.serialization.UserCommandFromApiJsonDeserializerHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -46,12 +45,12 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
private final AppUserRepository appUserRepository;
|
||||
private final OfficeRepository officeRepository;
|
||||
private final RoleRepository roleRepository;
|
||||
private final UserCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final UserCommandFromApiJsonDeserializerHelper fromApiJsonDeserializer;
|
||||
|
||||
@Autowired
|
||||
public AppUserWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final AppUserRepository appUserRepository,
|
||||
final UserDomainService userDomainService, final OfficeRepository officeRepository, final RoleRepository roleRepository,
|
||||
final PlatformPasswordEncoder platformPasswordEncoder, final UserCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
|
||||
final PlatformPasswordEncoder platformPasswordEncoder, final UserCommandFromApiJsonDeserializerHelper fromApiJsonDeserializer) {
|
||||
this.context = context;
|
||||
this.appUserRepository = appUserRepository;
|
||||
this.userDomainService = userDomainService;
|
||||
@@ -68,8 +67,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
final UserCommand userCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
userCommand.validateForCreate();
|
||||
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
||||
|
||||
final String officeIdParamName = "officeId";
|
||||
final Long officeId = command.longValueOfParameterNamed(officeIdParamName);
|
||||
@@ -83,8 +81,11 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
final AppUser appUser = AppUser.fromJson(userOffice, allRoles, command);
|
||||
this.userDomainService.create(appUser);
|
||||
|
||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(appUser.getId())
|
||||
.withOfficeId(userOffice.getId()).build();
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
.withEntityId(appUser.getId()) //
|
||||
.withOfficeId(userOffice.getId()) //
|
||||
.build();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return CommandProcessingResult.empty();
|
||||
@@ -108,55 +109,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
final UserCommand userCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
userCommand.validateForUpdate();
|
||||
|
||||
final AppUser userToUpdate = this.appUserRepository.findOne(userId);
|
||||
if (userToUpdate == null) { throw new UserNotFoundException(userId); }
|
||||
|
||||
final Map<String, Object> changes = userToUpdate.update(command, this.platformPasswordEncoder);
|
||||
|
||||
if (changes.containsKey("officeId")) {
|
||||
final Long officeId = (Long) changes.get("officeId");
|
||||
final Office office = this.officeRepository.findOne(officeId);
|
||||
if (office == null) { throw new OfficeNotFoundException(officeId); }
|
||||
|
||||
userToUpdate.changeOffice(office);
|
||||
}
|
||||
|
||||
if (changes.containsKey("roles")) {
|
||||
final String[] roleIds = (String[]) changes.get("roles");
|
||||
final Set<Role> allRoles = assembleSetOfRoles(roleIds);
|
||||
|
||||
userToUpdate.updateRoles(allRoles);
|
||||
}
|
||||
|
||||
if (!changes.isEmpty()) {
|
||||
this.appUserRepository.save(userToUpdate);
|
||||
}
|
||||
|
||||
return new CommandProcessingResultBuilder().withEntityId(userId).withOfficeId(userToUpdate.getOffice().getId()).with(changes)
|
||||
.build();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return CommandProcessingResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Different between this and <code>updateUser</code> is that we dont do
|
||||
* maker-checker flow or require that user have particular permission to
|
||||
* change their own details.
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult updateUsersOwnAccountDetails(final Long userId, final JsonCommand command) {
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
final UserCommand userCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
userCommand.validateForUpdate();
|
||||
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||
|
||||
final AppUser userToUpdate = this.appUserRepository.findOne(userId);
|
||||
if (userToUpdate == null) { throw new UserNotFoundException(userId); }
|
||||
@@ -182,7 +135,11 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
this.appUserRepository.saveAndFlush(userToUpdate);
|
||||
}
|
||||
|
||||
return CommandProcessingResult.withChanges(userId, changes);
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withEntityId(userId) //
|
||||
.withOfficeId(userToUpdate.getOffice().getId()) //
|
||||
.with(changes) //
|
||||
.build();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return CommandProcessingResult.empty();
|
||||
|
||||
+4
-4
@@ -2,13 +2,13 @@ package org.mifosplatform.useradministration.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.useradministration.data.PermissionUsageData;
|
||||
import org.mifosplatform.useradministration.data.PermissionData;
|
||||
|
||||
public interface PermissionReadPlatformService {
|
||||
|
||||
Collection<PermissionUsageData> retrieveAllPermissions();
|
||||
Collection<PermissionData> retrieveAllPermissions();
|
||||
|
||||
Collection<PermissionUsageData> retrieveAllMakerCheckerablePermissions();
|
||||
Collection<PermissionData> retrieveAllMakerCheckerablePermissions();
|
||||
|
||||
Collection<PermissionUsageData> retrieveAllRolePermissions(Long roleId);
|
||||
Collection<PermissionData> retrieveAllRolePermissions(Long roleId);
|
||||
}
|
||||
+7
-7
@@ -6,7 +6,7 @@ import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.useradministration.data.PermissionUsageData;
|
||||
import org.mifosplatform.useradministration.data.PermissionData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,7 +29,7 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionUsageData> retrieveAllPermissions() {
|
||||
public Collection<PermissionData> retrieveAllPermissions() {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
@@ -40,7 +40,7 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionUsageData> retrieveAllMakerCheckerablePermissions() {
|
||||
public Collection<PermissionData> retrieveAllMakerCheckerablePermissions() {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionUsageData> retrieveAllRolePermissions(final Long roleId) {
|
||||
public Collection<PermissionData> retrieveAllRolePermissions(final Long roleId) {
|
||||
|
||||
final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper();
|
||||
final String sql = mapper.rolePermissionSchema();
|
||||
@@ -61,10 +61,10 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] { roleId });
|
||||
}
|
||||
|
||||
private static final class PermissionUsageDataMapper implements RowMapper<PermissionUsageData> {
|
||||
private static final class PermissionUsageDataMapper implements RowMapper<PermissionData> {
|
||||
|
||||
@Override
|
||||
public PermissionUsageData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
public PermissionData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final String grouping = rs.getString("grouping");
|
||||
final String code = rs.getString("code");
|
||||
@@ -72,7 +72,7 @@ public class PermissionReadPlatformServiceImpl implements PermissionReadPlatform
|
||||
final String actionName = rs.getString("actionName");
|
||||
final Boolean selected = rs.getBoolean("selected");
|
||||
|
||||
return new PermissionUsageData(grouping, code, entityName, actionName, selected);
|
||||
return PermissionData.instance(grouping, code, entityName, actionName, selected);
|
||||
}
|
||||
|
||||
public String permissionSchema() {
|
||||
|
||||
+11
-7
@@ -9,7 +9,6 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.mifosplatform.useradministration.domain.Permission;
|
||||
import org.mifosplatform.useradministration.domain.PermissionRepository;
|
||||
import org.mifosplatform.useradministration.domain.Role;
|
||||
@@ -48,8 +47,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
final RoleCommand roleCommand = this.roleCommandFromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
roleCommand.validateForCreate();
|
||||
this.roleCommandFromApiJsonDeserializer.validateForCreate(command.json());
|
||||
|
||||
final Role entity = Role.fromJson(command);
|
||||
this.roleRepository.save(entity);
|
||||
@@ -63,8 +61,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
final RoleCommand roleCommand = this.roleCommandFromApiJsonDeserializer.commandFromApiJson(command.json());
|
||||
roleCommand.validateForUpdate();
|
||||
this.roleCommandFromApiJsonDeserializer.validateForUpdate(command.json());
|
||||
|
||||
final Role role = this.roleRepository.findOne(roleId);
|
||||
if (role == null) { throw new RoleNotFoundException(roleId); }
|
||||
@@ -74,7 +71,10 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
||||
this.roleRepository.save(role);
|
||||
}
|
||||
|
||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(roleId).with(changes).build();
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
.withEntityId(roleId).with(changes) //
|
||||
.build();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -107,7 +107,11 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf
|
||||
this.roleRepository.save(role);
|
||||
}
|
||||
|
||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(roleId).with(changes).build();
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
.withEntityId(roleId) //
|
||||
.with(changes) //
|
||||
.build();
|
||||
}
|
||||
|
||||
private Permission findPermissionByCode(Collection<Permission> allPermissions, String permissionCode) {
|
||||
|
||||
Reference in New Issue
Block a user