Commit 149c1bb3 by Your Name

allow flagging for abuse and spoilers

parent 9f0bbe59
......@@ -156,9 +156,9 @@ namespace :db do
"comment_count" => 0, "title" => Faker::Lorem.sentence(6), "author_id" => rand(1..10).to_s,
"body" => Faker::Lorem.paragraphs.join("\n\n"), "course_id" => COURSE_ID, "created_at" => Time.now,
"commentable_id" => COURSE_ID, "closed" => [true, false].sample, "updated_at" => Time.now, "last_activity_at" => Time.now,
"votes" => {"count" => 0, "down" => [], "down_count" => 0, "point" => 0, "up" => [], "up_count" => []}}
"votes" => {"count" => 0, "down" => [], "down_count" => 0, "point" => 0, "up" => [], "spoiler_count" => []}}
coll.insert(doc)
end
endson if hes working that woul
binding.pry
Tire.index('comment_threads').delete
CommentThread.create_elasticsearch_index
......
......@@ -37,11 +37,18 @@ helpers do
obj.reload.to_hash.to_json
end
def flag_as_abuse(obj)
raise ArgumentError, "User id is required" unless user
obj.abuse_flaggers << user.id unless obj.abuse_flaggers.include? user.id
obj.reload.to_hash.to_json
end
def undo_vote_for(obj)
raise ArgumentError, "must provide user id" unless user
user.unvote(obj)
obj.reload.to_hash.to_json
end
def value_to_boolean(value)
!!(value.to_s =~ /^true$/i)
......
......@@ -60,6 +60,8 @@ class Comment < Content
.merge("thread_id" => comment_thread.id)
.merge("commentable_id" => comment_thread.commentable_id)
.merge("votes" => votes.slice(*%w[count up_count down_count point]))
.merge("abuse_flaggers" => comment_thread.abuse_flaggers)
.merge("spoiler_flaggers" => comment_thread.spoiler_flaggers)
.merge("type" => "comment")
end
end
......
......@@ -158,6 +158,8 @@ class CommentThread < Content
.merge("id" => _id, "user_id" => author.id,
"username" => author.username,
"votes" => votes.slice(*%w[count up_count down_count point]),
"abuse_flaggers" => abuse_flaggers,
"spoiler_flaggers" => spoiler_flaggers,
"tags" => tags_array,
"type" => "thread",
"endorsed" => endorsed?)
......
......@@ -2,6 +2,10 @@ class Content
include Mongoid::Document
field :visible, type: Boolean, default: true
field :abuse_flaggers, type: Array, default: []
field :spoiler_flaggers, type: Array, default: []
def author_with_anonymity(attr=nil, attr_when_anonymous=nil)
if not attr
(anonymous || anonymous_to_peers) ? nil : author
......@@ -9,4 +13,5 @@ class Content
(anonymous || anonymous_to_peers) ? attr_when_anonymous : author.send(attr)
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment