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
58015e80
Commit
58015e80
authored
Jul 23, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make auto-subscribe an optional parameter instead of config
parent
c8e929cf
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
29 deletions
+18
-29
app.rb
+10
-2
config/application.yml
+0
-1
models/comment.rb
+2
-13
models/comment_thread.rb
+2
-13
spec/app_spec.rb
+4
-0
No files found.
app.rb
View file @
58015e80
...
...
@@ -31,8 +31,12 @@ end
post
'/api/v1/:commentable_id/threads'
do
|
commentable_id
|
thread
=
CommentThread
.
new
(
params
.
slice
(
*
%w[title body course_id]
).
merge
(
commentable_id:
commentable_id
))
thread
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
thread
.
author
=
author
thread
.
save!
if
params
[
"auto_subscribe"
]
author
.
subscribe
(
thread
)
end
thread
.
to_hash
.
to_json
end
...
...
@@ -50,8 +54,12 @@ end
post
'/api/v1/threads/:thread_id/comments'
do
|
thread_id
|
thread
=
CommentThread
.
find
(
thread_id
)
comment
=
thread
.
comments
.
new
(
params
.
slice
(
*
%w[body course_id]
))
comment
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
comment
.
author
=
author
comment
.
save!
if
params
[
"auto_subscribe"
]
author
.
subscribe
(
thread
)
end
comment
.
to_hash
.
to_json
end
...
...
config/application.yml
View file @
58015e80
level_limit
:
3
send_notifications_to_author
:
false
auto_subscribe_comment_threads
:
true
allow_anonymity
:
false
models/comment.rb
View file @
58015e80
...
...
@@ -21,7 +21,7 @@ class Comment < Content
validates_presence_of
:author
if
not
CommentService
.
config
[
"allow_anonymity"
]
before_destroy
:delete_descendants
# TODO async
after_create
:
handle_after_create
after_create
:
generate_notifications
def
self
.
hash_tree
(
nodes
)
nodes
.
map
{
|
node
,
sub_nodes
|
node
.
to_hash
.
merge
(
"children"
=>
hash_tree
(
sub_nodes
).
compact
)}
...
...
@@ -73,17 +73,6 @@ private
end
end
def
auto_subscribe_comment_thread
if
CommentService
.
config
[
"auto_subscribe_comment_threads"
]
and
author
author
.
subscribe
(
get_comment_thread
)
end
end
def
handle_after_create
generate_notifications
auto_subscribe_comment_thread
end
handle_asynchronously
:handle_after_create
handle_asynchronously
:generate_notifications
end
models/comment_thread.rb
View file @
58015e80
...
...
@@ -32,7 +32,7 @@ class CommentThread < Content
validates_presence_of
:commentable_id
validates_presence_of
:author
if
not
CommentService
.
config
[
"allow_anonymity"
]
after_create
:
handle_after_create
after_create
:
generate_notifications
def
commentable
Commentable
.
find
(
commentable_id
)
...
...
@@ -86,16 +86,5 @@ private
end
end
def
auto_subscribe_comment_thread
if
CommentService
.
config
[
"auto_subscribe_comment_threads"
]
and
author
author
.
subscribe
(
self
)
end
end
def
handle_after_create
generate_notifications
auto_subscribe_comment_thread
end
handle_asynchronously
:handle_after_create
handle_asynchronously
:generate_notifications
end
spec/app_spec.rb
View file @
58015e80
...
...
@@ -22,6 +22,7 @@ def init_without_subscriptions
thread
=
CommentThread
.
new
(
title:
"I can't solve this problem"
,
body:
"can anyone help me?"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
)
thread
.
author
=
user
thread
.
save!
user
.
subscribe
(
thread
)
comment
=
thread
.
comments
.
new
(
body:
"this problem is so easy"
,
course_id:
"1"
)
comment
.
author
=
user
...
...
@@ -43,6 +44,7 @@ def init_without_subscriptions
thread
=
CommentThread
.
new
(
title:
"This problem is wrong"
,
body:
"it is unsolvable"
,
course_id:
"2"
,
commentable_id:
commentable
.
id
)
thread
.
author
=
user
thread
.
save!
user
.
subscribe
(
thread
)
comment
=
thread
.
comments
.
new
(
body:
"how do you know?"
,
course_id:
"1"
)
comment
.
author
=
user
...
...
@@ -89,6 +91,7 @@ def init_with_subscriptions
thread
=
CommentThread
.
new
(
title:
"I can't solve this problem"
,
body:
"can anyone help me?"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
)
thread
.
author
=
user1
user1
.
subscribe
(
thread
)
user2
.
subscribe
(
thread
)
thread
.
save!
...
...
@@ -106,6 +109,7 @@ def init_with_subscriptions
thread
=
CommentThread
.
new
(
title:
"This problem is wrong"
,
body:
"it is unsolvable"
,
course_id:
"2"
,
commentable_id:
commentable
.
id
)
thread
.
author
=
user2
user2
.
subscribe
(
thread
)
thread
.
save!
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