MIFOSX-982 Issue Fix
Updated Fix
This commit is contained in:
committed by
Vishwas Babu A J
parent
67ec9163bd
commit
cf4bf988a4
+1
-1
@@ -42,7 +42,7 @@ public class UsersApiResource {
|
||||
* {@link AppUserData}.
|
||||
*/
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "username",
|
||||
"firstname", "lastname", "email", "allowedOffices", "availableRoles", "selectedRoles"));
|
||||
"firstname", "lastname", "email", "allowedOffices", "availableRoles", "selectedRoles", "staffId"));
|
||||
|
||||
private final String resourceNameForPermissions = "USER";
|
||||
|
||||
|
||||
+9
-6
@@ -6,6 +6,7 @@
|
||||
package org.mifosplatform.useradministration.data;
|
||||
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -26,29 +27,30 @@ public class AppUserData {
|
||||
private final Collection<OfficeData> allowedOffices;
|
||||
private final Collection<RoleData> availableRoles;
|
||||
private final Collection<RoleData> selectedRoles;
|
||||
private final StaffData staff;
|
||||
|
||||
public static AppUserData template(final AppUserData user, final 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);
|
||||
user.availableRoles, user.selectedRoles, officesForDropdown, user.staff);
|
||||
}
|
||||
|
||||
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);
|
||||
return new AppUserData(null, null, null, null, null, null, null, availableRoles, null, offices, null);
|
||||
}
|
||||
|
||||
public static AppUserData dropdown(final Long id, final String username) {
|
||||
return new AppUserData(id, username, null, null, null, null, null, null, null, null);
|
||||
return new AppUserData(id, username, null, 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);
|
||||
final Collection<RoleData> selectedRoles, final StaffData staff) {
|
||||
return new AppUserData(id, username, email, officeId, officeName, firstname, lastname, availableRoles, selectedRoles, null, staff);
|
||||
}
|
||||
|
||||
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) {
|
||||
final Collection<RoleData> selectedRoles, final Collection<OfficeData> allowedOffices, final StaffData staff) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.officeId = officeId;
|
||||
@@ -59,6 +61,7 @@ public class AppUserData {
|
||||
this.allowedOffices = allowedOffices;
|
||||
this.availableRoles = availableRoles;
|
||||
this.selectedRoles = selectedRoles;
|
||||
this.staff = staff;
|
||||
}
|
||||
|
||||
public boolean hasIdentifyOf(final Long createdById) {
|
||||
|
||||
+26
-4
@@ -88,7 +88,7 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date lastTimePasswordUpdated;
|
||||
|
||||
public static AppUser fromJson(final Office userOffice, final Set<Role> allRoles, final JsonCommand command) {
|
||||
public static AppUser fromJson(final Office userOffice, final Staff linkedStaff, final Set<Role> allRoles, final JsonCommand command) {
|
||||
|
||||
final String username = command.stringValueOfParameterNamed("username");
|
||||
String password = command.stringValueOfParameterNamed("password");
|
||||
@@ -113,7 +113,7 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
final String firstname = command.stringValueOfParameterNamed("firstname");
|
||||
final String lastname = command.stringValueOfParameterNamed("lastname");
|
||||
|
||||
return new AppUser(userOffice, user, allRoles, email, firstname, lastname);
|
||||
return new AppUser(userOffice, user, allRoles, email, firstname, lastname, linkedStaff);
|
||||
}
|
||||
|
||||
protected AppUser() {
|
||||
@@ -123,7 +123,7 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
}
|
||||
|
||||
public AppUser(final Office office, final User user, final Set<Role> roles, final String email, final String firstname,
|
||||
final String lastname) {
|
||||
final String lastname, final Staff staff) {
|
||||
this.office = office;
|
||||
this.email = email.trim();
|
||||
this.username = user.getUsername().trim();
|
||||
@@ -136,7 +136,8 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
this.enabled = user.isEnabled();
|
||||
this.roles = roles;
|
||||
this.firstTimeLoginRemaining = true;
|
||||
this.lastTimePasswordUpdated = DateUtils.getDateOfTenant();
|
||||
this.lastTimePasswordUpdated = DateUtils.getDateOfTenant();
|
||||
this.staff = staff;
|
||||
}
|
||||
|
||||
public EnumOptionData organisationalRoleData() {
|
||||
@@ -157,6 +158,10 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
public void changeOffice(final Office differentOffice) {
|
||||
this.office = differentOffice;
|
||||
}
|
||||
|
||||
public void changeStaff(final Staff differentStaff) {
|
||||
this.staff = differentStaff;
|
||||
}
|
||||
|
||||
public void updateRoles(final Set<Role> allRoles) {
|
||||
if (!allRoles.isEmpty()) {
|
||||
@@ -195,6 +200,19 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
actualChanges.put(officeIdParamName, newValue);
|
||||
}
|
||||
|
||||
final String staffIdParamName = "staffId";
|
||||
if(command.hasParameter(staffIdParamName)) {
|
||||
if(this.staff==null) {
|
||||
final Long newValue = command.longValueOfParameterNamed(staffIdParamName);
|
||||
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";
|
||||
if (command.isChangeInArrayParameterNamed(rolesParamName, getRolesAsIdStringArray())) {
|
||||
final String[] newValue = command.arrayValueOfParameterNamed(rolesParamName);
|
||||
@@ -325,6 +343,10 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
public Office getOffice() {
|
||||
return this.office;
|
||||
}
|
||||
|
||||
public Staff getStaff() {
|
||||
return this.staff;
|
||||
}
|
||||
|
||||
public Date getLastTimePasswordUpdated(){ return this.lastTimePasswordUpdated; }
|
||||
|
||||
|
||||
+27
-9
@@ -16,6 +16,8 @@ import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
import org.mifosplatform.organisation.staff.service.StaffReadPlatformService;
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
import org.mifosplatform.useradministration.data.RoleData;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
@@ -36,16 +38,18 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
private final OfficeReadPlatformService officeReadPlatformService;
|
||||
private final RoleReadPlatformService roleReadPlatformService;
|
||||
private final AppUserRepository appUserRepository;
|
||||
|
||||
private final StaffReadPlatformService staffReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
public AppUserReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource,
|
||||
final OfficeReadPlatformService officeReadPlatformService, final RoleReadPlatformService roleReadPlatformService,
|
||||
final AppUserRepository appUserRepository) {
|
||||
final AppUserRepository appUserRepository, final StaffReadPlatformService staffReadPlatformService) {
|
||||
this.context = context;
|
||||
this.officeReadPlatformService = officeReadPlatformService;
|
||||
this.roleReadPlatformService = roleReadPlatformService;
|
||||
this.appUserRepository = appUserRepository;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.staffReadPlatformService = staffReadPlatformService;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -63,7 +67,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
final String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
final String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
final AppUserMapper mapper = new AppUserMapper(this.roleReadPlatformService);
|
||||
final AppUserMapper mapper = new AppUserMapper(this.roleReadPlatformService, this.staffReadPlatformService);
|
||||
final String sql = "select " + mapper.schema();
|
||||
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] { hierarchySearchString });
|
||||
@@ -108,16 +112,25 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
|
||||
availableRoles.removeAll(selectedUserRoles);
|
||||
|
||||
final StaffData linkedStaff;
|
||||
if(user.getStaff()!=null) {
|
||||
linkedStaff = this.staffReadPlatformService.retrieveStaff(user.getStaffId());
|
||||
} else {
|
||||
linkedStaff = null;
|
||||
}
|
||||
|
||||
return AppUserData.instance(user.getId(), user.getUsername(), user.getEmail(), user.getOffice().getId(),
|
||||
user.getOffice().getName(), user.getFirstname(), user.getLastname(), availableRoles, selectedUserRoles);
|
||||
user.getOffice().getName(), user.getFirstname(), user.getLastname(), availableRoles, selectedUserRoles, linkedStaff);
|
||||
}
|
||||
|
||||
private static final class AppUserMapper implements RowMapper<AppUserData> {
|
||||
|
||||
private final RoleReadPlatformService roleReadPlatformService;
|
||||
private final StaffReadPlatformService staffReadPlatformService;
|
||||
|
||||
public AppUserMapper(final RoleReadPlatformService roleReadPlatformService) {
|
||||
public AppUserMapper(final RoleReadPlatformService roleReadPlatformService, final StaffReadPlatformService staffReadPlatformService) {
|
||||
this.roleReadPlatformService = roleReadPlatformService;
|
||||
this.staffReadPlatformService = staffReadPlatformService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,15 +143,20 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
final String email = rs.getString("email");
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
|
||||
final Long staffId = JdbcSupport.getLong(rs, "staffId");
|
||||
final Collection<RoleData> selectedRoles = this.roleReadPlatformService.retrieveAppUserRoles(id);
|
||||
|
||||
return AppUserData.instance(id, username, email, officeId, officeName, firstname, lastname, null, selectedRoles);
|
||||
}
|
||||
final StaffData linkedStaff;
|
||||
if(staffId!=null) {
|
||||
linkedStaff = this.staffReadPlatformService.retrieveStaff(staffId);
|
||||
} else {
|
||||
linkedStaff = null;
|
||||
}
|
||||
return AppUserData.instance(id, username, email, officeId, officeName, firstname, lastname, null, selectedRoles, linkedStaff); }
|
||||
|
||||
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 "
|
||||
+ " u.office_id as officeId, o.name as officeName, u.staff_id as staffId 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";
|
||||
}
|
||||
|
||||
|
||||
+31
-3
@@ -24,6 +24,9 @@ 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.organisation.staff.domain.Staff;
|
||||
import org.mifosplatform.organisation.staff.domain.StaffRepositoryWrapper;
|
||||
import org.mifosplatform.organisation.staff.exception.StaffNotFoundException;
|
||||
import org.mifosplatform.useradministration.api.AppUserApiConstant;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.mifosplatform.useradministration.domain.AppUserPreviousPassword;
|
||||
@@ -60,12 +63,13 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
private final RoleRepository roleRepository;
|
||||
private final UserDataValidator fromApiJsonDeserializer;
|
||||
private final AppUserPreviousPasswordRepository appUserPreviewPasswordRepository;
|
||||
|
||||
private final StaffRepositoryWrapper staffRepositoryWrapper;
|
||||
|
||||
@Autowired
|
||||
public AppUserWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final AppUserRepository appUserRepository,
|
||||
final UserDomainService userDomainService, final OfficeRepository officeRepository, final RoleRepository roleRepository,
|
||||
final PlatformPasswordEncoder platformPasswordEncoder, final UserDataValidator fromApiJsonDeserializer,
|
||||
final AppUserPreviousPasswordRepository appUserPreviewPasswordRepository) {
|
||||
final AppUserPreviousPasswordRepository appUserPreviewPasswordRepository, final StaffRepositoryWrapper staffRepositoryWrapper) {
|
||||
this.context = context;
|
||||
this.appUserRepository = appUserRepository;
|
||||
this.userDomainService = userDomainService;
|
||||
@@ -74,6 +78,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
this.platformPasswordEncoder = platformPasswordEncoder;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.appUserPreviewPasswordRepository = appUserPreviewPasswordRepository;
|
||||
this.staffRepositoryWrapper = staffRepositoryWrapper;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -95,7 +100,19 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
final String[] roles = command.arrayValueOfParameterNamed("roles");
|
||||
final Set<Role> allRoles = assembleSetOfRoles(roles);
|
||||
|
||||
final AppUser appUser = AppUser.fromJson(userOffice, allRoles, command);
|
||||
AppUser appUser;
|
||||
|
||||
final String staffIdParamName = "staffId";
|
||||
final Long staffId = command.longValueOfParameterNamed(staffIdParamName);
|
||||
|
||||
if(staffId != null) {
|
||||
final Staff linkedStaff = this.staffRepositoryWrapper.findOneWithNotFoundDetection(staffId);
|
||||
if(linkedStaff.officeId() != userOffice.getId()) { throw new StaffNotFoundException(staffId); }
|
||||
appUser = AppUser.fromJson(userOffice,linkedStaff, allRoles, command);
|
||||
|
||||
} else {
|
||||
appUser = AppUser.fromJson(userOffice, null, allRoles, command);
|
||||
}
|
||||
final Boolean sendPasswordToEmail = command.booleanObjectValueOfParameterNamed("sendPasswordToEmail");
|
||||
this.userDomainService.create(appUser, sendPasswordToEmail);
|
||||
|
||||
@@ -146,6 +163,17 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit
|
||||
|
||||
userToUpdate.changeOffice(office);
|
||||
}
|
||||
|
||||
if (changes.containsKey("staffId")) {
|
||||
final Long staffId = (Long) changes.get("staffId");
|
||||
final Staff linkedStaff;
|
||||
if(staffId!=null) {
|
||||
linkedStaff = this.staffRepositoryWrapper.findOneWithNotFoundDetection(staffId);
|
||||
} else {
|
||||
linkedStaff = null;
|
||||
}
|
||||
userToUpdate.changeStaff(linkedStaff);
|
||||
}
|
||||
|
||||
if (changes.containsKey("roles")) {
|
||||
final String[] roleIds = (String[]) changes.get("roles");
|
||||
|
||||
+11
-1
@@ -32,7 +32,7 @@ public final class UserDataValidator {
|
||||
* 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", "sendPasswordToEmail"));
|
||||
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles", "sendPasswordToEmail", "staffId"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@@ -81,6 +81,11 @@ public final class UserDataValidator {
|
||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", element);
|
||||
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
|
||||
|
||||
if(this.fromApiJsonHelper.parameterExists("staffId", element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed("staffId", element);
|
||||
baseDataValidator.reset().parameter("staffId").value(staffId).notNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
final String[] roles = this.fromApiJsonHelper.extractArrayNamed("roles", element);
|
||||
baseDataValidator.reset().parameter("roles").value(roles).arrayNotEmpty();
|
||||
|
||||
@@ -106,6 +111,11 @@ public final class UserDataValidator {
|
||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", element);
|
||||
baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
if(this.fromApiJsonHelper.parameterExists("staffId", element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed("staffId", element);
|
||||
baseDataValidator.reset().parameter("staffId").value(staffId).integerGreaterThanZero();
|
||||
}
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists("username", element)) {
|
||||
final String username = this.fromApiJsonHelper.extractStringNamed("username", element);
|
||||
|
||||
Reference in New Issue
Block a user