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 {
}
@RequestMapping(value = "/accounts", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccounts(HttpServletRequest request) throws MyTeamException {
List<Map<Object, Object>> accountsList = accountService.getAccountsList();
// @RequestMapping(value = "/accounts", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
// public ResponseEntity<?> getAccounts(HttpServletRequest request) throws MyTeamException {
// 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);
ResponseDetails getRespDetails = new ResponseDetails(new Date(), AccountStatus.GET_ACCOUNTS.getCode(), AccountStatus.GET_ACCOUNTS.getMessage(),
......
......@@ -81,11 +81,20 @@ public class DomainController {
}
@RequestMapping(value = "/domains", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getDomains(HttpServletRequest request) throws MyTeamException {
// @RequestMapping(value = "/domains", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
// 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(),
"Domains list", domainService.getDomainsList(), request.getRequestURI(), "details", null);
"Domains list", domainService.getDomainsListByLoginId(loginId), request.getRequestURI(), "details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
......
......@@ -31,4 +31,6 @@ public interface IAccountService {
public Account getAccountByName(String name);
List<Map<Object, Object>> getAccountsListByLoginId(String loginId);
}
......@@ -35,5 +35,7 @@ public interface IDomainService {
Domain getDomainById(String domainId);
List<DomainVO> getDomainsListByLoginId(String loginId);
}
......@@ -6,9 +6,12 @@ import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.repository.AccountRepo;
import com.nisum.myteam.service.IAccountService;
import com.nisum.myteam.service.IEmployeeRoleService;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IRoleService;
import com.nisum.myteam.utils.CommomUtil;
import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.utils.constants.ApplicationRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.FindAndModifyOptions;
......@@ -33,6 +36,9 @@ public class AccountService implements IAccountService {
@Autowired
private IRoleService roleService;
@Autowired
private IEmployeeService employeeService;
@Autowired
private IEmployeeRoleService empRoleService;
......@@ -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;
import com.nisum.myteam.service.IAccountService;
import com.nisum.myteam.service.IDomainService;
import com.nisum.myteam.service.IEmployeeRoleService;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IRoleService;
import com.nisum.myteam.utils.CommomUtil;
import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.utils.constants.ApplicationRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
......@@ -39,6 +42,8 @@ public class DomainService implements IDomainService {
@Autowired
private IRoleService roleService;
@Autowired
private IEmployeeService employeeService;
@Autowired
private IEmployeeRoleService empRoleService;
......@@ -260,6 +265,27 @@ public class DomainService implements IDomainService {
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 {
List<Project> projectList = projectRepo.findByAccountIdIn(accountIdSet);
for (Project proj : projectList) {
if(proj.getDeliveryLeadIds().stream().anyMatch(e->e.equals(empId)))
addToProjectList(projectsList, proj);
}
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
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