use of br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules in project mamute by caelum.
the class HistoryController method history.
@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.MODERATE_EDITS)
@Get
public void history() {
ModeratableAndPendingHistory pendingQuestions = informations.pendingByUpdatables(Question.class);
result.include("questions", pendingQuestions);
ModeratableAndPendingHistory pendingAnswers = informations.pendingByUpdatables(Answer.class);
result.include("answers", pendingAnswers);
}
use of br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules in project mamute by caelum.
the class FlagController method addFlag.
@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.CREATE_FLAG)
@Post
public void addFlag(String flaggableType, Long flaggableId, FlagType flagType, String reason) {
Class<?> clazz = urlMapping.getClassFor(flaggableType);
if (flagType == null) {
result.use(http()).sendError(400);
return;
}
if (flags.alreadyFlagged(loggedUser.getCurrent(), flaggableId, clazz)) {
// conflict
result.use(http()).sendError(409);
return;
}
Flaggable flaggable = flaggables.getById(flaggableId, clazz);
flagTrigger.fire(flaggable);
Flag flag = new Flag(flagType, loggedUser.getCurrent());
if (flagType.equals(FlagType.OTHER)) {
flag.setReason(reason);
}
flags.save(flag);
flaggable.add(flag);
result.nothing();
}
use of br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules in project mamute by caelum.
the class HistoryController method publish.
@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.MODERATE_EDITS)
@Post
public void publish(Long moderatableId, String moderatableType, Long aprovedInformationId, String aprovedInformationType) {
Class<?> moderatableClass = urlMapping.getClassFor(moderatableType);
Information approved = informations.getById(aprovedInformationId, aprovedInformationType);
Moderatable moderatable = moderatables.getById(moderatableId, moderatableClass);
List<Information> pending = informations.pendingFor(moderatableId, moderatableClass);
if (!approved.isPending()) {
result.use(Results.http()).sendError(403);
return;
}
User approvedAuthor = approved.getAuthor();
refusePending(aprovedInformationId, pending);
currentUser.getCurrent().approve(moderatable, approved, environmentKarma);
ReputationEvent editAppoved = new ReputationEvent(EventType.EDIT_APPROVED, moderatable.getQuestion(), approvedAuthor);
int karma = calculator.karmaFor(editAppoved);
approvedAuthor.increaseKarma(karma);
reputationEvents.save(editAppoved);
result.redirectTo(this).history();
}
use of br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules 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);
}
Aggregations