use of org.mifos.security.util.ActivityContext in project head by mifos.
the class BirtReportsUploadActionStrutsTest method setupReportEditPermission.
private void setupReportEditPermission(boolean allowReportEdit) throws Exception {
UserContext userContext = TestUtils.makeUser();
request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
request.getSession(false).setAttribute(Constants.ACTIVITYCONTEXT, ac);
RoleBO role = legacyRolesPermissionsDao.getRole(userContext.getRoles().iterator().next());
List<ActivityEntity> roleActivities = new ArrayList<ActivityEntity>(role.getActivities());
List<ActivityEntity> updatedRoleActivities = new ArrayList<ActivityEntity>();
for (ActivityEntity ae : roleActivities) {
if (ae.getId() != SecurityConstants.EDIT_REPORT_INFORMATION || allowReportEdit) {
updatedRoleActivities.add(ae);
}
}
try {
StaticHibernateUtil.startTransaction();
role.update(userContext.getId(), "test", updatedRoleActivities);
legacyRolesPermissionsDao.save(role);
StaticHibernateUtil.flushSession();
for (ActivityEntity ae : legacyRolesPermissionsDao.getActivities()) {
StaticHibernateUtil.getSessionTL().refresh(ae);
}
StaticHibernateUtil.commitTransaction();
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
StaticHibernateUtil.closeSession();
}
setRequestPathInfo("/birtReportsUploadAction.do");
addRequestParameter("method", "edit");
addRequestParameter("reportId", "1");
}
use of org.mifos.security.util.ActivityContext in project head by mifos.
the class ReportsActionStrutsTest method setUp.
@Before
public void setUp() throws Exception {
userContext = TestUtils.makeUser();
request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
addRequestParameter("recordLoanOfficerId", "1");
addRequestParameter("recordOfficeId", "1");
ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
request.getSession(false).setAttribute("ActivityContext", ac);
}
use of org.mifos.security.util.ActivityContext in project head by mifos.
the class ReportsUserParamsActionStrutsTest method setUp.
@Before
public void setUp() throws Exception {
userContext = TestUtils.makeUser();
request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
request.getSession(false).setAttribute("ActivityContext", ac);
}
use of org.mifos.security.util.ActivityContext in project head by mifos.
the class RolesPermissionsActionStrutsTest method testCreate.
@Test
public void testCreate() throws Exception {
setRequestPathInfo("/rolesPermission.do");
addRequestParameter("method", "load");
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
verifyNoActionErrors();
verifyNoActionMessages();
verifyForward(ActionForwards.load_success.toString());
setRequestPathInfo("/rolesPermission.do");
addRequestParameter("method", "create");
addRequestParameter("name", "New Role");
addRequestParameter("activity(1)", "checkbox");
addRequestParameter("activity(2)", "3");
addRequestParameter("activity(3)", "4");
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
actionPerform();
verifyNoActionErrors();
verifyNoActionMessages();
verifyForward(ActionForwards.create_success.toString());
role = legacyRolesPermissionsDao.getRole("New Role");
Assert.assertEquals(2, role.getActivities().size());
UserContext userContext = TestUtils.makeUser(role.getId());
ActivityContext activityContext = new ActivityContext((short) 3, (short) 1, (short) 0);
Assert.assertTrue(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
activityContext = new ActivityContext((short) 4, (short) 1, (short) 0);
Assert.assertTrue(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
activityContext = new ActivityContext((short) 5, (short) 1, (short) 0);
Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
}
use of org.mifos.security.util.ActivityContext in project head by mifos.
the class RolesPermissionsActionStrutsTest method testUpdateSuccess.
@Test
public void testUpdateSuccess() throws Exception {
rolesPermissionService.createRole(RolesAndPermissionConstants.ADMIN_ROLE, "New Role", legacyRolesPermissionsDao.getActivitieIds());
role = legacyRolesPermissionsDao.getRole("New Role");
setRequestPathInfo("/rolesPermission.do");
addRequestParameter("method", "manage");
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
addRequestParameter("id", role.getId().toString());
actionPerform();
verifyNoActionErrors();
verifyNoActionMessages();
verifyForward(ActionForwards.manage_success.toString());
Assert.assertNotNull(request.getAttribute(Constants.CURRENTFLOWKEY));
setRequestPathInfo("/rolesPermission.do");
addRequestParameter("method", "update");
addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
addRequestParameter("name", role.getName());
addRequestParameter("activity(1)", "checkbox");
addRequestParameter("activity(2)", "3");
addRequestParameter("activity(3)", "4");
actionPerform();
verifyNoActionErrors();
verifyNoActionMessages();
verifyForward(ActionForwards.update_success.toString());
Assert.assertNull(request.getAttribute(Constants.CURRENTFLOWKEY));
role = legacyRolesPermissionsDao.getRole(role.getId());
Assert.assertEquals(2, role.getActivities().size());
UserContext userContext = TestUtils.makeUser(role.getId());
ActivityContext activityContext = new ActivityContext((short) 3, (short) 1, (short) 0);
Assert.assertTrue(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
activityContext = new ActivityContext((short) 4, (short) 1, (short) 0);
Assert.assertTrue(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
activityContext = new ActivityContext((short) 5, (short) 1, (short) 0);
Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
}
Aggregations