Post#approve!: signal errors with invalid object instead of exception.
This commit is contained in:
@@ -3,14 +3,13 @@ module Moderator
|
||||
class ApprovalsController < ApplicationController
|
||||
before_filter :approver_only
|
||||
skip_before_filter :api_check
|
||||
respond_to :json, :xml, :js
|
||||
|
||||
def create
|
||||
cookies.permanent[:moderated] = Time.now.to_i
|
||||
@post = ::Post.find(params[:post_id])
|
||||
if @post.is_deleted? || @post.is_flagged? || @post.is_pending?
|
||||
@post.approve!
|
||||
end
|
||||
rescue ::Post::ApprovalError
|
||||
post = ::Post.find(params[:post_id])
|
||||
@approval = post.approve!
|
||||
respond_with(@approval)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -322,7 +322,7 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def approve!(approver = CurrentUser.user)
|
||||
approvals.create!(user: approver)
|
||||
approvals.create(user: approver)
|
||||
end
|
||||
|
||||
def approved_by?(user)
|
||||
|
||||
@@ -14,6 +14,10 @@ class PostApproval < ActiveRecord::Base
|
||||
errors.add(:post, "is locked and cannot be approved")
|
||||
end
|
||||
|
||||
if post.status == "active"
|
||||
errors.add(:post, "is already active and cannot be approved")
|
||||
end
|
||||
|
||||
if post.uploader == user
|
||||
errors.add(:base, "You cannot approve a post you uploaded")
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% if @post.errors.any? %>
|
||||
<% if @approval.errors.any? %>
|
||||
|
||||
Danbooru.error("Error: " + <%= @post.errors.full_messages.join("; ").to_json.html_safe %>);
|
||||
Danbooru.error("Error: " + <%= @approval.errors.full_messages.join("; ").to_json.html_safe %>);
|
||||
|
||||
<% else %>
|
||||
|
||||
@@ -10,7 +10,7 @@ $("#c-posts #flag").show();
|
||||
|
||||
$("#pending-approval-notice").hide();
|
||||
|
||||
$("#c-moderator-post-queues #post-<%= @post.id %>").hide();
|
||||
$("#c-moderator-post-queues #post-<%= @approval.post.id %>").hide();
|
||||
Danbooru.notice("Post was approved");
|
||||
|
||||
Danbooru.ModQueue.increment_processed();
|
||||
|
||||
Reference in New Issue
Block a user