ActionMessages errors = new ActionErrors();
InviteMemberForm form = (InviteMemberForm)actionForm;
UserManager umgr = RollerFactory.getRoller().getUserManager();
UserData user = umgr.getUserByUserName(form.getUserName());
BasePageModel pageModel = new BasePageModel(
"inviteMember.title", request, response, mapping);
RollerSession rses = RollerSession.getRollerSession(request);
// Ensure use has admin perms for this weblog
if (pageModel.getWebsite() != null && rses.isUserAuthorizedToAdmin(pageModel.getWebsite())) {
if (user == null) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("inviteMember.error.userNotFound"));
} else {
RollerRequest rreq = RollerRequest.getRollerRequest(request);
WebsiteData website = rreq.getWebsite();
PermissionsData perms = umgr.getPermissions(website, user);
if (perms != null && perms.isPending()) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("inviteMember.error.userAlreadyInvited"));
request.setAttribute("model", new BasePageModel(
"inviteMember.title", request, response, mapping));
} else if (perms != null) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("inviteMember.error.userAlreadyMember"));
request.setAttribute("model", new BasePageModel(
"inviteMember.title", request, response, mapping));
} else {
String mask = request.getParameter("permissionsMask");
umgr.inviteUser(website, user, Short.parseShort(mask));
RollerFactory.getRoller().flush();
request.setAttribute("user", user);
try {
notifyInvitee(request, website, user);
} catch (RollerException e) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.untranslated", e.getMessage()));
}
msgs.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("inviteMember.userInvited"));
request.setAttribute("model", new BasePageModel(
"inviteMemberDone.title", request, response, mapping));
forward = mapping.findForward("memberPermissions");
}
}