Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit f2d92b8

Browse files
author
Alicia Matsumoto
committed
remove debug
1 parent 8c2929e commit f2d92b8

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

src/dispatch/auth/permissions.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,37 +335,45 @@ def has_required_permissions(
335335
request=request,
336336
)
337337

338+
338339
class IncidentEditPermissionForTasks(BasePermission):
339340
"""
340341
Permissions dependency to apply incident edit permissions to task-based requests.
341342
"""
343+
342344
def has_required_permissions(self, request: Request) -> bool:
343345
incident_id = None
344346
# for task creation, retrieve the incident id from the payload
345-
if request.method == 'POST' and hasattr(request, '_body'):
347+
if request.method == "POST" and hasattr(request, "_body"):
346348
try:
347349
import json
350+
348351
body = json.loads(request._body.decode())
349-
incident_id = body['incident']['id']
352+
incident_id = body["incident"]["id"]
350353
except (json.JSONDecodeError, KeyError, AttributeError):
351-
log.error("Encountered create_task request without expected incident ID. Cannot properly ascertain incident permissions.")
354+
log.error(
355+
"Encountered create_task request without expected incident ID. Cannot properly ascertain incident permissions."
356+
)
352357
return False
353-
else: # otherwise, retrieve via the task id
358+
else: # otherwise, retrieve via the task id
354359
pk = PrimaryKeyModel(id=request.path_params["task_id"])
355360
current_task = task_service.get(db_session=request.state.db, task_id=pk.id)
356361
if not current_task or not current_task.incident:
357362
return False
358363
incident_id = current_task.incident.id
359364

360-
print(incident_id)
361365
# minimal object with the attributes required for IncidentViewPermission
362-
incident_request = type('IncidentRequest', (), {
363-
'path_params': {**request.path_params, 'incident_id': incident_id},
364-
'state': request.state
365-
})()
366+
incident_request = type(
367+
"IncidentRequest",
368+
(),
369+
{
370+
"path_params": {**request.path_params, "incident_id": incident_id},
371+
"state": request.state,
372+
},
373+
)()
366374

367375
# copy necessary request attributes
368-
for attr in ['headers', 'method', 'url', 'query_params']:
376+
for attr in ["headers", "method", "url", "query_params"]:
369377
if hasattr(request, attr):
370378
setattr(incident_request, attr, getattr(request, attr))
371379

src/dispatch/task/views.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44

55
from dispatch.auth.service import CurrentUser
6-
from dispatch.auth.permissions import (
7-
PermissionsDependency,
8-
IncidentEditPermissionForTasks
9-
)
6+
from dispatch.auth.permissions import PermissionsDependency, IncidentEditPermissionForTasks
107
from dispatch.common.utils.views import create_pydantic_include
118
from dispatch.database.core import DbSession
129
from dispatch.database.service import CommonParameters, search_filter_sort_paginate
@@ -47,7 +44,12 @@ def get_tasks(common: CommonParameters, include: list[str] = Query([], alias="in
4744
return json.loads(TaskPagination(**pagination).json())
4845

4946

50-
@router.post("", response_model=TaskRead, tags=["tasks"], dependencies=[Depends(PermissionsDependency([IncidentEditPermissionForTasks]))])
47+
@router.post(
48+
"",
49+
response_model=TaskRead,
50+
tags=["tasks"],
51+
dependencies=[Depends(PermissionsDependency([IncidentEditPermissionForTasks]))],
52+
)
5153
def create_task(
5254
db_session: DbSession,
5355
task_in: TaskCreate,
@@ -68,12 +70,12 @@ def create_task(
6870
return task
6971

7072

71-
@router.post("/ticket/{task_id}", tags=["tasks"], dependencies=[Depends(PermissionsDependency([IncidentEditPermissionForTasks]))])
72-
def create_ticket(
73-
db_session: DbSession,
74-
task_id: PrimaryKey,
75-
current_user: CurrentUser
76-
):
73+
@router.post(
74+
"/ticket/{task_id}",
75+
tags=["tasks"],
76+
dependencies=[Depends(PermissionsDependency([IncidentEditPermissionForTasks]))],
77+
)
78+
def create_ticket(db_session: DbSession, task_id: PrimaryKey, current_user: CurrentUser):
7779
"""Creates a ticket for an existing task."""
7880
task = get(db_session=db_session, task_id=task_id)
7981
if not task:
@@ -84,8 +86,15 @@ def create_ticket(
8486
return create_task_ticket(task=task, db_session=db_session)
8587

8688

87-
@router.put("/{task_id}", response_model=TaskRead, tags=["tasks"], dependencies=[Depends(PermissionsDependency([IncidentEditPermissionForTasks]))])
88-
def update_task(db_session: DbSession, task_id: PrimaryKey, task_in: TaskUpdate, current_user: CurrentUser):
89+
@router.put(
90+
"/{task_id}",
91+
response_model=TaskRead,
92+
tags=["tasks"],
93+
dependencies=[Depends(PermissionsDependency([IncidentEditPermissionForTasks]))],
94+
)
95+
def update_task(
96+
db_session: DbSession, task_id: PrimaryKey, task_in: TaskUpdate, current_user: CurrentUser
97+
):
8998
"""Updates an existing task."""
9099
task = get(db_session=db_session, task_id=task_id)
91100
if not task:
@@ -109,7 +118,12 @@ def update_task(db_session: DbSession, task_id: PrimaryKey, task_in: TaskUpdate,
109118
return task
110119

111120

112-
@router.delete("/{task_id}", response_model=None, tags=["tasks"], dependencies=[Depends(PermissionsDependency([IncidentEditPermissionForTasks]))])
121+
@router.delete(
122+
"/{task_id}",
123+
response_model=None,
124+
tags=["tasks"],
125+
dependencies=[Depends(PermissionsDependency([IncidentEditPermissionForTasks]))],
126+
)
113127
def delete_task(db_session: DbSession, task_id: PrimaryKey, current_user: CurrentUser):
114128
"""Deletes an existing task."""
115129
task = get(db_session=db_session, task_id=task_id)

0 commit comments

Comments
 (0)