cleaning up commit for MIFOSX-982
This commit is contained in:
+18
-10
@@ -5,6 +5,23 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.useradministration.api;
|
package org.mifosplatform.useradministration.api;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
@@ -21,15 +38,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.UriInfo;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Path("/users")
|
@Path("/users")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@@ -42,7 +50,7 @@ public class UsersApiResource {
|
|||||||
* {@link AppUserData}.
|
* {@link AppUserData}.
|
||||||
*/
|
*/
|
||||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "username",
|
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "username",
|
||||||
"firstname", "lastname", "email", "allowedOffices", "availableRoles", "selectedRoles", "staffId"));
|
"firstname", "lastname", "email", "allowedOffices", "availableRoles", "selectedRoles", "staff"));
|
||||||
|
|
||||||
private final String resourceNameForPermissions = "USER";
|
private final String resourceNameForPermissions = "USER";
|
||||||
|
|
||||||
|
|||||||
+24
-24
@@ -7,17 +7,28 @@ package org.mifosplatform.useradministration.domain;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.JoinTable;
|
||||||
|
import javax.persistence.ManyToMany;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.persistence.UniqueConstraint;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||||
|
import org.mifosplatform.infrastructure.core.service.DateUtils;
|
||||||
import org.mifosplatform.infrastructure.security.domain.PlatformUser;
|
import org.mifosplatform.infrastructure.security.domain.PlatformUser;
|
||||||
import org.mifosplatform.infrastructure.security.exception.NoAuthorizationException;
|
import org.mifosplatform.infrastructure.security.exception.NoAuthorizationException;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformPasswordEncoder;
|
import org.mifosplatform.infrastructure.security.service.PlatformPasswordEncoder;
|
||||||
@@ -30,8 +41,6 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
|
|||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
import org.mifosplatform.infrastructure.core.service.DateUtils;
|
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "m_appuser", uniqueConstraints = @UniqueConstraint(columnNames = { "username" }, name = "username_org"))
|
@Table(name = "m_appuser", uniqueConstraints = @UniqueConstraint(columnNames = { "username" }, name = "username_org"))
|
||||||
@@ -201,16 +210,10 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String staffIdParamName = "staffId";
|
final String staffIdParamName = "staffId";
|
||||||
if(command.hasParameter(staffIdParamName)) {
|
if (command.hasParameter(staffIdParamName)
|
||||||
if(this.staff==null) {
|
&& (this.staff == null || command.isChangeInLongParameterNamed(staffIdParamName, this.staff.getId()))) {
|
||||||
final Long newValue = command.longValueOfParameterNamed(staffIdParamName);
|
final Long newValue = command.longValueOfParameterNamed(staffIdParamName);
|
||||||
actualChanges.put(staffIdParamName, newValue);
|
actualChanges.put(staffIdParamName, newValue);
|
||||||
} else {
|
|
||||||
if (command.isChangeInLongParameterNamed(staffIdParamName, this.staff.getId())) {
|
|
||||||
final Long newValue = command.longValueOfParameterNamed(staffIdParamName);
|
|
||||||
actualChanges.put(staffIdParamName, newValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String rolesParamName = "roles";
|
final String rolesParamName = "roles";
|
||||||
@@ -348,7 +351,9 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
|||||||
return this.staff;
|
return this.staff;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getLastTimePasswordUpdated(){ return this.lastTimePasswordUpdated; }
|
public Date getLastTimePasswordUpdated() {
|
||||||
|
return this.lastTimePasswordUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canNotApproveLoanInPast() {
|
public boolean canNotApproveLoanInPast() {
|
||||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "APPROVEINPAST_LOAN");
|
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "APPROVEINPAST_LOAN");
|
||||||
@@ -518,27 +523,22 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
|||||||
return staffDisplayName;
|
return staffDisplayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEncodedPassword(final JsonCommand command,final PlatformPasswordEncoder platformPasswordEncoder)
|
public String getEncodedPassword(final JsonCommand command, final PlatformPasswordEncoder platformPasswordEncoder) {
|
||||||
{
|
|
||||||
final String passwordParamName = "password";
|
final String passwordParamName = "password";
|
||||||
final String passwordEncodedParamName = "passwordEncoded";
|
final String passwordEncodedParamName = "passwordEncoded";
|
||||||
String passwordEncodedValue = null;
|
String passwordEncodedValue = null;
|
||||||
|
|
||||||
if (command.hasParameter(passwordParamName)) {
|
if (command.hasParameter(passwordParamName)) {
|
||||||
if (command.isChangeInPasswordParameterNamed(passwordParamName, this.password
|
if (command.isChangeInPasswordParameterNamed(passwordParamName, this.password, platformPasswordEncoder, getId())) {
|
||||||
, platformPasswordEncoder,getId())) {
|
|
||||||
|
|
||||||
passwordEncodedValue = command.passwordValueOfParameterNamed(passwordParamName, platformPasswordEncoder,
|
passwordEncodedValue = command.passwordValueOfParameterNamed(passwordParamName, platformPasswordEncoder, getId());
|
||||||
getId());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} else if (command.hasParameter(passwordEncodedParamName)) {
|
||||||
else if (command.hasParameter(passwordEncodedParamName)) {
|
|
||||||
if (command.isChangeInStringParameterNamed(passwordEncodedParamName, this.password)) {
|
if (command.isChangeInStringParameterNamed(passwordEncodedParamName, this.password)) {
|
||||||
|
|
||||||
passwordEncodedValue = command.stringValueOfParameterNamed(passwordEncodedParamName);
|
passwordEncodedValue = command.stringValueOfParameterNamed(passwordEncodedParamName);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-13
@@ -26,7 +26,6 @@ import org.mifosplatform.organisation.office.domain.OfficeRepository;
|
|||||||
import org.mifosplatform.organisation.office.exception.OfficeNotFoundException;
|
import org.mifosplatform.organisation.office.exception.OfficeNotFoundException;
|
||||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||||
import org.mifosplatform.organisation.staff.domain.StaffRepositoryWrapper;
|
import org.mifosplatform.organisation.staff.domain.StaffRepositoryWrapper;
|
||||||
import org.mifosplatform.organisation.staff.exception.StaffNotFoundException;
|
|
||||||
import org.mifosplatform.useradministration.api.AppUserApiConstant;
|
import org.mifosplatform.useradministration.api.AppUserApiConstant;
|
||||||
import org.mifosplatform.useradministration.domain.AppUser;
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
import org.mifosplatform.useradministration.domain.AppUserPreviousPassword;
|
import org.mifosplatform.useradministration.domain.AppUserPreviousPassword;
|
||||||
@@ -105,14 +104,13 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
|||||||
final String staffIdParamName = "staffId";
|
final String staffIdParamName = "staffId";
|
||||||
final Long staffId = command.longValueOfParameterNamed(staffIdParamName);
|
final Long staffId = command.longValueOfParameterNamed(staffIdParamName);
|
||||||
|
|
||||||
if(staffId != null) {
|
Staff linkedStaff = null;
|
||||||
final Staff linkedStaff = this.staffRepositoryWrapper.findOneWithNotFoundDetection(staffId);
|
if (staffId != null) {
|
||||||
if(linkedStaff.officeId() != userOffice.getId()) { throw new StaffNotFoundException(staffId); }
|
linkedStaff = this.staffRepositoryWrapper.findByOfficeWithNotFoundDetection(staffId, userOffice.getId());
|
||||||
appUser = AppUser.fromJson(userOffice,linkedStaff, allRoles, command);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
appUser = AppUser.fromJson(userOffice, null, allRoles, command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
appUser = AppUser.fromJson(userOffice, linkedStaff, allRoles, command);
|
||||||
|
|
||||||
final Boolean sendPasswordToEmail = command.booleanObjectValueOfParameterNamed("sendPasswordToEmail");
|
final Boolean sendPasswordToEmail = command.booleanObjectValueOfParameterNamed("sendPasswordToEmail");
|
||||||
this.userDomainService.create(appUser, sendPasswordToEmail);
|
this.userDomainService.create(appUser, sendPasswordToEmail);
|
||||||
|
|
||||||
@@ -166,11 +164,9 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
|||||||
|
|
||||||
if (changes.containsKey("staffId")) {
|
if (changes.containsKey("staffId")) {
|
||||||
final Long staffId = (Long) changes.get("staffId");
|
final Long staffId = (Long) changes.get("staffId");
|
||||||
final Staff linkedStaff;
|
Staff linkedStaff = null;
|
||||||
if(staffId!=null) {
|
if (staffId != null) {
|
||||||
linkedStaff = this.staffRepositoryWrapper.findOneWithNotFoundDetection(staffId);
|
linkedStaff = this.staffRepositoryWrapper.findByOfficeWithNotFoundDetection(staffId, userToUpdate.getOffice().getId());
|
||||||
} else {
|
|
||||||
linkedStaff = null;
|
|
||||||
}
|
}
|
||||||
userToUpdate.changeStaff(linkedStaff);
|
userToUpdate.changeStaff(linkedStaff);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -81,9 +81,9 @@ public final class UserDataValidator {
|
|||||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", element);
|
final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", element);
|
||||||
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
|
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
|
||||||
|
|
||||||
if(this.fromApiJsonHelper.parameterExists("staffId", element)) {
|
if (this.fromApiJsonHelper.parameterExists("staffId", element)) {
|
||||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed("staffId", element);
|
final Long staffId = this.fromApiJsonHelper.extractLongNamed("staffId", element);
|
||||||
baseDataValidator.reset().parameter("staffId").value(staffId).notNull().integerGreaterThanZero();
|
baseDataValidator.reset().parameter("staffId").value(staffId).notNull().integerGreaterThanZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] roles = this.fromApiJsonHelper.extractArrayNamed("roles", element);
|
final String[] roles = this.fromApiJsonHelper.extractArrayNamed("roles", element);
|
||||||
@@ -112,9 +112,9 @@ public final class UserDataValidator {
|
|||||||
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
|
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.fromApiJsonHelper.parameterExists("staffId", element)) {
|
if (this.fromApiJsonHelper.parameterExists("staffId", element)) {
|
||||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed("staffId", element);
|
final Long staffId = this.fromApiJsonHelper.extractLongNamed("staffId", element);
|
||||||
baseDataValidator.reset().parameter("staffId").value(staffId).integerGreaterThanZero();
|
baseDataValidator.reset().parameter("staffId").value(staffId).ignoreIfNull().integerGreaterThanZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.fromApiJsonHelper.parameterExists("username", element)) {
|
if (this.fromApiJsonHelper.parameterExists("username", element)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user