Commit 53045237 by Alan Boudreault Committed by Saqib

Add ability to query threads that are not associated with any group_id

parent 5abd5183
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>
<component name="InspectionProjectProfileManager">
<profile version="1.0" is_locked="false">
<option name="myName" value="Project Default" />
<option name="myLocal" value="false" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="3">
<item index="0" class="java.lang.String" itemvalue="distribute" />
<item index="1" class="java.lang.String" itemvalue="lxml" />
<item index="2" class="java.lang.String" itemvalue="nosedjango" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<value>
<list size="3">
<item index="0" class="java.lang.String" itemvalue="xblock.runtime.LmsUser.anonymous_student_id" />
<item index="1" class="java.lang.String" itemvalue="xblock.runtime.LmsUser.get_real_user" />
<item index="2" class="java.lang.String" itemvalue="xblock.runtime.LmsCourse.course_id" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="TaskInspection" enabled="true" level="INFO" enabled_by_default="true">
<option name="suppressedTasks">
<set>
<option value="CoffeeScript" />
<option value="HAML" />
</set>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.3.2+ (/usr/bin/python3m)" project-jdk-type="Python SDK" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/cs_comments_service.iml" filepath="$PROJECT_DIR$/.idea/cs_comments_service.iml" />
</modules>
</component>
</project>
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
......@@ -24,3 +24,4 @@ Ben McMorran <ben.mcmorran@gmail.com>
Bill DeRusha <bill@edx.org>
Brian Beggs <macdiesel@gmail.com>
Clinton Blackburn <cblackburn@edx.org>
Eugeny Kolpakov <eugeny.kolpakov@gmail.com>
......@@ -3,9 +3,13 @@ get "#{APIPREFIX}/threads" do # retrieve threads by course
threads = Content.where({"_type" => "CommentThread", "course_id" => params["course_id"]})
if params[:commentable_ids]
threads = threads.in({"commentable_id" => params[:commentable_ids].split(",")})
end
#if a group id is sent, then process the set of threads with that group id or with no group id
group_ids = get_group_ids_from_params(params)
if not group_ids.empty?
exclude_groups = value_to_boolean(params['exclude_groups'])
if exclude_groups
threads = threads.where({"group_id" => {"$exists" => false}})
elsif not group_ids.empty?
threads = threads.any_of(
{:group_id.in => group_ids},
{:group_id.exists => false},
......
......@@ -7,7 +7,7 @@ get "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
threads = Content.where({"_type" => "CommentThread", "commentable_id" => commentable_id})
if params["course_id"]
threads = threads.where({"course_id" => params["course_id"]})
threads = Content.where(_type:"CommentThread", commentable_id: commentable_id)
end
group_ids = get_group_ids_from_params(params)
if not group_ids.empty?
threads = threads.any_of(
......
get "#{APIPREFIX}/search/threads" do
local_params = params # Necessary for params to be available inside blocks
local_params['exclude_groups'] = value_to_boolean(local_params['exclude_groups'])
group_ids = get_group_ids_from_params(local_params)
context = local_params["context"] ? local_params["context"] : "course"
search_text = local_params["text"]
......@@ -27,7 +28,9 @@ get "#{APIPREFIX}/search/threads" do
{:term => {:context => context}}
]
if not group_ids.empty?
if local_params['exclude_groups']
filter :not, :exists => {:field => :group_id}
elsif not group_ids.empty?
if group_ids.length > 1
group_id_criteria = {:terms => {:group_id => group_ids}}
else
......
......@@ -141,6 +141,12 @@ describe "app" do
assert_response_contains(expected_ids)
end
it "with exclude_groups" do
get "/api/v1/search/threads", text: "text", exclude_groups: "true"
expected_ids = (0..29).find_all {|i| i % 5 == 0}
assert_response_contains(expected_ids)
end
it "by all filters combined" do
get "/api/v1/search/threads", text: "text", course_id: "test/course/id0", commentable_id: "commentable0", group_id: "1"
assert_response_contains([0, 6])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment