Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@

threads_data = handle_threads_query(
threads,
params["user_id"],
user_id,
params["course_id"],
get_group_ids_from_params(params),
params["author_id"],
Expand All @@ -173,7 +173,7 @@
raw_query: raw_query
)

if sort_key == 'user_activity'
if raw_query
Comment thread
xitij2000 marked this conversation as resolved.
num_pages = [1, (threads_data.count / per_page.to_f).ceil].max
page = [num_pages, [1, page].max].min

Expand Down
4 changes: 3 additions & 1 deletion lib/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ def handle_threads_query(
comment_threads.batch_size(CommentService.config["manual_pagination_batch_size"].to_i).each do |thread|
thread_key = thread._id.to_s
if !read_dates.has_key?(thread_key) || read_dates[thread_key] < thread.last_activity_at
if skipped >= to_skip or raw_query
if raw_query
threads << thread
elsif skipped >= to_skip
if threads.length == per_page
has_more = true
break
Expand Down
119 changes: 70 additions & 49 deletions spec/api/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,55 +236,76 @@ def thread_result(user_id, params)
end
end

it "filters by group_id" do
@threads["t1"].author = @users["u100"]
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_id: 42
expect(rs.length).to eq(2)
@threads["t1"].group_id = 43
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_id: 42
expect(rs.length).to eq(1)
@threads["t1"].group_id = 42
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_id: 42
expect(rs.length).to eq(2)
end

it "filters by group_ids" do
@threads["t1"].author = @users["u100"]
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_ids: "42"
expect(rs.length).to eq(2)
@threads["t1"].group_id = 43
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_ids: "42"
expect(rs.length).to eq(1)
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_ids: "42,43"
expect(rs.length).to eq(2)
end

it "does not return threads in which the user has only participated anonymously" do
@comments["t3 c4"].author = @users["u100"]
@comments["t3 c4"].anonymous_to_peers = true
@comments["t3 c4"].save!
@comments["t5 c1"].author = @users["u100"]
@comments["t5 c1"].anonymous = true
@comments["t5 c1"].save!
rs = thread_result 100, course_id: "xyz"
expect(rs.length).to eq(1)
check_thread_result_json(@users["u100"], @threads["t0"], rs.first)
end

it "only returns threads from the specified course" do
@threads.each do |k, v|
v.author = @users["u100"]
v.save!
end
@threads["t9"].course_id = "zzz"
@threads["t9"].save!
rs = thread_result 100, course_id: "xyz"
expect(rs.length).to eq(9)
context 'filtering' do

it "filters by unread", :new => true do
# All 10 threads are are assigned to the requesting user
(1...10).each { |tid|
@threads["t#{tid}"].author = @users["u100"]
@threads["t#{tid}"].save!
}
# However one of them is marked as read
@users["u100"].mark_as_read(@threads["t3"])
# The results should include 9 entries, and exclude t3 which is marked as read.
rs = thread_result 100, course_id: DFLT_COURSE_ID, unread: true, per_page: 5
expect(rs.length).to eq(5)
expect(rs).not_to include have_attributes(:title => "t3")
rs2 = thread_result 100, course_id: DFLT_COURSE_ID, unread: true, per_page: 5, page: 2
expect(rs2.length).to eq(4)
expect(rs2).not_to include have_attributes(:title => "t3")
end

it "filters by group_id" do
@threads["t1"].author = @users["u100"]
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_id: 42
expect(rs.length).to eq(2)
@threads["t1"].group_id = 43
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_id: 42
expect(rs.length).to eq(1)
@threads["t1"].group_id = 42
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_id: 42
expect(rs.length).to eq(2)
end

it "filters by group_ids" do
@threads["t1"].author = @users["u100"]
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_ids: "42"
expect(rs.length).to eq(2)
@threads["t1"].group_id = 43
@threads["t1"].save!
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_ids: "42"
expect(rs.length).to eq(1)
rs = thread_result 100, course_id: DFLT_COURSE_ID, group_ids: "42,43"
expect(rs.length).to eq(2)
end

it "does not return threads in which the user has only participated anonymously" do
@comments["t3 c4"].author = @users["u100"]
@comments["t3 c4"].anonymous_to_peers = true
@comments["t3 c4"].save!
@comments["t5 c1"].author = @users["u100"]
@comments["t5 c1"].anonymous = true
@comments["t5 c1"].save!
rs = thread_result 100, course_id: "xyz"
expect(rs.length).to eq(1)
check_thread_result_json(@users["u100"], @threads["t0"], rs.first)
end

it "only returns threads from the specified course" do
@threads.each do |k, v|
v.author = @users["u100"]
v.save!
end
@threads["t9"].course_id = "zzz"
@threads["t9"].save!
rs = thread_result 100, course_id: "xyz"
expect(rs.length).to eq(9)
end

end

context "sorting" do
Expand Down