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());
}
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());
}
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);
}
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();
}
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());
}
Aggregations