Skip to content

Commit

Permalink
Merge pull request #783 from frankrousseau/master
Browse files Browse the repository at this point in the history
[tasks] Add a route to get all tasks for open projects
  • Loading branch information
EvanBldy authored Mar 8, 2024
2 parents 08da265 + 1053e1f commit 138eb65
Show file tree
Hide file tree
Showing 5 changed files with 435 additions and 6 deletions.
19 changes: 14 additions & 5 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,21 @@ def generate_fixture_project_no_preview_tree(self):
)

def generate_fixture_asset(
self, name="Tree", description="Description Tree", asset_type_id=None
self, name="Tree",
description="Description Tree",
asset_type_id=None,
project_id=None,
):
if asset_type_id is None:
asset_type_id = self.asset_type.id

if project_id is None:
project_id = self.project_id

self.asset = Entity.create(
name=name,
description=description,
project_id=self.project.id,
project_id=project_id,
entity_type_id=asset_type_id,
)
return self.asset
Expand Down Expand Up @@ -500,7 +506,7 @@ def generate_fixture_user_vendor(self):
def generate_fixture_person(
self,
first_name="John",
last_name="Doe",
last_name="Doe",
desktop_login="john.doe",
email="[email protected]",
):
Expand Down Expand Up @@ -655,20 +661,23 @@ def generate_fixture_assigner(self):
return self.assigner

def generate_fixture_task(
self, name="Master", entity_id=None, task_type_id=None
self, name="Master", entity_id=None, task_type_id=None, project_id=None
):
if entity_id is None:
entity_id = self.asset.id

if task_type_id is None:
task_type_id = self.task_type.id

if project_id is None:
project_id = self.project.id

start_date = fields.get_date_object("2017-02-20")
due_date = fields.get_date_object("2017-02-28")
real_start_date = fields.get_date_object("2017-02-22")
self.task = Task.create(
name=name,
project_id=self.project.id,
project_id=project_id,
task_type_id=task_type_id,
task_status_id=self.task_status.id,
entity_id=entity_id,
Expand Down
60 changes: 60 additions & 0 deletions tests/tasks/test_route_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,63 @@ def test_update_entity_main_preview_from_task(self):
)
entity = self.get("/data/entities/%s" % task["entity_id"])
self.assertEqual(entity["preview_file_id"], preview_file["id"])

def test_open_tasks(self):
self.generate_fixture_task()
task_id = str(self.task.id)
self.task.update({"task_status_id": self.wip_status_id})
self.generate_fixture_asset_types()
self.generate_fixture_asset_character()
self.generate_fixture_task(
entity_id=self.asset_character.id
)

animation_id = str(self.task_type_animation.id)
self.generate_fixture_shot_task()
self.generate_fixture_shot("SHOT_002")
self.generate_fixture_shot_task()
self.generate_fixture_shot("SHOT_003")
self.generate_fixture_shot_task()

tasks = self.get("/data/tasks/open-tasks")
self.assertEqual(len(tasks["data"]), 5)

self.generate_fixture_project_closed_status()
self.generate_fixture_project_closed()
asset = self.generate_fixture_asset(
project_id=self.project_closed.id
)
self.generate_fixture_task(
entity_id=asset.id,
project_id=self.project_closed.id
)
tasks = self.get("/data/tasks/open-tasks")
self.assertEqual(len(tasks["data"]), 5)

self.generate_fixture_project_standard()
self.generate_fixture_asset_standard()
self.generate_fixture_task_standard()
tasks = self.get("/data/tasks/open-tasks")
self.assertEqual(len(tasks["data"]), 6)

tasks = self.get("/data/tasks/open-tasks?project_id=%s" % self.project.id)
self.assertEqual(len(tasks["data"]), 5)

tasks = self.get("/data/tasks/open-tasks?project_id=%s&limit=3" % self.project.id)
self.assertEqual(len(tasks["data"]), 3)

tasks = self.get("/data/tasks/open-tasks?project_id=%s&limit=3&page=2" % self.project.id)
self.assertEqual(len(tasks["data"]), 2)

tasks = self.get("/data/tasks/open-tasks?task_type_id=%s" % animation_id)
self.assertEqual(len(tasks["data"]), 3)

