Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDCP-409] fix(search): Filters fail with Agenda ObjectId query #1530

Merged
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
31 changes: 30 additions & 1 deletion server/features/search_planning.feature
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Feature: Planning Search
]}
"""

@auth @wip
@auth
Scenario: Search by planning specific parameters
When we get "/events_planning_search?repo=planning&only_future=false&agendas=sports,finance"
Then we get list with 3 items
Expand Down Expand Up @@ -392,3 +392,32 @@ Feature: Planning Search
{"_id": "planning_4"}
]}
"""

@auth
Scenario: Search using Agenda with ObjectId
When we post to "agenda"
"""
[{
"name": "TestAgenda"
}]
"""
Then we get OK response
When we post to "planning"
"""
[{
"guid": "plan_with_agenda",
"headline": "test agenda",
"slugline": "slug_agenda",
"name": "name_agenda",
"planning_date": "2016-01-02T14:00:00+0000",
"agendas": ["#agenda._id#"]
}]
"""
Then we get OK response
When we get "/events_planning_search?repo=planning&only_future=false&agendas=#agenda._id#"
Then we get list with 1 items
"""
{"_items": [
{"_id": "plan_with_agenda"}
]}
"""
40 changes: 40 additions & 0 deletions server/features/search_planning_filters.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Feature: Planning Search Filters
@auth
Scenario: Search using Agenda with ObjectId
When we post to "agenda"
"""
[{
"name": "TestAgenda"
}]
"""
Then we get OK response
When we post to "planning"
"""
[{
"guid": "plan_with_agenda",
"headline": "test agenda",
"slugline": "slug_agenda",
"name": "name_agenda",
"planning_date": "2016-01-02T14:00:00+0000",
"agendas": ["#agenda._id#"]
}]
"""
Then we get OK response
When we post to "events_planning_filters"
"""
[{
"name": "Test",
"item_type": "planning",
"params": {
"agendas": ["#agenda._id#"]
}
}]
"""
Then we get OK response
When we get "/events_planning_search?repo=planning&only_future=false&filter_id=#events_planning_filters._id#"
Then we get list with 1 items
"""
{"_items": [
{"_id": "plan_with_agenda"}
]}
"""
8 changes: 7 additions & 1 deletion server/planning/search/queries/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ def str_to_date(value: Union[datetime, str]):


def search_item_ids(params: Dict[str, Any], query: elastic.ElasticQuery):
ids = str_to_array(params.get('item_ids'))
ids = [
str(item_id)
for item_id in str_to_array(params.get('item_ids'))
]
if len(ids):
query.must.append(
elastic.terms(
Expand Down Expand Up @@ -287,6 +290,9 @@ def construct_search_query(

if len(filter_params):
query = elastic.ElasticQuery()

# Set `only_future` to False as `construct_query` with request params will add this if neccessary
filter_params['only_future'] = False
filter_query = construct_query(filter_params, filters)

remove_filter_params_from_query(filter_params, params)
Expand Down
5 changes: 4 additions & 1 deletion server/planning/search/queries/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def search_reference(params: Dict[str, Any], query: elastic.ElasticQuery):


def search_source(params: Dict[str, Any], query: elastic.ElasticQuery):
sources = str_to_array(params.get('source'))
sources = [
str(source_id)
for source_id in str_to_array(params.get('source'))
]

if len(sources):
query.must.append(
Expand Down
10 changes: 8 additions & 2 deletions server/planning/search/queries/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def search_planning(_: Dict[str, Any], query: elastic.ElasticQuery):


def search_agendas(params: Dict[str, Any], query: elastic.ElasticQuery):
agendas = str_to_array(params.get('agendas'))
agendas = [
str(agenda_id)
for agenda_id in str_to_array(params.get('agendas'))
]

if len(agendas):
query.must.append(
Expand Down Expand Up @@ -134,7 +137,10 @@ def search_featured(params: Dict[str, Any], query: elastic.ElasticQuery):


def search_by_events(params: Dict[str, Any], query: elastic.ElasticQuery):
event_ids = str_to_array(params.get('event_item'))
event_ids = [
str(event_id)
for event_id in str_to_array(params.get('event_item'))
]
num_ids = len(event_ids)

if num_ids == 1:
Expand Down