Search in sources :

Example 11 with CustomBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules 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 12 with CustomBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules 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

CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)12 Post (br.com.caelum.vraptor.Post)9 Watcher (org.mamute.model.watch.Watcher)4 Get (br.com.caelum.vraptor.Get)3 TagPage (org.mamute.model.TagPage)3 EmailAction (org.mamute.mail.action.EmailAction)2 LoggedUser (org.mamute.model.LoggedUser)2 NewsInformation (org.mamute.model.NewsInformation)2 Tag (org.mamute.model.Tag)2 User (org.mamute.model.User)2 Watchable (org.mamute.model.interfaces.Watchable)2 SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)1 ArrayList (java.util.ArrayList)1 Statistics (org.hibernate.stat.Statistics)1 FlaggableAndFlagCount (org.mamute.dto.FlaggableAndFlagCount)1 QuestionCreated (org.mamute.event.QuestionCreated)1 org.mamute.model (org.mamute.model)1 Answer (org.mamute.model.Answer)1 Comment (org.mamute.model.Comment)1 Information (org.mamute.model.Information)1