Fix new users being able to remove posts from pools
This commit is contained in:
@@ -6,6 +6,7 @@ class Pool < ActiveRecord::Base
|
|||||||
validates_inclusion_of :category, :in => %w(series collection)
|
validates_inclusion_of :category, :in => %w(series collection)
|
||||||
validate :updater_can_change_category
|
validate :updater_can_change_category
|
||||||
validate :name_does_not_conflict_with_metatags
|
validate :name_does_not_conflict_with_metatags
|
||||||
|
validate :updater_can_remove_posts
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User"
|
||||||
has_many :versions, lambda {order("pool_versions.id ASC")}, :class_name => "PoolVersion", :dependent => :destroy
|
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)
|
def remove!(post)
|
||||||
return unless contains?(post.id)
|
return unless contains?(post.id)
|
||||||
|
return unless CurrentUser.user.can_remove_from_pools?
|
||||||
return if is_deleted?
|
return if is_deleted?
|
||||||
|
|
||||||
update_attributes(:post_ids => remove_number_from_string(post.id, post_ids), :post_count => post_count - 1)
|
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
|
true
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
@@ -916,6 +916,7 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
def remove_pool!(pool, force = false)
|
def remove_pool!(pool, force = false)
|
||||||
return unless belongs_to_pool?(pool)
|
return unless belongs_to_pool?(pool)
|
||||||
|
return unless CurrentUser.user.can_remove_from_pools?
|
||||||
return if pool.is_deleted? && !force
|
return if pool.is_deleted? && !force
|
||||||
reload
|
reload
|
||||||
self.pool_string = pool_string.gsub(/(?:\A| )pool:#{pool.id}(?:\Z| )/, " ").strip
|
self.pool_string = pool_string.gsub(/(?:\A| )pool:#{pool.id}(?:\Z| )/, " ").strip
|
||||||
|
|||||||
Reference in New Issue
Block a user