Don't allow users to double flag stuff
Correct seed fu to match model
This commit is contained in:
parent
204a8a8b52
commit
f79f0e740a
|
@ -2,6 +2,8 @@ require_dependency 'rate_limiter'
|
|||
require_dependency 'system_message'
|
||||
|
||||
class PostAction < ActiveRecord::Base
|
||||
class AlreadyFlagged < StandardError; end
|
||||
|
||||
include RateLimiter::OnCreateRecord
|
||||
|
||||
attr_accessible :deleted_at, :post_action_type_id, :post_id, :user_id, :post, :user, :post_action_type, :message
|
||||
|
@ -115,6 +117,15 @@ class PostAction < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
before_create do
|
||||
if is_flag?
|
||||
if PostAction.where('user_id = ? and post_id = ? and post_action_type_id in (?) and deleted_at is null',
|
||||
self.user_id, self.post_id, PostActionType.FlagTypes).exists?
|
||||
raise AlreadyFlagged
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after_save do
|
||||
|
||||
# Update denormalized counts
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class PostActionType < ActiveRecord::Base
|
||||
|
||||
attr_accessible :id, :is_flag, :name_key, :icon
|
||||
|
||||
def self.ordered
|
||||
|
|
|
@ -93,10 +93,6 @@ module Discourse
|
|||
# So open id logs somewhere sane
|
||||
config.after_initialize do
|
||||
OpenID::Util.logger = Rails.logger
|
||||
|
||||
# latest possible so earliest in the stack
|
||||
# require 'rack/message_bus'
|
||||
# config.middleware.insert(0, Rack::MessageBus)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,6 +27,13 @@ PostActionType.seed do |s|
|
|||
s.position = 4
|
||||
end
|
||||
|
||||
PostActionType.seed do |s|
|
||||
s.id = PostActionType.Types[:vote]
|
||||
s.name_key = 'vote'
|
||||
s.is_flag = false
|
||||
s.position = 5
|
||||
end
|
||||
|
||||
PostActionType.seed do |s|
|
||||
s.id = PostActionType.Types[:spam]
|
||||
s.name_key = 'spam'
|
||||
|
|
|
@ -111,6 +111,13 @@ describe PostAction do
|
|||
|
||||
describe 'flagging' do
|
||||
|
||||
it 'does not allow you to flag stuff with 2 reasons' do
|
||||
post = Fabricate(:post)
|
||||
u1 = Fabricate(:evil_trout)
|
||||
PostAction.act(u1, post, PostActionType.Types[:spam])
|
||||
lambda { PostAction.act(u1, post, PostActionType.Types[:off_topic]) }.should raise_error(PostAction::AlreadyFlagged)
|
||||
end
|
||||
|
||||
it 'should update counts when you clear flags' do
|
||||
post = Fabricate(:post)
|
||||
u1 = Fabricate(:evil_trout)
|
||||
|
|
Loading…
Reference in New Issue