@Test public final void testEditButtonVisiblity() { try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); TargetDefaultCommand comm = new TargetDefaultCommand(); comm.setMode(TargetDefaultCommand.MODE_VIEW); comm.setTargetOid(4000L); Target aTarget = manager.load(comm.getTargetOid(), true); removeAllCurrentUserPrivileges(); assertFalse(authorityManager.hasPrivilege(aTarget,Privilege.MODIFY_TARGET)); BindException aError = new BindException(new DefaultSiteCommand(), null); ModelAndView mav = testInstance.showForm(request, response, comm, aError); assertFalse((Boolean)request.getSession().getAttribute(Constants.GBL_SESS_CAN_EDIT)); addCurrentUserPrivilege(Privilege.SCOPE_AGENCY, Privilege.MODIFY_TARGET); assertTrue(authorityManager.hasPrivilege(aTarget,Privilege.MODIFY_TARGET)); mav = testInstance.showForm(request, response, comm, aError); assertTrue((Boolean)request.getSession().getAttribute(Constants.GBL_SESS_CAN_EDIT)); removeCurrentUserPrivilege(Privilege.SCOPE_AGENCY, Privilege.MODIFY_TARGET); assertFalse(authorityManager.hasPrivilege(aTarget,Privilege.MODIFY_TARGET)); addCurrentUserPrivilege(Privilege.SCOPE_ALL, Privilege.MODIFY_TARGET); assertTrue(authorityManager.hasPrivilege(aTarget,Privilege.MODIFY_TARGET)); mav = testInstance.showForm(request, response, comm, aError); assertTrue((Boolean)request.getSession().getAttribute(Constants.GBL_SESS_CAN_EDIT)); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }
@Override protected ModelAndView showForm(HttpServletRequest req, HttpServletResponse res, Object comm, BindException bex) throws Exception { TargetDefaultCommand command = (TargetDefaultCommand) comm; if( command != null && command.getTargetOid() != null) { Target aTarget = targetManager.load(command.getTargetOid(), true); if(command.isCopyMode()) { Target copy = targetManager.copy(aTarget); aTarget = copy; } TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, command.isEditMode()); ctx.setCanEdit(false); if (!command.isEditMode()) { if (authorityManager.hasPrivilege(aTarget,Privilege.MODIFY_TARGET)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); } else { Target aTarget = businessObjectFactory.newTarget(); TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, true); bindEditorContext(req, ctx); } Tab general = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = general.getTabHandler().preProcessNextTab(this, general, req, res, null, bex); tmav.getTabStatus().setCurrentTab(general); return tmav; }
TabbedTargetController extends TabbedController { @Override protected ModelAndView showForm(HttpServletRequest req, HttpServletResponse res, Object comm, BindException bex) throws Exception { TargetDefaultCommand command = (TargetDefaultCommand) comm; if( command != null && command.getTargetOid() != null) { Target aTarget = targetManager.load(command.getTargetOid(), true); if(command.isCopyMode()) { Target copy = targetManager.copy(aTarget); aTarget = copy; } TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, command.isEditMode()); ctx.setCanEdit(false); if (!command.isEditMode()) { if (authorityManager.hasPrivilege(aTarget,Privilege.MODIFY_TARGET)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); } else { Target aTarget = businessObjectFactory.newTarget(); TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, true); bindEditorContext(req, ctx); } Tab general = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = general.getTabHandler().preProcessNextTab(this, general, req, res, null, bex); tmav.getTabStatus().setCurrentTab(general); return tmav; } }
TabbedTargetController extends TabbedController { @Override protected ModelAndView showForm(HttpServletRequest req, HttpServletResponse res, Object comm, BindException bex) throws Exception { TargetDefaultCommand command = (TargetDefaultCommand) comm; if( command != null && command.getTargetOid() != null) { Target aTarget = targetManager.load(command.getTargetOid(), true); if(command.isCopyMode()) { Target copy = targetManager.copy(aTarget); aTarget = copy; } TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, command.isEditMode()); ctx.setCanEdit(false); if (!command.isEditMode()) { if (authorityManager.hasPrivilege(aTarget,Privilege.MODIFY_TARGET)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); } else { Target aTarget = businessObjectFactory.newTarget(); TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, true); bindEditorContext(req, ctx); } Tab general = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = general.getTabHandler().preProcessNextTab(this, general, req, res, null, bex); tmav.getTabStatus().setCurrentTab(general); return tmav; }  }
TabbedTargetController extends TabbedController { @Override protected ModelAndView showForm(HttpServletRequest req, HttpServletResponse res, Object comm, BindException bex) throws Exception { TargetDefaultCommand command = (TargetDefaultCommand) comm; if( command != null && command.getTargetOid() != null) { Target aTarget = targetManager.load(command.getTargetOid(), true); if(command.isCopyMode()) { Target copy = targetManager.copy(aTarget); aTarget = copy; } TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, command.isEditMode()); ctx.setCanEdit(false); if (!command.isEditMode()) { if (authorityManager.hasPrivilege(aTarget,Privilege.MODIFY_TARGET)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); } else { Target aTarget = businessObjectFactory.newTarget(); TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, true); bindEditorContext(req, ctx); } Tab general = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = general.getTabHandler().preProcessNextTab(this, general, req, res, null, bex); tmav.getTabStatus().setCurrentTab(general); return tmav; }  void bindEditorContext(HttpServletRequest req, TargetEditorContext context); void unbindEditorContext(HttpServletRequest req); TargetEditorContext getEditorContext(HttpServletRequest req); void setTargetManager(TargetManager targetManager); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setSearchController(TargetSearchController searchController); void setMessageSource(MessageSource messageSource); void setAuthorityManager(AuthorityManager authorityManager); }
TabbedTargetController extends TabbedController { @Override protected ModelAndView showForm(HttpServletRequest req, HttpServletResponse res, Object comm, BindException bex) throws Exception { TargetDefaultCommand command = (TargetDefaultCommand) comm; if( command != null && command.getTargetOid() != null) { Target aTarget = targetManager.load(command.getTargetOid(), true); if(command.isCopyMode()) { Target copy = targetManager.copy(aTarget); aTarget = copy; } TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, command.isEditMode()); ctx.setCanEdit(false); if (!command.isEditMode()) { if (authorityManager.hasPrivilege(aTarget,Privilege.MODIFY_TARGET)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); } else { Target aTarget = businessObjectFactory.newTarget(); TargetEditorContext ctx = new TargetEditorContext(targetManager, aTarget, true); bindEditorContext(req, ctx); } Tab general = getTabConfig().getTabByID("GENERAL"); TabbedModelAndView tmav = general.getTabHandler().preProcessNextTab(this, general, req, res, null, bex); tmav.getTabStatus().setCurrentTab(general); return tmav; }  void bindEditorContext(HttpServletRequest req, TargetEditorContext context); void unbindEditorContext(HttpServletRequest req); TargetEditorContext getEditorContext(HttpServletRequest req); void setTargetManager(TargetManager targetManager); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setSearchController(TargetSearchController searchController); void setMessageSource(MessageSource messageSource); void setAuthorityManager(AuthorityManager authorityManager); static final String EDITOR_CONTEXT; }