Commit 8e6dc07b authored by vikram singh's avatar vikram singh

added security in account,project,domain page

parent 547d800d
...@@ -81,9 +81,21 @@ public class AccountController { ...@@ -81,9 +81,21 @@ public class AccountController {
} }
@RequestMapping(value = "/accounts", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) // @RequestMapping(value = "/accounts", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccounts(HttpServletRequest request) throws MyTeamException { // public ResponseEntity<?> getAccounts(HttpServletRequest request) throws MyTeamException {
List<Map<Object, Object>> accountsList = accountService.getAccountsList(); // List<Map<Object, Object>> accountsList = accountService.getAccountsList();
// log.info("The accounts list::" + accountsList);
//
// ResponseDetails getRespDetails = new ResponseDetails(new Date(), AccountStatus.GET_ACCOUNTS.getCode(), AccountStatus.GET_ACCOUNTS.getMessage(),
// "Accounts list", accountsList, request.getRequestURI(), "details", null);
//
// return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
//
// }
@RequestMapping(value = "/accountsByLoginId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccounts(@RequestParam("loginId") String loginId ,HttpServletRequest request) throws MyTeamException {
List<Map<Object, Object>> accountsList = accountService.getAccountsListByLoginId(loginId);
log.info("The accounts list::" + accountsList); log.info("The accounts list::" + accountsList);
ResponseDetails getRespDetails = new ResponseDetails(new Date(), AccountStatus.GET_ACCOUNTS.getCode(), AccountStatus.GET_ACCOUNTS.getMessage(), ResponseDetails getRespDetails = new ResponseDetails(new Date(), AccountStatus.GET_ACCOUNTS.getCode(), AccountStatus.GET_ACCOUNTS.getMessage(),
......
...@@ -81,11 +81,20 @@ public class DomainController { ...@@ -81,11 +81,20 @@ public class DomainController {
} }
@RequestMapping(value = "/domains", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) // @RequestMapping(value = "/domains", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getDomains(HttpServletRequest request) throws MyTeamException { // public ResponseEntity<?> getDomains(HttpServletRequest request) throws MyTeamException {
//
// ResponseDetails getRespDetails = new ResponseDetails(new Date(), DomainStatus.GET_DOMIAINS.getCode(), DomainStatus.GET_DOMIAINS.getMessage(),
// "Domains list", domainService.getDomainsList(), request.getRequestURI(), "details", null);
//
// return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
// }
@RequestMapping(value = "/domainsByLoginId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getDomains(@RequestParam("loginId") String loginId ,HttpServletRequest request) throws MyTeamException {
ResponseDetails getRespDetails = new ResponseDetails(new Date(), DomainStatus.GET_DOMIAINS.getCode(), DomainStatus.GET_DOMIAINS.getMessage(), ResponseDetails getRespDetails = new ResponseDetails(new Date(), DomainStatus.GET_DOMIAINS.getCode(), DomainStatus.GET_DOMIAINS.getMessage(),
"Domains list", domainService.getDomainsList(), request.getRequestURI(), "details", null); "Domains list", domainService.getDomainsListByLoginId(loginId), request.getRequestURI(), "details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK); return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
} }
......
...@@ -31,4 +31,6 @@ public interface IAccountService { ...@@ -31,4 +31,6 @@ public interface IAccountService {
public Account getAccountByName(String name); public Account getAccountByName(String name);
List<Map<Object, Object>> getAccountsListByLoginId(String loginId);
} }
...@@ -35,5 +35,7 @@ public interface IDomainService { ...@@ -35,5 +35,7 @@ public interface IDomainService {
Domain getDomainById(String domainId); Domain getDomainById(String domainId);
List<DomainVO> getDomainsListByLoginId(String loginId);
} }
...@@ -6,9 +6,12 @@ import com.nisum.myteam.model.dao.Employee; ...@@ -6,9 +6,12 @@ import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.repository.AccountRepo; import com.nisum.myteam.repository.AccountRepo;
import com.nisum.myteam.service.IAccountService; import com.nisum.myteam.service.IAccountService;
import com.nisum.myteam.service.IEmployeeRoleService; import com.nisum.myteam.service.IEmployeeRoleService;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IRoleService; import com.nisum.myteam.service.IRoleService;
import com.nisum.myteam.utils.CommomUtil; import com.nisum.myteam.utils.CommomUtil;
import com.nisum.myteam.utils.MyTeamUtils; import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.utils.constants.ApplicationRole;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.FindAndModifyOptions; import org.springframework.data.mongodb.core.FindAndModifyOptions;
...@@ -32,6 +35,9 @@ public class AccountService implements IAccountService { ...@@ -32,6 +35,9 @@ public class AccountService implements IAccountService {
@Autowired @Autowired
private IRoleService roleService; private IRoleService roleService;
@Autowired
private IEmployeeService employeeService;
@Autowired @Autowired
private IEmployeeRoleService empRoleService; private IEmployeeRoleService empRoleService;
...@@ -272,6 +278,27 @@ public class AccountService implements IAccountService { ...@@ -272,6 +278,27 @@ public class AccountService implements IAccountService {
} }
} }
@Override
public List<Map<Object, Object>> getAccountsListByLoginId(String loginId) {
boolean isAdmin=employeeService.getEmployeeById(loginId).getRole().equals(ApplicationRole.ADMIN.getRoleName());
// List<Account> accounts
List<Map<Object, Object>> updatedAccountList = new ArrayList<>();
List<Map<String, String>> updatedEmployeeList = null;
for (Account account : accountRepo.findAll()) {
updatedEmployeeList = new ArrayList<>();
for (Employee employee : getEmployeeDetails(account)) {
updatedEmployeeList.add(getEmployeeDetails(employee));
}
if(updatedEmployeeList.stream().map(e->e.get(MyTeamUtils.EMPLOYEE_ID)).anyMatch(empId->empId.equals(loginId))||isAdmin)
updatedAccountList.add(getAccuntDetails(account, updatedEmployeeList));
}
return updatedAccountList;
}
......
...@@ -9,9 +9,12 @@ import com.nisum.myteam.repository.DomainRepo; ...@@ -9,9 +9,12 @@ import com.nisum.myteam.repository.DomainRepo;
import com.nisum.myteam.service.IAccountService; import com.nisum.myteam.service.IAccountService;
import com.nisum.myteam.service.IDomainService; import com.nisum.myteam.service.IDomainService;
import com.nisum.myteam.service.IEmployeeRoleService; import com.nisum.myteam.service.IEmployeeRoleService;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IRoleService; import com.nisum.myteam.service.IRoleService;
import com.nisum.myteam.utils.CommomUtil; import com.nisum.myteam.utils.CommomUtil;
import com.nisum.myteam.utils.MyTeamUtils; import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.utils.constants.ApplicationRole;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
...@@ -39,6 +42,8 @@ public class DomainService implements IDomainService { ...@@ -39,6 +42,8 @@ public class DomainService implements IDomainService {
@Autowired @Autowired
private IRoleService roleService; private IRoleService roleService;
@Autowired
private IEmployeeService employeeService;
@Autowired @Autowired
private IEmployeeRoleService empRoleService; private IEmployeeRoleService empRoleService;
...@@ -259,6 +264,27 @@ public class DomainService implements IDomainService { ...@@ -259,6 +264,27 @@ public class DomainService implements IDomainService {
} }
return accIdsSet; return accIdsSet;
} }
@Override
public List<DomainVO> getDomainsListByLoginId(String loginId) {
List<DomainVO> domainVOS = new ArrayList<>();
boolean isAdmin=employeeService.getEmployeeById(loginId).getRole().equals(ApplicationRole.ADMIN.getRoleName());
domainRepo.findAll().stream().filter(e-> e.getDeliveryManagers().stream().anyMatch(empId->empId.equals(loginId))||isAdmin).forEach(domainPersisted->
{
DomainVO domainVO = new DomainVO();
domainVO.setId(domainPersisted.getId().toString());
domainVO.setAccountId(domainPersisted.getAccountId());
domainVO.setAccountName(accountService.getAccountById(domainPersisted.getAccountId()).getAccountName());
domainVO.setDomainId(domainPersisted.getDomainId());
domainVO.setDomainName(domainPersisted.getDomainName());
domainVO.setStatus(domainPersisted.getStatus());
domainVO.setDeliveryManagers(prepareEmployeeList(domainPersisted));
domainVOS.add(domainVO);
});
return domainVOS;
}
......
...@@ -339,10 +339,22 @@ public class ProjectService implements IProjectService { ...@@ -339,10 +339,22 @@ public class ProjectService implements IProjectService {
List<Project> projectList = projectRepo.findByAccountIdIn(accountIdSet); List<Project> projectList = projectRepo.findByAccountIdIn(accountIdSet);
for (Project proj : projectList) { for (Project proj : projectList) {
addToProjectList(projectsList, proj); if(proj.getDeliveryLeadIds().stream().anyMatch(e->e.equals(empId)))
addToProjectList(projectsList, proj);
} }
return projectsList; return projectsList;
} }
// @Override
// public List<HashMap<Object, Object>> getRoleBasedProjects(String empId) throws MyTeamException {
// List<HashMap<Object, Object>> projectsList = new ArrayList<HashMap<Object, Object>>();
// Set<String> accountIdSet = domainService.accountsAssignedToDeliveryLead(empId);
// List<Project> projectList = projectRepo.findByAccountIdIn(accountIdSet);
//
// for (Project proj : projectList) {
// addToProjectList(projectsList, proj);
// }
// return projectsList;
// }
@Override @Override
public List<HashMap<Object, Object>> getProjectsInsteadOfRole() throws MyTeamException { public List<HashMap<Object, Object>> getProjectsInsteadOfRole() throws MyTeamException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment