Skip to content

Commit

Permalink
[FIX] Api v2 endpoint to get task was not working anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
c8y3 committed Jan 10, 2025
1 parent 05a4060 commit 1276c3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
29 changes: 0 additions & 29 deletions source/app/blueprints/rest/v2/cases/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
from flask import Blueprint
from flask import request

from app.blueprints.rest.endpoints import response_api_not_found
from app.blueprints.rest.endpoints import response_api_error
from app.blueprints.rest.endpoints import response_api_created
from app.blueprints.access_controls import ac_api_return_access_denied
from app.blueprints.access_controls import ac_api_requires
from app.schema.marshables import CaseTaskSchema
from app.business.errors import ObjectNotFoundError
from app.business.errors import BusinessProcessingError
from app.business.tasks import tasks_create
from app.business.tasks import tasks_get
from app.models.authorization import CaseAccessLevel
from app.iris_engine.access_control.utils import ac_fast_check_current_user_has_case_access

Expand All @@ -55,29 +52,3 @@ def add_case_task(case_id):
return response_api_created(task_schema.dump(case))
except BusinessProcessingError as e:
return response_api_error(e.get_message())


@case_tasks_bp.get('/<int:identifier>')
@ac_api_requires()
def get_case_task(case_id, identifier):
"""
Handles getting a task from a case.
Args:
case_id (int): The case ID
identifier (int): The task ID
"""

try:
task = tasks_get(identifier)

if task.task_case_id != case_id:
raise ObjectNotFoundError()

if not ac_fast_check_current_user_has_case_access(task.task_case_id, [CaseAccessLevel.read_only, CaseAccessLevel.full_access]):
return ac_api_return_access_denied(caseid=task.task_case_id)

task_schema = CaseTaskSchema()
return response_api_created(task_schema.dump(task))
except ObjectNotFoundError:
return response_api_not_found()
26 changes: 20 additions & 6 deletions source/app/blueprints/rest/v2/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from flask import Blueprint

from app.blueprints.rest.endpoints import response_api_not_found
from app.blueprints.rest.endpoints import response_api_created
from app.blueprints.rest.endpoints import response_api_deleted
from app.blueprints.rest.endpoints import response_api_error
from app.blueprints.access_controls import ac_api_requires
Expand All @@ -28,22 +29,35 @@
from app.business.errors import ObjectNotFoundError
from app.business.errors import BusinessProcessingError
from app.models.authorization import CaseAccessLevel
from app.schema.marshables import CaseTaskSchema
from app.iris_engine.access_control.utils import ac_fast_check_current_user_has_case_access


tasks_blueprint = Blueprint('tasks',
__name__,
url_prefix='/tasks')


@tasks_blueprint.get('/<int:identifier>')
@ac_api_requires()
def get_case_task(identifier):

try:
task = tasks_get(identifier)

if not ac_fast_check_current_user_has_case_access(task.task_case_id, [CaseAccessLevel.read_only, CaseAccessLevel.full_access]):
return ac_api_return_access_denied(caseid=task.task_case_id)

task_schema = CaseTaskSchema()
# TODO should be response_api_success => add a test
return response_api_created(task_schema.dump(task))
except ObjectNotFoundError:
return response_api_not_found()


@tasks_blueprint.delete('/<int:identifier>')
@ac_api_requires()
def delete_case_task(identifier):
"""
Handle deleting a task from a case
Args:
identifier (int): The task identifier
"""

try:
task = tasks_get(identifier)
Expand Down

0 comments on commit 1276c3d

Please sign in to comment.