* Added note version controller and test
* Added pool version controller and test * Refactored unit tests for post disapprovals * Renamed PostModerationDetail to PostDisapproval
This commit is contained in:
10
app/controllers/note_versions_controller.rb
Normal file
10
app/controllers/note_versions_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class NoteVersionsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
|
||||
def index
|
||||
@search = NoteVersion.search(params[:search])
|
||||
@note_versions = @search.paginate(:page => params[:page])
|
||||
respond_with(@note_versions)
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,6 @@
|
||||
class PoolVersionsController < ApplicationController
|
||||
def index
|
||||
@search = PoolVersion.search(params[:search])
|
||||
@pool_versions = @search.paginate(:page => params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
class PostModerationController < ApplicationController
|
||||
def show
|
||||
end
|
||||
|
||||
def create
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :janitor_only
|
||||
|
||||
def moderate
|
||||
@search = Post.pending.available_for_moderation.search(params[:search]).order("id asc")
|
||||
@posts = @search.paginate(:page => params[:page])
|
||||
respond_with(@posts)
|
||||
end
|
||||
|
||||
def update
|
||||
def approve
|
||||
@post = Post.find(params[:post_id])
|
||||
@post.approve!
|
||||
respond_with(@post, :location => post_moderation_moderate_path)
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
def disapprove
|
||||
@post = Post.find(params[:post_id])
|
||||
@post_disapproval = PostDisapproval.create(:post => @post, :user => CurrentUser.user)
|
||||
respond_with(@post_disapproval, :location => post_moderation_moderate_path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
class NoteVersion < ActiveRecord::Base
|
||||
before_validation :initialize_updater
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
|
||||
@@ -26,8 +26,11 @@ class Post < ActiveRecord::Base
|
||||
validates_presence_of :parent, :if => lambda {|rec| !rec.parent_id.nil?}
|
||||
validate :validate_parent_does_not_have_a_parent
|
||||
attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at
|
||||
scope :pending, where(["is_pending = ?", true])
|
||||
scope :visible, lambda {|user| Danbooru.config.can_user_see_post_conditions(user)}
|
||||
scope :commented_before, lambda {|date| where("last_commented_at < ?", date).order("last_commented_at DESC")}
|
||||
scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
|
||||
scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
|
||||
|
||||
module FileMethods
|
||||
def delete_files
|
||||
|
||||
11
app/models/post_disapproval.rb
Normal file
11
app/models/post_disapproval.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class PostDisapproval < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
validates_uniqueness_of :post_id, :scope => [:user_id]
|
||||
|
||||
def self.prune!
|
||||
joins(:post).where("posts.is_pending = FALSE AND posts.is_flagged = FALSE").select("post_disapprovals.*").each do |post_disapproval|
|
||||
post_disapproval.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
class PostModerationDetail < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
|
||||
def self.filter(posts, user, select_hidden = false)
|
||||
hidden = where(:user_id => user.id).select("post_id").map(&:post_id)
|
||||
if select_hidden
|
||||
posts.select {|x| hidden.include?(x.id)}
|
||||
else
|
||||
posts.reject {|x| hidden.include?(x.id)}
|
||||
end
|
||||
end
|
||||
|
||||
def self.prune!
|
||||
joins(:post).where("posts.is_pending = FALSE AND posts.is_flagged = FALSE").each do |hidden_post|
|
||||
hidden_post.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
0
app/views/note_versions/index.html.erb
Normal file
0
app/views/note_versions/index.html.erb
Normal file
0
app/views/pool_versions/index.html.erb
Normal file
0
app/views/pool_versions/index.html.erb
Normal file
0
app/views/post_moderation/moderate.html.erb
Normal file
0
app/views/post_moderation/moderate.html.erb
Normal file
Reference in New Issue
Block a user