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
12661104
Commit
12661104
authored
Sep 15, 2014
by
Christina Roberts
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #118 from edx/christina/notifications_group_id
Add group_id to payload from notifications.
parents
2d2a05a1
f78fdd94
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
19 deletions
+63
-19
lib/helpers.rb
+5
-2
spec/api/notifications_spec.rb
+58
-17
No files found.
lib/helpers.rb
View file @
12661104
...
@@ -255,14 +255,14 @@ helpers do
...
@@ -255,14 +255,14 @@ helpers do
end
end
end
end
def
notifications_by_date_range_and_user_ids
start_date_time
,
end_date_time
,
user_ids
def
notifications_by_date_range_and_user_ids
(
start_date_time
,
end_date_time
,
user_ids
)
#given a date range and a user, find all of the notifiable content
#given a date range and a user, find all of the notifiable content
#key by thread id, and return notification messages for each user
#key by thread id, and return notification messages for each user
#first, find the subscriptions for the users
#first, find the subscriptions for the users
subscriptions
=
Subscription
.
where
(
:subscriber_id
.
in
=>
user_ids
)
subscriptions
=
Subscription
.
where
(
:subscriber_id
.
in
=>
user_ids
)
#get the th
h
read ids
#get the thread ids
thread_ids
=
subscriptions
.
collect
{
|
t
|
t
.
source_id
}.
uniq
thread_ids
=
subscriptions
.
collect
{
|
t
|
t
.
source_id
}.
uniq
#find all the comments
#find all the comments
...
@@ -308,6 +308,9 @@ helpers do
...
@@ -308,6 +308,9 @@ helpers do
t
[
"content"
]
=
[]
t
[
"content"
]
=
[]
t
[
"title"
]
=
current_thread
.
title
t
[
"title"
]
=
current_thread
.
title
t
[
"commentable_id"
]
=
current_thread
.
commentable_id
t
[
"commentable_id"
]
=
current_thread
.
commentable_id
unless
current_thread
.
group_id
.
nil?
t
[
"group_id"
]
=
current_thread
.
group_id
end
else
else
t
=
notification_map
[
u
][
c
.
course_id
][
c
.
comment_thread_id
.
to_s
]
t
=
notification_map
[
u
][
c
.
course_id
][
c
.
comment_thread_id
.
to_s
]
end
end
...
...
spec/api/notifications_spec.rb
View file @
12661104
...
@@ -8,23 +8,43 @@ describe "app" do
...
@@ -8,23 +8,43 @@ describe "app" do
set_api_key_header
set_api_key_header
end
end
describe
"POST /api/v1/notifications"
do
def
create_thread
(
user
,
options
=
{})
it
"returns notifications by class and user"
do
# Create a CommentThread with the given user.
start_time
=
Time
.
now
# Can optionally specify a cohort group_id via options.
user
=
User
.
create
(
:external_id
=>
1
,
:username
=>
"example"
)
# Returns the created CommentThread.
commentable
=
Commentable
.
new
(
"question_1"
)
commentable
=
Commentable
.
new
(
"question_1"
)
random_string
=
(
0
...
8
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
random_string
=
(
0
...
8
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
thread
=
CommentThread
.
new
(
title:
"Test title"
,
body:
"elephant otter"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
,
comments_text_dummy:
random_string
)
thread
=
CommentThread
.
new
(
title:
"Test title"
,
body:
"elephant otter"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
,
comments_text_dummy:
random_string
)
thread
.
thread_type
=
:discussion
thread
.
thread_type
=
:discussion
thread
.
author
=
user
thread
.
author
=
user
if
options
[
:group_id
]
thread
.
group_id
=
options
[
:group_id
]
end
thread
.
save!
thread
.
save!
subscription
=
Subscription
.
create
({
:subscriber_id
=>
user
.
_id
.
to_s
,
:source_id
=>
thread
.
_id
.
to_s
})
return
thread
end
def
get_thread_notification
(
comment_body
,
options
=
{})
# Creates a thread and comment with the specified comment_body.
# Can optionally specify a cohort group_id via options.
# Calls the notifications API to retrieve the notification for the thread
# and returns the response hash for the single comment thread within the course.
# Keys for the returned hash: content, title, commentable_id, group_id (only present if cohorted).
start_time
=
Time
.
now
user
=
User
.
create
(
:external_id
=>
1
,
:username
=>
"example"
)
thread
=
create_thread
(
user
,
options
)
subscription
=
Subscription
.
create
(
:subscriber_id
=>
user
.
_id
.
to_s
,
:source_id
=>
thread
.
_id
.
to_s
)
dummy
=
random_string
=
(
0
..
5
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
comment
=
Comment
.
new
comment
=
Comment
.
new
comment
.
comment_thread_id
=
thread
.
id
comment
.
comment_thread_id
=
thread
.
id
comment
.
body
=
dumm
y
comment
.
body
=
comment_bod
y
comment
.
author_id
=
user
.
id
comment
.
author_id
=
user
.
id
comment
.
course_id
=
'test course'
comment
.
course_id
=
'test course'
comment
.
save!
comment
.
save!
...
@@ -33,10 +53,36 @@ describe "app" do
...
@@ -33,10 +53,36 @@ describe "app" do
end_time
=
Time
.
now
end_time
=
Time
.
now
post
"/api/v1/notifications"
,
from:
CGI
::
escape
(
start_time
.
to_s
),
to:
CGI
::
escape
(
end_time
.
to_s
),
user_ids:
subscription
.
subscriber_id
post
(
"/api/v1/notifications"
,
{
from:
CGI
::
escape
(
start_time
.
to_s
),
to:
CGI
::
escape
(
end_time
.
to_s
),
user_ids:
subscription
.
subscriber_id
}
)
last_response
.
should
be_ok
last_response
.
should
be_ok
last_response
.
body
.
to_s
.
include?
(
dummy
).
should
==
true
response_hash
=
JSON
.
parse
(
last_response
.
body
)
return
response_hash
[
user
.
id
][
comment
.
course_id
][
thread
.
id
.
to_s
]
end
describe
"POST /api/v1/notifications"
do
it
"returns notifications by class and user"
do
expected_comment_body
=
random_string
=
(
0
..
5
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
thread_notification
=
get_thread_notification
(
expected_comment_body
)
actual_comment_body
=
thread_notification
[
"content"
][
0
][
"body"
]
actual_comment_body
.
should
eq
(
expected_comment_body
)
end
it
"contains cohort group_id if defined"
do
thread_notification
=
get_thread_notification
(
"dummy comment content"
,
:group_id
=>
1974
)
thread_notification
[
"group_id"
].
should
be
(
1974
)
end
it
"does not contain cohort group_id if not defined"
do
thread_notification
=
get_thread_notification
(
"dummy comment content"
)
thread_notification
.
has_key?
(
"group_id"
).
should
be_false
end
end
it
"returns only threads subscribed to by user"
do
it
"returns only threads subscribed to by user"
do
...
@@ -44,16 +90,11 @@ describe "app" do
...
@@ -44,16 +90,11 @@ describe "app" do
# first make a dummy thread and comment and a subscription
# first make a dummy thread and comment and a subscription
commentable
=
Commentable
.
new
(
"question_1"
)
commentable
=
Commentable
.
new
(
"question_1"
)
user
=
User
.
create
(
:external_id
=>
1
,
:username
=>
"example"
)
user
=
User
.
create
(
:external_id
=>
1
,
:username
=>
"example"
)
random_string
=
(
0
...
8
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
thread
=
create_thread
(
user
)
thread
=
CommentThread
.
new
(
title:
"Test title"
,
body:
"elephant otter"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
,
comments_text_dummy:
random_string
)
thread
.
thread_type
=
:discussion
thread
.
author
=
user
thread
.
save!
subscription
=
Subscription
.
create
({
:subscriber_id
=>
user
.
_id
.
to_s
,
:source_id
=>
thread
.
_id
.
to_s
})
subscription
=
Subscription
.
create
({
:subscriber_id
=>
user
.
_id
.
to_s
,
:source_id
=>
thread
.
_id
.
to_s
})
comment
=
Comment
.
new
(
body:
random_string
,
course_id:
"1"
,
commentable_id:
commentable
.
id
)
comment
=
Comment
.
new
(
body:
"dummy body text"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
)
comment
.
author
=
user
comment
.
author
=
user
comment
.
comment_thread
=
thread
comment
.
comment_thread
=
thread
comment
.
save!
comment
.
save!
...
...
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