Search in sources :

Example 1 with CustomBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules in project mamute by caelum.

the class NewsController method newNews.

@Post
@CustomBrutauthRules({ LoggedRule.class, InputRule.class })
public void newNews(String title, MarkedText description) {
    NewsInformation information = new NewsInformation(title, description, currentUser, "new news");
    User author = currentUser.getCurrent();
    News news = new News(information, author);
    result.include("news", news);
    newses.save(news);
    result.redirectTo(this).showNews(news, news.getSluggedTitle());
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) News(org.mamute.model.News) NewsInformation(org.mamute.model.NewsInformation) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post)

Example 2 with CustomBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules in project mamute by caelum.

the class QuestionController method newQuestion.

@Post
@CustomBrutauthRules({ LoggedRule.class, InputRule.class })
public void newQuestion(String title, MarkedText description, String tagNames, boolean watching, List<Long> attachmentsIds) {
    List<Attachment> attachments = this.attachments.load(attachmentsIds);
    attachmentsValidator.validate(attachments);
    List<String> splitedTags = splitter.splitTags(tagNames);
    List<Tag> foundTags = tagsManager.findOrCreate(splitedTags);
    validate(foundTags, splitedTags);
    QuestionInformation information = new QuestionInformation(title, description, currentUser, foundTags, "new question");
    brutalValidator.validate(information);
    User author = currentUser.getCurrent();
    Question question = new Question(information, author);
    result.include("question", question);
    validator.onErrorUse(Results.page()).of(this.getClass()).questionForm();
    questions.save(question);
    index.indexQuestion(question);
    question.add(attachments);
    ReputationEvent reputationEvent = new ReputationEvent(EventType.CREATED_QUESTION, question, author);
    author.increaseKarma(reputationEvent.getKarmaReward());
    reputationEvents.save(reputationEvent);
    if (watching) {
        watchers.add(question, new Watcher(author));
    }
    questionCreated.fire(new QuestionCreated(question));
    result.include("mamuteMessages", asList(messageFactory.build("alert", "question.quality_reminder")));
    result.redirectTo(this).showQuestion(question, question.getSluggedTitle());
}
Also used : Watcher(org.mamute.model.watch.Watcher) QuestionCreated(org.mamute.event.QuestionCreated) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post)

Example 3 with CustomBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules in project mamute by caelum.

the class FlagController method topFlagged.

@CustomBrutauthRules(ModeratorOnlyRule.class)
@Get
public void topFlagged() {
    List<FlaggableAndFlagCount> flaggedQuestions = flaggables.flaggedButVisible(Question.class);
    List<FlaggableAndFlagCount> flaggedAnswers = flaggables.flaggedButVisible(Answer.class);
    List<FlaggableAndFlagCount> flaggedComments = flaggables.flaggedButVisible(Comment.class);
    List<Question> commentQuestions = new ArrayList<>();
    Iterator<FlaggableAndFlagCount> iterator = flaggedComments.iterator();
    while (iterator.hasNext()) {
        Comment comment = (Comment) iterator.next().getFlaggable();
        Question q = questions.fromCommentId(comment.getId());
        if (q != null) {
            commentQuestions.add(q);
            continue;
        }
        Answer answerFromComment = answers.fromCommentId(comment.getId());
        if (answerFromComment != null) {
            commentQuestions.add(answerFromComment.getQuestion());
            continue;
        }
        // some flags may be related to news (not questions nor answers)
        iterator.remove();
    }
    result.include("questions", flaggedQuestions);
    result.include("answers", flaggedAnswers);
    result.include("comments", flaggedComments);
    result.include("commentQuestions", commentQuestions);
}
Also used : Comment(org.mamute.model.Comment) Answer(org.mamute.model.Answer) FlaggableAndFlagCount(org.mamute.dto.FlaggableAndFlagCount) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Get(br.com.caelum.vraptor.Get)

Example 4 with CustomBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules in project mamute by caelum.

the class TagController method saveTags.

@Post
@CustomBrutauthRules(ModeratorOnlyRule.class)
public void saveTags(String stringTags) {
    List<String> tagList = splitter.splitTags(stringTags);
    for (String tag : tagList) {
        tags.saveIfDoesntExists(new Tag(tag, "", null));
    }
    result.nothing();
}
Also used : Tag(org.mamute.model.Tag) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Post(br.com.caelum.vraptor.Post)

Example 5 with CustomBrutauthRules

use of br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules in project mamute by caelum.

the class TagPageController method newTagPage.

@Post
@CustomBrutauthRules(ModeratorOnlyRule.class)
public void newTagPage(String tagName, MarkedText about) {
    if (!validator.validateCreationWithTag(tagName))
        return;
    Tag tag = tags.findByName(tagName);
    TagPage tagPage = new TagPage(tag, about);
    if (!validator.validate(tagPage)) {
        validator.onErrorRedirectTo(TagPageController.class).tagPageForm(tagPage.getTagName());
        return;
    }
    tagPages.save(tagPage);
    result.redirectTo(this).showTagPage(tagPage.getTagName());
}
Also used : Tag(org.mamute.model.Tag) TagPage(org.mamute.model.TagPage) 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