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
e097ed98
Commit
e097ed98
authored
Sep 14, 2012
by
Arjun Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Anonymous to peers
parent
d0656e8e
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
21 additions
and
12 deletions
+21
-12
api/comment_threads.rb
+1
-0
api/commentables.rb
+1
-0
api/comments.rb
+1
-0
api/users.rb
+1
-1
lib/helpers.rb
+5
-1
models/comment.rb
+3
-2
models/comment_thread.rb
+3
-2
models/content.rb
+2
-2
models/observers/post_reply_observer.rb
+2
-2
models/observers/post_topic_observer.rb
+2
-2
No files found.
api/comment_threads.rb
View file @
e097ed98
...
...
@@ -22,6 +22,7 @@ end
post
"
#{
APIPREFIX
}
/threads/:thread_id/comments"
do
|
thread_id
|
comment
=
Comment
.
new
(
params
.
slice
(
*
%w[body course_id]
))
comment
.
anonymous
=
bool_anonymous
||
false
comment
.
anonymous_to_peers
=
bool_anonymous_to_peers
||
false
comment
.
author
=
user
comment
.
comment_thread
=
thread
comment
.
save
...
...
api/commentables.rb
View file @
e097ed98
...
...
@@ -12,6 +12,7 @@ end
post
"
#{
APIPREFIX
}
/:commentable_id/threads"
do
|
commentable_id
|
thread
=
CommentThread
.
new
(
params
.
slice
(
*
%w[title body course_id]
).
merge
(
commentable_id:
commentable_id
))
thread
.
anonymous
=
bool_anonymous
||
false
thread
.
anonymous_to_peers
=
bool_anonymous_to_peers
||
false
thread
.
tags
=
params
[
"tags"
]
||
""
thread
.
author
=
user
thread
.
save
...
...
api/comments.rb
View file @
e097ed98
...
...
@@ -14,6 +14,7 @@ end
post
"
#{
APIPREFIX
}
/comments/:comment_id"
do
|
comment_id
|
sub_comment
=
comment
.
children
.
new
(
params
.
slice
(
*
%w[body course_id]
))
sub_comment
.
anonymous
=
bool_anonymous
||
false
sub_comment
.
anonymous_to_peers
=
bool_anonymous_to_peers
||
false
sub_comment
.
author
=
user
sub_comment
.
comment_thread
=
comment
.
comment_thread
sub_comment
.
save
...
...
api/users.rb
View file @
e097ed98
...
...
@@ -23,7 +23,7 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
page
=
(
params
[
"page"
]
||
DEFAULT_PAGE
).
to_i
per_page
=
(
params
[
"per_page"
]
||
DEFAULT_PER_PAGE
).
to_i
active_contents
=
Content
.
where
(
author_id:
user_id
,
anonymous:
false
,
course_id:
params
[
"course_id"
])
active_contents
=
Content
.
where
(
author_id:
user_id
,
anonymous:
false
,
anonymous_to_peers:
false
,
course_id:
params
[
"course_id"
])
.
order_by
(
updated_at: :desc
)
num_pages
=
[
1
,
(
active_contents
.
count
/
per_page
.
to_f
).
ceil
].
max
...
...
lib/helpers.rb
View file @
e097ed98
...
...
@@ -63,6 +63,10 @@ helpers do
value_to_boolean
params
[
"anonymous"
]
end
def
bool_anonymous_to_peers
value_to_boolean
params
[
"anonymous_to_peers"
]
end
def
handle_paged_threads_query
(
paged_comment_threads
)
end
...
...
@@ -126,7 +130,7 @@ helpers do
contents
.
map
do
|
content
|
content
[
'children'
]
=
author_contents_only
(
content
[
'children'
],
author_id
)
if
content
[
'children'
].
length
>
0
or
\
(
content
[
'user_id'
]
==
author_id
and
not
content
[
'anonymous'
])
(
content
[
'user_id'
]
==
author_id
and
not
content
[
'anonymous'
]
and
not
content
[
'anonymous_to_peers'
]
)
content
else
nil
...
...
models/comment.rb
View file @
e097ed98
...
...
@@ -13,6 +13,7 @@ class Comment < Content
field
:body
,
type:
String
field
:endorsed
,
type:
Boolean
,
default:
false
field
:anonymous
,
type:
Boolean
,
default:
false
field
:anonymous_to_peers
,
type:
Boolean
,
default:
false
field
:at_position_list
,
type:
Array
,
default:
[]
index
({
author_id:
1
,
course_id:
1
})
...
...
@@ -20,7 +21,7 @@ class Comment < Content
belongs_to
:comment_thread
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
index:
true
attr_accessible
:body
,
:course_id
,
:anonymous
,
:endorsed
attr_accessible
:body
,
:course_id
,
:anonymous
,
:
anonymous_to_peers
,
:
endorsed
validates_presence_of
:comment_thread
,
autosave:
false
validates_presence_of
:body
...
...
@@ -50,7 +51,7 @@ class Comment < Content
if
params
[
:recursive
]
self
.
class
.
hash_tree
(
subtree
(
sort:
sort_by_parent_and_time
)).
first
else
as_document
.
slice
(
*
%w[body course_id endorsed anonymous created_at updated_at at_position_list]
)
as_document
.
slice
(
*
%w[body course_id endorsed anonymous
anonymous_to_peers
created_at updated_at at_position_list]
)
.
merge
(
"id"
=>
_id
)
.
merge
(
"user_id"
=>
author
.
id
)
.
merge
(
"username"
=>
author
.
username
)
...
...
models/comment_thread.rb
View file @
e097ed98
...
...
@@ -17,6 +17,7 @@ class CommentThread < Content
field
:course_id
,
type:
String
field
:commentable_id
,
type:
String
field
:anonymous
,
type:
Boolean
,
default:
false
field
:anonymous_to_peers
,
type:
Boolean
,
default:
false
field
:closed
,
type:
Boolean
,
default:
false
field
:at_position_list
,
type:
Array
,
default:
[]
field
:last_activity_at
,
type:
Time
...
...
@@ -47,7 +48,7 @@ class CommentThread < Content
has_many
:comments
,
dependent: :destroy
#, autosave: true# Use destroy to envoke callback on the top-level comments TODO async
has_many
:activities
,
autosave:
true
attr_accessible
:title
,
:body
,
:course_id
,
:commentable_id
,
:anonymous
,
:closed
attr_accessible
:title
,
:body
,
:course_id
,
:commentable_id
,
:anonymous
,
:
anonymous_to_peers
,
:
closed
validates_presence_of
:title
validates_presence_of
:body
...
...
@@ -153,7 +154,7 @@ class CommentThread < Content
end
def
to_hash
(
params
=
{})
doc
=
as_document
.
slice
(
*
%w[title body course_id anonymous commentable_id created_at updated_at at_position_list closed]
)
doc
=
as_document
.
slice
(
*
%w[title body course_id anonymous
anonymous_to_peers
commentable_id created_at updated_at at_position_list closed]
)
.
merge
(
"id"
=>
_id
,
"user_id"
=>
author
.
id
,
"username"
=>
author
.
username
,
"votes"
=>
votes
.
slice
(
*
%w[count up_count down_count point]
),
...
...
models/content.rb
View file @
e097ed98
...
...
@@ -4,9 +4,9 @@ class Content
def
author_with_anonymity
(
attr
=
nil
,
attr_when_anonymous
=
nil
)
if
not
attr
anonymous
?
nil
:
author
(
anonymous
||
anonymous_to_peers
)
?
nil
:
author
else
anonymous
?
attr_when_anonymous
:
author
.
send
(
attr
)
(
anonymous
||
anonymous_to_peers
)
?
attr_when_anonymous
:
author
.
send
(
attr
)
end
end
end
models/observers/post_reply_observer.rb
View file @
e097ed98
...
...
@@ -9,13 +9,13 @@ class PostReplyObserver < Mongoid::Observer
activity
=
Activity
.
new
activity
.
happend_at
=
comment
.
created_at
activity
.
anonymous
=
comment
.
anonymous
activity
.
anonymous
=
(
comment
.
anonymous
||
comment
.
anonymous_to_peers
)
activity
.
actor
=
comment
.
author
activity
.
target
=
comment
.
comment_thread
activity
.
activity_type
=
"post_reply"
activity
.
save!
if
comment
.
comment_thread
.
subscribers
or
(
comment
.
author
.
followers
if
not
comment
.
anonymous
)
if
comment
.
comment_thread
.
subscribers
or
(
comment
.
author
.
followers
if
not
activity
.
anonymous
)
notification
=
Notification
.
new
(
notification_type:
"post_reply"
,
info:
{
...
...
models/observers/post_topic_observer.rb
View file @
e097ed98
...
...
@@ -8,13 +8,13 @@ class PostTopicObserver < Mongoid::Observer
def
self
.
generate_notifications
(
comment_thread
)
activity
=
Activity
.
new
activity
.
happend_at
=
comment_thread
.
created_at
activity
.
anonymous
=
comment_thread
.
anonymous
activity
.
anonymous
=
(
comment_thread
.
anonymous
||
comment_thread
.
anonymous_to_peers
)
activity
.
actor
=
comment_thread
.
author
#activity.target_id = comment_thread.commentable.id
#activity.target_type = comment_thread.commentable._type
activity
.
activity_type
=
"post_topic"
activity
.
save!
if
comment_thread
.
commentable
.
subscribers
or
(
author
.
followers
if
not
anonymous
)
if
comment_thread
.
commentable
.
subscribers
or
(
author
.
followers
if
not
a
ctivity
.
a
nonymous
)
notification
=
Notification
.
new
(
notification_type:
"post_topic"
,
info:
{
...
...
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