Fix new users being able to remove posts from pools

This commit is contained in:
Toks
2015-10-22 22:25:02 -04:00
parent b708f5ea03
commit 40800988a8
2 changed files with 13 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ class Pool < ActiveRecord::Base
validates_inclusion_of :category, :in => %w(series collection)
validate :updater_can_change_category
validate :name_does_not_conflict_with_metatags
validate :updater_can_remove_posts
belongs_to :creator, :class_name => "User"
belongs_to :updater, :class_name => "User"
has_many :versions, lambda {order("pool_versions.id ASC")}, :class_name => "PoolVersion", :dependent => :destroy
@@ -233,6 +234,7 @@ class Pool < ActiveRecord::Base
def remove!(post)
return unless contains?(post.id)
return unless CurrentUser.user.can_remove_from_pools?
return if is_deleted?
update_attributes(:post_ids => remove_number_from_string(post.id, post_ids), :post_count => post_count - 1)
@@ -415,4 +417,14 @@ class Pool < ActiveRecord::Base
true
end
end
def updater_can_remove_posts
removed = post_id_array_was - post_id_array
if removed.any? && !CurrentUser.user.can_remove_from_pools?
errors[:base] << "You cannot removes posts from pools within the first week of sign up"
false
else
true
end
end
end

View File

@@ -916,6 +916,7 @@ class Post < ActiveRecord::Base
def remove_pool!(pool, force = false)
return unless belongs_to_pool?(pool)
return unless CurrentUser.user.can_remove_from_pools?
return if pool.is_deleted? && !force
reload
self.pool_string = pool_string.gsub(/(?:\A| )pool:#{pool.id}(?:\Z| )/, " ").strip