use of org.mamute.mail.action.EmailAction in project mamute by caelum.
the class NotificationMailer method buildEmail.
public Email buildEmail(NotificationMail notificationMail) {
DateTimeFormatter dateFormat = forPattern("MMM, dd").withLocale(new Locale("pt", "br"));
EmailAction action = notificationMail.getAction();
User to = notificationMail.getTo();
Email email = templates.template(notificationMail.getEmailTemplate(), bundle.getMessage("site.name"), action.getMainThread().getTitle()).with("emailAction", action).with("dateFormat", dateFormat).with("sanitizer", POLICY).with("bundle", bundle).with("watcher", to).with("linkerHelper", new LinkToHelper(router, brutalEnv)).with("logoUrl", env.get("mail_logo_url")).to(to.getName(), to.getEmail());
return email;
}
use of org.mamute.mail.action.EmailAction in project mamute by caelum.
the class CommentController method comment.
@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.CREATE_COMMENT)
@CustomBrutauthRules({ InputRule.class, InactiveQuestionRequiresMoreKarmaRule.class })
@Post
public void comment(Long id, String onWhat, MarkedText comment, boolean watching) {
User current = currentUser.getCurrent();
Comment newComment = new Comment(current, comment);
Class<?> type = getType(onWhat);
validator.validate(newComment);
validator.onErrorUse(Results.http()).setStatusCode(400);
org.mamute.model.Post commentable = comments.loadCommentable(type, id);
commentable.add(newComment);
comments.save(newComment);
Watchable watchable = commentable.getMainThread();
notificationManager.sendEmailsAndInactivate(new EmailAction(newComment, commentable));
if (watching) {
watchers.add(watchable, new Watcher(current));
} else {
watchers.removeIfWatching(watchable, new Watcher(current));
}
result.include("post", commentable);
result.include("type", onWhat);
result.forwardTo(BrutalTemplatesController.class).comment(newComment);
}
use of org.mamute.mail.action.EmailAction in project mamute by caelum.
the class AnswerController method newAnswer.
@Post
@CustomBrutauthRules({ LoggedRule.class, InputRule.class, InactiveQuestionRequiresMoreKarmaRule.class })
public void newAnswer(@Load Question question, MarkedText description, boolean watching, List<Long> attachmentsIds) {
User current = currentUser.getCurrent();
boolean canAnswer = answeredByValidator.validate(question);
boolean isUserWithKarma = current.hasKarma();
AnswerInformation information = new AnswerInformation(description, currentUser, "new answer");
Answer answer = new Answer(information, question, current);
List<Attachment> attachmentsLoaded = attachments.load(attachmentsIds);
answer.add(attachmentsLoaded);
if (canAnswer) {
question.touchedBy(current);
answers.save(answer);
ReputationEvent reputationEvent = new ReputationEvent(EventType.CREATED_ANSWER, question, current);
reputationEvents.save(reputationEvent);
if (isUserWithKarma) {
current.increaseKarma(reputationEvent.getKarmaReward());
}
result.redirectTo(QuestionController.class).showQuestion(question, question.getSluggedTitle());
notificationManager.sendEmailsAndInactivate(new EmailAction(answer, question));
if (watching) {
watchers.add(question, new Watcher(current));
}
} else {
result.include("answer", answer);
answeredByValidator.onErrorRedirectTo(QuestionController.class).showQuestion(question, question.getSluggedTitle());
}
}
Aggregations