tasks = self.get("/data/tasks/open-tasks?task_status_id=%s" % self.wip_status_id)
self.assertEqual(len(tasks["data"]), 1)

jane = self.generate_fixture_person("Jane", "Doe", "jane.doe", "[email protected]")
data = {"person_id": jane.id}
self.put("/actions/tasks/%s/assign" % task_id, data, 200)
self.put("/actions/tasks/%s/assign" % self.shot_task.id, data, 200)
tasks = self.get("/data/tasks/open-tasks?person_id=%s" % jane.id)
self.assertEqual(len(tasks["data"]), 2)
2 changes: 2 additions & 0 deletions zou/app/blueprints/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from zou.app.utils.api import configure_api_from_blueprint

from zou.app.blueprints.tasks.resources import (
OpenTasksResource,
TaskFullResource,
TaskForEntityResource,
DeleteTasksResource,
Expand Down Expand Up @@ -38,6 +39,7 @@


routes = [
("/data/tasks/open-tasks", OpenTasksResource),
("/data/tasks/<task_id>/comments", TaskCommentsResource),
("/data/tasks/<task_id>/comments/<comment_id>", TaskCommentResource),
("/data/tasks/<task_id>/previews", TaskPreviewsResource),
Expand Down
125 changes: 125 additions & 0 deletions zou/app/blueprints/tasks/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,3 +1568,128 @@ def get(self):
"""
permissions.check_admin_permissions()
return tasks_service.get_persons_tasks_dates()


class OpenTasksResource(Resource, ArgsMixin):
"""
Return all tasks related to open projects.
"""

@jwt_required()
def get(self):
"""
Return all tasks related to open projects.
---
tags:
- Tasks
parameters:
- in: query
name: project_id
description: Filter tasks on given project ID
type: string
format: UUID
x-example: a24a6ea4-ce75-4665-a070-57453082c25
- in: query
name: task_status_id
description: Filter tasks on given task status ID
type: string
format: UUID
x-example: a24a6ea4-ce75-4665-a070-57453082c25
- in: query
name: task_type_id
description: Filter tasks on given task type ID ID
type: string
format: UUID
x-example: a24a6ea4-ce75-4665-a070-57453082c25
- in: query
name: person_id
description: Filter tasks on given person ID
type: string
format: UUID
x-example: a24a6ea4-ce75-4665-a070-57453082c25
- in: query
name: start_date
description: Filter tasks posterior to given start date
type: string
format: date
x-example: "2022-07-12"
- in: query
name: due_date
description: Filter tasks anterior to given due date
type: string
format: date
x-example: "2022-07-12"
- in: query
name: priority
description: Filter tasks on given priority
type: integer
x-example: "3"
- in: query
name: page
description: Page number
type: integer
x-example: 1
default: 1
- in: query
name: limit
description: Number of tasks per page
type: integer
x-example: 100
default: 100
responses:
200:
schema:
type: object
properties:
data:
type: array
description: List of tasks
stats:
type: object
properties:
total:
type: integer
description: Total number of tasks
total_duration:
type: integer
description: Total duration of tasks in minutes
total_estimation:
type: integer
description: Total estimation of tasks in minutes
status:
type: object
description: Number of tasks per status
limit:
type: integer
description: Number of tasks per page
page:
type: integer
description: Page number
is_more:
type: boolean
description: True if there are more tasks to retrieve
"""
args = self.get_args([
("task_type_id", None, False, str),
("project_id", None, False, str),
("person_id", None, False, str),
("task_status_id", None, False, str),
("start_date", None, False, str),
("due_date", None, False, str),
("priority", None, False, str),
("group_by", None, False, str),
("page", None, False, int),
("limit", 100, False, int),
])
return tasks_service.get_open_tasks(
task_type_id=args["task_type_id"],
project_id=args["project_id"],
person_id=args["person_id"],
task_status_id=args["task_status_id"],
start_date=args["start_date"],
due_date=args["due_date"],
priority=args["priority"],
page=args["page"],
limit=args["limit"]
)
Loading

0 comments on commit 138eb65

Please sign in to comment.