moderation log: fix tag change summary; fixes issue #43
This commit is contained in:
parent
d108158d15
commit
a4e5684994
|
@ -138,24 +138,19 @@ class Story < ActiveRecord::Base
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
all_changes = self.changes.merge(self.tagging_changes)
|
||||||
|
|
||||||
m = Moderation.new
|
m = Moderation.new
|
||||||
m.moderator_user_id = self.editor_user_id
|
m.moderator_user_id = self.editor_user_id
|
||||||
m.story_id = self.id
|
m.story_id = self.id
|
||||||
|
|
||||||
if self.changes["is_expired"] && self.is_expired?
|
if all_changes["is_expired"] && self.is_expired?
|
||||||
m.action = "deleted story"
|
m.action = "deleted story"
|
||||||
elsif self.changes["is_expired"] && !self.is_expired?
|
elsif all_changes["is_expired"] && !self.is_expired?
|
||||||
m.action = "undeleted story"
|
m.action = "undeleted story"
|
||||||
else
|
else
|
||||||
actions = self.changes.map{|k,v| "changed #{k} from #{v[0].inspect} " <<
|
m.action = all_changes.map{|k,v| "changed #{k} from #{v[0].inspect} " <<
|
||||||
"to #{v[1].inspect}" }
|
"to #{v[1].inspect}" }.join(", ")
|
||||||
|
|
||||||
if (old_tags = self.tags.map{|t| t.tag }) != self.tags_a
|
|
||||||
actions.push "changed tags from \"#{old_tags.join(", ")}\" to " <<
|
|
||||||
"\"#{self.tags_a.join(", ")}\""
|
|
||||||
end
|
|
||||||
|
|
||||||
m.action = actions.join(", ")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
m.reason = self.moderation_reason
|
m.reason = self.moderation_reason
|
||||||
|
@ -306,6 +301,19 @@ class Story < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tagging_changes
|
||||||
|
old_tags_a = self.taggings.reject{|tg| tg.new_record? }.map{|tg|
|
||||||
|
tg.tag.tag }.join(" ")
|
||||||
|
new_tags_a = self.taggings.reject{|tg| tg.marked_for_destruction?
|
||||||
|
}.map{|tg| tg.tag.tag }.join(" ")
|
||||||
|
|
||||||
|
if old_tags_a == new_tags_a
|
||||||
|
{}
|
||||||
|
else
|
||||||
|
{ "tags" => [ old_tags_a, new_tags_a ] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def url=(u)
|
def url=(u)
|
||||||
# strip out stupid google analytics parameters
|
# strip out stupid google analytics parameters
|
||||||
|
|
|
@ -112,4 +112,33 @@ describe Story do
|
||||||
s.valid?
|
s.valid?
|
||||||
s.url.should == "https://factorable.net/"
|
s.url.should == "https://factorable.net/"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "calculates tag changes properly" do
|
||||||
|
s = Story.make!(:title => "blah", :tags_a => [ "tag1", "tag2" ])
|
||||||
|
|
||||||
|
s.tags_a = [ "tag2" ]
|
||||||
|
s.tagging_changes.should == { "tags" => [ "tag1 tag2", "tag2" ] }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "logs moderations properly" do
|
||||||
|
mod = User.make!(:username => "mod", :is_moderator => true)
|
||||||
|
|
||||||
|
s = Story.make!(:title => "blah", :tags_a => [ "tag1", "tag2" ],
|
||||||
|
:description => "desc")
|
||||||
|
|
||||||
|
s.title = "changed title"
|
||||||
|
s.description = nil
|
||||||
|
s.tags_a = [ "tag1" ]
|
||||||
|
|
||||||
|
s.editor_user_id = mod.id
|
||||||
|
s.moderation_reason = "because i hate you"
|
||||||
|
s.save!
|
||||||
|
|
||||||
|
mod_log = Moderation.last
|
||||||
|
mod_log.moderator_user_id.should == mod.id
|
||||||
|
mod_log.story_id.should == s.id
|
||||||
|
mod_log.reason.should == "because i hate you"
|
||||||
|
mod_log.action.should match(/title from "blah" to "changed title"/)
|
||||||
|
mod_log.action.should match(/tags from "tag1 tag2" to "tag1"/)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue