Search in sources :

Example 1 with EmailAction

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;
}
Also used : Locale(java.util.Locale) User(org.mamute.model.User) Email(org.apache.commons.mail.Email) EmailAction(org.mamute.mail.action.EmailAction) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 2 with EmailAction

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);
}
Also used : Watchable(org.mamute.model.interfaces.Watchable) Watcher(org.mamute.model.watch.Watcher) org.mamute.model(org.mamute.model) EmailAction(org.mamute.mail.action.EmailAction) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post) SimpleBrutauthRules(br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)

Example 3 with EmailAction

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());
    }
}
Also used : Watcher(org.mamute.model.watch.Watcher) EmailAction(org.mamute.mail.action.EmailAction) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post)

Aggregations

EmailAction (org.mamute.mail.action.EmailAction)3 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)2 Post (br.com.caelum.vraptor.Post)2 Watcher (org.mamute.model.watch.Watcher)2 SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)1 Locale (java.util.Locale)1 Email (org.apache.commons.mail.Email)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 org.mamute.model (org.mamute.model)1 User (org.mamute.model.User)1 Watchable (org.mamute.model.interfaces.Watchable)1