int removed = 0;
int changed = 0;
List<WeblogPermission> permsList = new ArrayList<WeblogPermission>();
try {
UserManager userMgr = WebloggerFactory.getWeblogger().getUserManager();
List<WeblogPermission> permissions = userMgr.getWeblogPermissions(getActionWeblog());
// we have to copy the permissions list so that when we remove permissions
// below we don't get ConcurrentModificationExceptions
for( WeblogPermission perm : permissions ) {
permsList.add(perm);
}
for (WeblogPermission perms : permsList) {
String sval = getParameter("perm-" + perms.getUser().getId());
if (sval != null) {
boolean error = false;
User user = getAuthenticatedUser();
if (perms.getUser().getUserName().equals(user.getUserName())) {
// if modifying self
if (sval.equals(WeblogPermission.EDIT_DRAFT)
&& (perms.hasAction(WeblogPermission.POST) || perms.hasAction(WeblogPermission.ADMIN))) {
error = true;
addError("memberPermissions.noSelfDemotions");
}
if (sval.equals(WeblogPermission.POST) && perms.hasAction(WeblogPermission.ADMIN)) {
error = true;
addError("memberPermissions.noSelfDemotions");
}
}
if (!error && !perms.hasAction(sval)) {
if (sval == null) {
userMgr.revokeWeblogPermission(
perms.getWeblog(), perms.getUser(), WeblogPermission.ALL_ACTIONS);
removed++;
} else {
userMgr.revokeWeblogPermission(
perms.getWeblog(), perms.getUser(), WeblogPermission.ALL_ACTIONS);
userMgr.grantWeblogPermission(
perms.getWeblog(), perms.getUser(), Utilities.stringToStringList(sval, ","));
changed++;
}
}
}