From 6667c6e6b9aca1fa9c6d70cad986560aaaafda81 Mon Sep 17 00:00:00 2001 From: Yolanda Robla Date: Tue, 18 Nov 2014 11:35:44 +0100 Subject: [PATCH] Add API call to return task statuses /v1/task_statuses will return the list of task statuses to the webclient. They are still hardcoded as enum in server, but add the ability to return this enum to the webclient so we get rid of hardcoding that constants on the web side. In later steps we could replace the enum in the server for a proper table that can be maintained by admins, but it has some implications about how to group tasks in the api, how to make a difference between special states such as todo, merged, etc... Change-Id: I16cc7886f69fdefe05808af5035859fd818f3492 --- storyboard/api/v1/task_statuses.py | 38 ++++++++++++++++++++++++++++++ storyboard/api/v1/v1_controller.py | 2 ++ storyboard/api/v1/wmodels.py | 5 ++++ storyboard/db/api/tasks.py | 4 ++++ storyboard/db/models.py | 9 +++++-- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 storyboard/api/v1/task_statuses.py diff --git a/storyboard/api/v1/task_statuses.py b/storyboard/api/v1/task_statuses.py new file mode 100644 index 00000000..1938304e --- /dev/null +++ b/storyboard/api/v1/task_statuses.py @@ -0,0 +1,38 @@ +# Copyright (c) 2013 Mirantis Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from pecan import rest +from pecan.secure import secure +import wsmeext.pecan as wsme_pecan + +from storyboard.api.auth import authorization_checks as checks +from storyboard.api.v1.wmodels import TaskStatus +from storyboard.db.api import tasks as tasks_api + + +class TaskStatusesController(rest.RestController): + """Manages tasks statuses.""" + + @secure(checks.guest) + @wsme_pecan.wsexpose([TaskStatus]) + def get(self): + """Retrieve the possible task statuses + """ + statuses = tasks_api.task_get_statuses() + task_statuses = [] + for key, val in statuses.items(): + ts = TaskStatus(key=key, name=val) + task_statuses.append(ts) + return task_statuses diff --git a/storyboard/api/v1/v1_controller.py b/storyboard/api/v1/v1_controller.py index 97b44315..0c0b08a7 100644 --- a/storyboard/api/v1/v1_controller.py +++ b/storyboard/api/v1/v1_controller.py @@ -20,6 +20,7 @@ from storyboard.api.v1.stories import StoriesController from storyboard.api.v1.subscription_events import SubscriptionEventsController from storyboard.api.v1.subscriptions import SubscriptionsController from storyboard.api.v1.system_info import SystemInfoController +from storyboard.api.v1.task_statuses import TaskStatusesController from storyboard.api.v1.tasks import TasksController from storyboard.api.v1.teams import TeamsController from storyboard.api.v1.users import UsersController @@ -33,6 +34,7 @@ class V1Controller(object): teams = TeamsController() stories = StoriesController() tasks = TasksController() + task_statuses = TaskStatusesController() subscriptions = SubscriptionsController() subscription_events = SubscriptionEventsController() systeminfo = SystemInfoController() diff --git a/storyboard/api/v1/wmodels.py b/storyboard/api/v1/wmodels.py index 02b03fd2..62771640 100644 --- a/storyboard/api/v1/wmodels.py +++ b/storyboard/api/v1/wmodels.py @@ -329,3 +329,8 @@ class AccessToken(base.APIBase): user_id=1, access_token="a_unique_access_token", expires_in=3600) + + +class TaskStatus(base.APIBase): + key = wtypes.text + name = wtypes.text diff --git a/storyboard/db/api/tasks.py b/storyboard/db/api/tasks.py index 37cd96e6..c734e86c 100644 --- a/storyboard/db/api/tasks.py +++ b/storyboard/db/api/tasks.py @@ -88,3 +88,7 @@ def task_build_query(project_group_id, **kwargs): **kwargs) return query + + +def task_get_statuses(): + return models.Task.TASK_STATUSES diff --git a/storyboard/db/models.py b/storyboard/db/models.py index d4aa6b78..eecc8153 100644 --- a/storyboard/db/models.py +++ b/storyboard/db/models.py @@ -262,12 +262,17 @@ class Story(FullText, ModelBuilder, Base): class Task(FullText, ModelBuilder, Base): __fulltext_columns__ = ['title'] - _TASK_STATUSES = ('todo', 'inprogress', 'invalid', 'review', 'merged') + TASK_STATUSES = {'todo': 'Todo', + 'merged': 'Merged', + 'invalid': 'Invalid', + 'review': 'Review', + 'inprogress': 'Progress'} + _TASK_PRIORITIES = ('low', 'medium', 'high') creator_id = Column(Integer, ForeignKey('users.id')) title = Column(Unicode(100), nullable=True) - status = Column(Enum(*_TASK_STATUSES), default='todo') + status = Column(Enum(*TASK_STATUSES.keys()), default='todo') story_id = Column(Integer, ForeignKey('stories.id')) project_id = Column(Integer, ForeignKey('projects.id')) assignee_id = Column(Integer, ForeignKey('users.id'), nullable=True)