Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
e8c91269
Commit
e8c91269
authored
Apr 03, 2013
by
Kevin Chugh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
find comment flags and move testing forward
parent
88b0cd88
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
7 deletions
+60
-7
api/flags.rb
+0
-1
lib/helpers.rb
+23
-5
models/content.rb
+1
-0
spec/api/abuse_spec.rb
+36
-1
No files found.
api/flags.rb
View file @
e8c91269
...
@@ -13,4 +13,3 @@ end
...
@@ -13,4 +13,3 @@ end
put
"
#{
APIPREFIX
}
/comments/:comment_id/abuse_unflags"
do
|
thread_id
|
put
"
#{
APIPREFIX
}
/comments/:comment_id/abuse_unflags"
do
|
thread_id
|
un_flag_as_abuse
comment
un_flag_as_abuse
comment
end
end
lib/helpers.rb
View file @
e8c91269
...
@@ -46,7 +46,14 @@ helpers do
...
@@ -46,7 +46,14 @@ helpers do
def
un_flag_as_abuse
(
obj
)
def
un_flag_as_abuse
(
obj
)
raise
ArgumentError
,
"User id is required"
unless
user
raise
ArgumentError
,
"User id is required"
unless
user
if
params
[
"moderator"
]
obj
.
historical_abuse_flaggers
+=
obj
.
abuse_flaggers
obj
.
historical_abuse_flaggers
=
obj
.
historical_abuse_flaggers
.
uniq
obj
.
abuse_flaggers
.
clear
else
obj
.
abuse_flaggers
.
delete
user
.
id
obj
.
abuse_flaggers
.
delete
user
.
id
end
obj
.
save
obj
.
save
obj
.
reload
.
to_hash
.
to_json
obj
.
reload
.
to_hash
.
to_json
end
end
...
@@ -107,13 +114,25 @@ helpers do
...
@@ -107,13 +114,25 @@ helpers do
end
end
def
handle_threads_query
(
comment_threads
)
def
handle_threads_query
(
comment_threads
)
if
params
[
:flagged
]
#get flagged threads and threads containing flagged responses
comment_threads
=
comment_threads
.
where
(
:course_id
=>
params
[
:course_id
]).
where
(
:abuse_flaggers
)
else
if
params
[
:course_id
]
if
params
[
:course_id
]
comment_threads
=
comment_threads
.
where
(
:course_id
=>
params
[
:course_id
])
comment_threads
=
comment_threads
.
where
(
:course_id
=>
params
[
:course_id
])
if
params
[
:flagged
]
#get flagged threads and threads containing flagged responses
comment_ids
=
Comment
.
where
(
:course_id
=>
params
[
:course_id
]).
where
(
:abuse_flaggers
.
ne
=>
[],
:abuse_flaggers
.
exists
=>
true
).
collect
{
|
c
|
c
.
comment_thread_id
}.
uniq
thread_ids
=
comment_threads
.
where
(
:abuse_flaggers
.
ne
=>
[],
:abuse_flaggers
.
exists
=>
true
).
collect
{
|
c
|
c
.
id
}
comment_ids
+=
thread_ids
comment_threads
=
comment_threads
.
where
(
:id
.
in
=>
comment_ids
)
end
end
end
if
CommentService
.
config
[
:cache_enabled
]
if
CommentService
.
config
[
:cache_enabled
]
query_params
=
params
.
slice
(
*
%w[course_id commentable_id sort_key sort_order page per_page user_id]
)
query_params
=
params
.
slice
(
*
%w[course_id commentable_id sort_key sort_order page per_page user_id]
)
...
@@ -170,7 +189,6 @@ helpers do
...
@@ -170,7 +189,6 @@ helpers do
}.
to_json
}.
to_json
end
end
end
end
end
def
author_contents_only
(
contents
,
author_id
)
def
author_contents_only
(
contents
,
author_id
)
contents
.
map
do
|
content
|
contents
.
map
do
|
content
|
...
...
models/content.rb
View file @
e8c91269
...
@@ -4,6 +4,7 @@ class Content
...
@@ -4,6 +4,7 @@ class Content
field
:visible
,
type:
Boolean
,
default:
true
field
:visible
,
type:
Boolean
,
default:
true
field
:abuse_flaggers
,
type:
Array
,
default:
[]
field
:abuse_flaggers
,
type:
Array
,
default:
[]
field
:historical_abuse_flaggers
,
type:
Array
,
default:
[]
#preserve abuse flaggers after a moderator unflags
def
author_with_anonymity
(
attr
=
nil
,
attr_when_anonymous
=
nil
)
def
author_with_anonymity
(
attr
=
nil
,
attr_when_anonymous
=
nil
)
if
not
attr
if
not
attr
...
...
spec/api/abuse_spec.rb
View file @
e8c91269
...
@@ -8,6 +8,14 @@ def create_thread_flag(thread_id, user_id)
...
@@ -8,6 +8,14 @@ def create_thread_flag(thread_id, user_id)
create_flag
(
"/api/v1/threads/"
+
thread_id
+
"/abuse_flags"
,
user_id
)
create_flag
(
"/api/v1/threads/"
+
thread_id
+
"/abuse_flags"
,
user_id
)
end
end
def
remove_thread_flag
(
thread_id
,
user_id
)
remove_flag
(
"/api/v1/threads/"
+
thread_id
+
"/abuse_unflags"
,
user_id
)
end
def
remove_comment_flag
(
thread_id
,
user_id
)
remove_flag
(
"/api/v1/threads/"
+
comment_id
+
"/abuse_unflags"
,
user_id
)
end
def
create_flag
(
put_command
,
user_id
)
def
create_flag
(
put_command
,
user_id
)
if
user_id
.
nil?
if
user_id
.
nil?
put
put_command
put
put_command
...
@@ -45,7 +53,7 @@ describe "app" do
...
@@ -45,7 +53,7 @@ describe "app" do
#end
#end
end
end
describe
"flag a thread as abusive"
do
describe
"flag a thread as abusive"
do
it
"create or update the abuse_flags on the
thread
"
do
it
"create or update the abuse_flags on the
comment
"
do
comment
=
Comment
.
first
comment
=
Comment
.
first
thread
=
comment
.
comment_thread
thread
=
comment
.
comment_thread
prev_abuse_flaggers
=
thread
.
abuse_flaggers
prev_abuse_flaggers
=
thread
.
abuse_flaggers
...
@@ -70,5 +78,32 @@ describe "app" do
...
@@ -70,5 +78,32 @@ describe "app" do
# Comment.first.comment_thread.to_hash
# Comment.first.comment_thread.to_hash
#end
#end
end
end
describe
"unflag a comment as abusive"
do
it
"removes the user from the existing abuse_flaggers"
do
comment
=
Comment
.
first
thread
=
comment
.
comment_thread
prev_abuse_flaggers
=
thread
.
abuse_flaggers
create_thread_flag
(
"
#{
thread
.
id
}
"
,
User
.
first
.
id
)
prev_abuse_flaggers
.
should
include
User
.
first
.
id
remove_thread_flag
(
"
#{
thread
.
id
}
"
,
User
.
first
.
id
)
comment
=
Comment
.
find
(
comment
.
id
)
comment
.
comment_thread
.
abuse_flaggers
.
length
.
should
==
prev_abuse_flaggers
.
length
+
1
prev_abuse_flaggers
.
should_not
include
?
User
.
first
.
id
end
it
"returns 400 when the thread does not exist"
do
remove_thread_flag
(
"does_not_exist"
,
User
.
first
.
id
)
last_response
.
status
.
should
==
400
end
it
"returns 400 when user_id is not provided"
do
remove_thread_flag
(
"
#{
Comment
.
first
.
comment_thread
.
id
}
"
,
nil
)
last_response
.
status
.
should
==
400
end
#Would like to test the output of to_hash, but not sure how to deal with a Moped::BSON::Document object
#it "has a correct hash" do
# create_thread_flag("#{Comment.first.comment_thread.id}", User.first.id)
# Comment.first.comment_thread.to_hash
#end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment