log.info("BEGIN");
UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
WeblogPermission p1 = new WeblogPermission(testWeblog, testUser,
WeblogPermission.ADMIN + "," + WeblogPermission.POST);
assertTrue(p1.hasAction(WeblogPermission.POST));
assertTrue(p1.hasAction(WeblogPermission.ADMIN));
assertEquals(2, p1.getActionsAsList().size());
WeblogPermission p2 = new WeblogPermission(testWeblog, testUser,
WeblogPermission.EDIT_DRAFT);
p1.addActions(p2);
assertEquals(3, p1.getActionsAsList().size());
WeblogPermission perm = null;
// delete permissions
testWeblog = TestUtils.getManagedWebsite(testWeblog);
testUser = TestUtils.getManagedUser(testUser);
perm = mgr.getWeblogPermission(testWeblog, testUser);
assertNotNull(perm);
mgr.revokeWeblogPermission(testWeblog, testUser, WeblogPermission.ALL_ACTIONS);
TestUtils.endSession(true);
// check that delete was successful
perm = null;
testWeblog = TestUtils.getManagedWebsite(testWeblog);
testUser = TestUtils.getManagedUser(testUser);
perm = mgr.getWeblogPermission(testWeblog, testUser);
assertNull(perm);
// create permissions
List<String> actions = new ArrayList<String>();
actions.add(WeblogPermission.ADMIN);
actions.add(WeblogPermission.POST);
mgr.grantWeblogPermission(testWeblog, testUser, actions);
TestUtils.endSession(true);
// check that create was successful
testWeblog = TestUtils.getManagedWebsite(testWeblog);
testUser = TestUtils.getManagedUser(testUser);
perm = null;
perm = mgr.getWeblogPermission(testWeblog, testUser);
assertNotNull(perm);
assertTrue(perm.hasAction(WeblogPermission.POST));
assertTrue(perm.hasAction(WeblogPermission.ADMIN));
TestUtils.endSession(true);
// revoke those same permissions
mgr.revokeWeblogPermission(perm.getWeblog(), perm.getUser(), WeblogPermission.ALL_ACTIONS);
TestUtils.endSession(true);
// add only draft permission
mgr.grantWeblogPermission(testWeblog, testUser,
Collections.singletonList(WeblogPermission.EDIT_DRAFT));
TestUtils.endSession(true);
// check that user has draft permisson only
testWeblog = TestUtils.getManagedWebsite(testWeblog);
testUser = TestUtils.getManagedUser(testUser);
perm = null;
perm = mgr.getWeblogPermission(testWeblog, testUser);
assertNotNull(perm);
assertTrue(perm.hasAction(WeblogPermission.EDIT_DRAFT));
assertFalse(perm.hasAction(WeblogPermission.POST));
assertFalse(perm.hasAction(WeblogPermission.ADMIN));
log.info("END");
}