ProfileListController extends AbstractCommandController { protected ModelAndView getView(ProfileListCommand command) { ModelAndView mav = new ModelAndView("profile-list"); List<Agency> agencies = new ArrayList<Agency>(); List<ProfileDTO> profiles = new ArrayList<ProfileDTO>(); if (authorityManager.hasAtLeastOnePrivilege(new String[]{Privilege.VIEW_PROFILES, Privilege.MANAGE_PROFILES})) { if (authorityManager.hasPrivilege(Privilege.VIEW_PROFILES, Privilege.SCOPE_ALL) || authorityManager.hasPrivilege(Privilege.MANAGE_PROFILES, Privilege.SCOPE_ALL)) { agencies = agencyUserManager.getAgencies(); profiles = profileManager.getDTOs(command.isShowInactive(), command.getHarvesterType()); } else { User loggedInUser = AuthUtil.getRemoteUserObject(); Agency usersAgency = loggedInUser.getAgency(); agencies = new ArrayList<Agency>(); agencies.add(usersAgency); profiles = profileManager.getAgencyDTOs(usersAgency, command.isShowInactive(), command.getHarvesterType()); } } mav.addObject(Constants.GBL_CMD_DATA, command); mav.addObject("profiles", profiles); mav.addObject("agencies", agencies); mav.addObject("usersAgency", AuthUtil.getRemoteUserObject().getAgency()); mav.addObject("types", HarvesterType.values()); mav.addObject("defaultType", HarvesterType.DEFAULT); return mav; } ProfileListController(); void setProfileManager(ProfileManager profileManager); void setAgencyUserManager(AgencyUserManager agencyUserManager); void setAuthorityManager(AuthorityManager authorityManager); static final String SESSION_KEY_SHOW_INACTIVE; static final String SESSION_AGENCY_FILTER; static final String SESSION_HARVESTER_TYPE_FILTER; }
@Test public final void testGetView() { this.testSetAgencyUserManager(); this.testSetAuthorityManager(); this.testSetProfileManager(); performTestGetView(-1, "", false); performTestGetView(-1, "", true); performTestGetView(Privilege.SCOPE_AGENCY, Privilege.VIEW_PROFILES, false); performTestGetView(Privilege.SCOPE_AGENCY, Privilege.VIEW_PROFILES, true); performTestGetView(Privilege.SCOPE_AGENCY, Privilege.MANAGE_PROFILES, false); performTestGetView(Privilege.SCOPE_AGENCY, Privilege.MANAGE_PROFILES, true); performTestGetView(Privilege.SCOPE_ALL, Privilege.VIEW_PROFILES, false); performTestGetView(Privilege.SCOPE_ALL, Privilege.VIEW_PROFILES, true); performTestGetView(Privilege.SCOPE_ALL, Privilege.MANAGE_PROFILES, false); performTestGetView(Privilege.SCOPE_ALL, Privilege.MANAGE_PROFILES, true); }