Stories can now be filtered by assignee_id
I expanded the story_api a bit to allow us to construct our story/task joins more dynamically, simply by passing in different dicts of filter parameters. Change-Id: Ie503022bb12f2951dab8e919dbe8844217522e17
This commit is contained in:
@@ -103,12 +103,14 @@ class StoriesController(rest.RestController):
|
||||
status_code=404)
|
||||
|
||||
@secure(checks.guest)
|
||||
@wsme_pecan.wsexpose([Story], int, int, int, unicode, unicode, unicode)
|
||||
def get_all(self, project_id=None, marker=None, limit=None,
|
||||
status=None, title=None, description=None):
|
||||
@wsme_pecan.wsexpose([Story], int, int, int, int, unicode, unicode,
|
||||
unicode)
|
||||
def get_all(self, project_id=None, assignee_id=None, marker=None,
|
||||
limit=None, status=None, title=None, description=None):
|
||||
"""Retrieve definitions of all of the stories.
|
||||
|
||||
:param project_id: filter stories by project ID.
|
||||
:param assignee_id: filter stories by who they are assigned to.
|
||||
:param marker: The resource id where the page should begin.
|
||||
:param limit: The number of stories to retrieve.
|
||||
:param status: Only show stories with this particular status.
|
||||
@@ -127,16 +129,26 @@ class StoriesController(rest.RestController):
|
||||
if marker_story is None or marker_story.project_id != project_id:
|
||||
marker_story = None
|
||||
|
||||
# Build a dict of all story parameters by which we're filtering
|
||||
# stories.
|
||||
story_filters = {
|
||||
'title': title,
|
||||
'description': description,
|
||||
'status': status
|
||||
}
|
||||
|
||||
# Build a dict of all task parameters by which we're filtering stories.
|
||||
task_filters = {
|
||||
'project_id': project_id,
|
||||
'assignee_id': assignee_id
|
||||
}
|
||||
|
||||
stories = stories_api.story_get_all(marker=marker_story,
|
||||
limit=limit,
|
||||
project_id=project_id,
|
||||
status=status,
|
||||
title=title,
|
||||
description=description)
|
||||
story_count = stories_api.story_get_count(project_id=project_id,
|
||||
status=status,
|
||||
title=title,
|
||||
description=description)
|
||||
story_filters=story_filters,
|
||||
task_filters=task_filters)
|
||||
story_count = stories_api.story_get_count(story_filters=story_filters,
|
||||
task_filters=task_filters)
|
||||
|
||||
# Apply the query response headers.
|
||||
response.headers['X-Limit'] = str(limit)
|
||||
|
||||
@@ -22,68 +22,53 @@ def story_get(story_id):
|
||||
return api_base.entity_get(models.StorySummary, story_id)
|
||||
|
||||
|
||||
def story_get_all(marker=None, limit=None, project_id=None, **kwargs):
|
||||
if project_id:
|
||||
return _story_get_all_in_project(marker=marker,
|
||||
limit=limit,
|
||||
project_id=project_id,
|
||||
**kwargs)
|
||||
else:
|
||||
return api_base.entity_get_all(models.StorySummary,
|
||||
marker=marker, limit=limit,
|
||||
**kwargs)
|
||||
|
||||
|
||||
def story_get_count(project_id=None, **kwargs):
|
||||
if project_id:
|
||||
return _story_get_count_in_project(project_id, **kwargs)
|
||||
else:
|
||||
return api_base.entity_get_count(models.StorySummary, **kwargs)
|
||||
|
||||
|
||||
def _story_get_all_in_project(project_id, marker=None, limit=None, **kwargs):
|
||||
|
||||
session = api_base.get_session()
|
||||
|
||||
sub_query = api_base.model_query(models.Task.story_id, session) \
|
||||
.filter_by(project_id=project_id) \
|
||||
.distinct(True) \
|
||||
.subquery('project_tasks')
|
||||
|
||||
query = api_base.model_query(models.StorySummary, session)
|
||||
query = api_base.apply_query_filters(query, models.StorySummary, **kwargs)
|
||||
query = query.join(sub_query,
|
||||
models.StorySummary.id == sub_query.c.story_id)
|
||||
def story_get_all(marker=None, limit=None, story_filters=None,
|
||||
task_filters=None):
|
||||
query = _story_build_query(story_filters=story_filters,
|
||||
task_filters=task_filters)
|
||||
|
||||
# paginate the query
|
||||
query = api_base.paginate_query(query=query,
|
||||
model=models.StorySummary,
|
||||
limit=limit,
|
||||
sort_keys=['id'],
|
||||
marker=marker,
|
||||
sort_dir='asc')
|
||||
|
||||
return query.all()
|
||||
|
||||
|
||||
def _story_get_count_in_project(project_id, **kwargs):
|
||||
# Sanity check on input parameters
|
||||
kwargs = dict((k, v) for k, v in kwargs.iteritems() if v)
|
||||
|
||||
session = api_base.get_session()
|
||||
|
||||
sub_query = api_base.model_query(models.Task.story_id, session) \
|
||||
.filter_by(project_id=project_id) \
|
||||
.distinct(True) \
|
||||
.subquery('project_tasks')
|
||||
|
||||
query = api_base.model_query(models.StorySummary, session)
|
||||
query = api_base.apply_query_filters(query, models.StorySummary, **kwargs)
|
||||
query = query.join(sub_query,
|
||||
models.StorySummary.id == sub_query.c.story_id)
|
||||
|
||||
def story_get_count(story_filters=None, task_filters=None):
|
||||
query = _story_build_query(story_filters=story_filters,
|
||||
task_filters=task_filters)
|
||||
return query.count()
|
||||
|
||||
|
||||
def _story_build_query(story_filters=None, task_filters=None):
|
||||
# Input sanity checks
|
||||
if story_filters:
|
||||
story_filters = dict((k, v) for k, v in story_filters.iteritems() if v)
|
||||
if task_filters:
|
||||
task_filters = dict((k, v) for k, v in task_filters.iteritems() if v)
|
||||
|
||||
# Build the main story query
|
||||
query = api_base.model_query(models.StorySummary)
|
||||
query = api_base.apply_query_filters(query=query,
|
||||
model=models.StorySummary,
|
||||
**story_filters)
|
||||
|
||||
# Do we have task parameter queries we need to deal with?
|
||||
if task_filters and len(task_filters) > 0:
|
||||
subquery = api_base.model_query(models.Task.story_id) \
|
||||
.filter_by(**task_filters) \
|
||||
.distinct(True) \
|
||||
.subquery('project_tasks')
|
||||
|
||||
query = query.join(subquery,
|
||||
models.StorySummary.id == subquery.c.story_id)
|
||||
|
||||
return query
|
||||
|
||||
|
||||
def story_create(values):
|
||||
return api_base.entity_create(models.Story, values)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user