added roles in the api call for users
This commit is contained in:
@@ -17909,7 +17909,14 @@ GET https://DomainName/api/v1/users
|
||||
"officeName": "Head Office",
|
||||
"firstname": "App",
|
||||
"lastname": "Administrator",
|
||||
"email": "demomfi@mifos.org"
|
||||
"email": "demomfi@mifos.org",
|
||||
"selectedRoles": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Super user",
|
||||
"description": "This role provides all application permissions."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
</code>
|
||||
|
||||
Regular → Executable
+10
-18
@@ -5,23 +5,6 @@
|
||||
*/
|
||||
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.service.CommandWrapperBuilder;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
@@ -38,6 +21,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
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")
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
@@ -79,7 +71,7 @@ public class UsersApiResource {
|
||||
|
||||
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
|
||||
|
||||
final Collection<AppUserData> users = this.readPlatformService.retrieveAllUsers();
|
||||
final Collection<AppUserData> users = this.readPlatformService.retrieveAllUsersWithRoles();
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, users, this.RESPONSE_DATA_PARAMETERS);
|
||||
|
||||
Regular → Executable
+4
-2
@@ -5,10 +5,10 @@
|
||||
*/
|
||||
package org.mifosplatform.useradministration.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface AppUserReadPlatformService {
|
||||
|
||||
Collection<AppUserData> retrieveAllUsers();
|
||||
@@ -18,4 +18,6 @@ public interface AppUserReadPlatformService {
|
||||
AppUserData retrieveNewUserDetails();
|
||||
|
||||
AppUserData retrieveUser(Long userId);
|
||||
|
||||
Collection<AppUserData> retrieveAllUsersWithRoles();
|
||||
}
|
||||
Regular → Executable
+20
-6
@@ -5,12 +5,6 @@
|
||||
*/
|
||||
package org.mifosplatform.useradministration.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
@@ -28,6 +22,10 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformService {
|
||||
|
||||
@@ -83,6 +81,22 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
return AppUserData.template(offices, availableRoles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AppUserData> retrieveAllUsersWithRoles() {
|
||||
this.context.authenticatedUser();
|
||||
final Collection<AppUser> users = this.appUserRepository.findAll();
|
||||
Collection<AppUserData> appUserData = new HashSet<AppUserData>();
|
||||
for(final AppUser user : users){
|
||||
final Set<RoleData> selectedUserRoles = new HashSet<RoleData>();
|
||||
for(final Role role : user.getRoles()){
|
||||
selectedUserRoles.add(role.toData()) ;
|
||||
}
|
||||
appUserData.add(AppUserData.instance(user.getId(), user.getUsername(), user.getEmail(), user.getOffice().getId(),
|
||||
user.getOffice().getName(), user.getFirstname(), user.getLastname(),null,selectedUserRoles)) ;
|
||||
}
|
||||
return appUserData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserData retrieveUser(final Long userId) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user