diff --git a/api/routers/v1/timelog.py b/api/routers/v1/timelog.py index dd873e344..33e9d8975 100644 --- a/api/routers/v1/timelog.py +++ b/api/routers/v1/timelog.py @@ -35,17 +35,18 @@ @router.get( - "/task_types/", + "/task_types", response_model=List[TaskTypeItem], dependencies=[Depends(PermissionsValidator(required_permissions=["task_type:read"]))], ) async def get_task_types( current_user=Depends(get_current_user), db: Session = Depends(get_db), + active: bool = True, skip: int = 0, limit: int = 100, ): - items = TaskTypeService(db).get_items() + items = TaskTypeService(db).get_items(active) return items diff --git a/api/services/timelog.py b/api/services/timelog.py index e303428c1..d14abe5fe 100644 --- a/api/services/timelog.py +++ b/api/services/timelog.py @@ -10,8 +10,11 @@ class TaskTypeService(AppService): - def get_items(self) -> List[TaskType]: - task_types = self.db.query(TaskType).all() or [] + def get_items(self, active) -> List[TaskType]: + query = self.db.query(TaskType) + if active: + query = query.filter(TaskType.active) + task_types = query.order_by(TaskType.name).all() or [] return task_types def slug_is_valid(self, slug: str) -> bool: diff --git a/api/tests/routers/v1/test_timelog.py b/api/tests/routers/v1/test_timelog.py index a5d44717a..d2cced57f 100644 --- a/api/tests/routers/v1/test_timelog.py +++ b/api/tests/routers/v1/test_timelog.py @@ -9,13 +9,31 @@ def test_get_task_types_authenticated(client: TestClient, get_regular_user_token_headers: Dict[str, str]) -> None: expected_types = [ {"slug": "meeting", "name": "Meeting", "active": True}, + {"slug": "project", "name": "Project time", "active": True}, + ] + + response = client.get( + f"{API_BASE_URL}/v1/timelog/task_types", + headers=get_regular_user_token_headers, + ) + assert response.status_code == HTTPStatus.OK + task_types = response.json() + assert task_types == expected_types + + +def test_get_task_types_including_inactive_ones( + client: TestClient, get_regular_user_token_headers: Dict[str, str] +) -> None: + expected_types = [ {"slug": "deprecated", "name": "Deprecated Type", "active": False}, + {"slug": "meeting", "name": "Meeting", "active": True}, {"slug": "project", "name": "Project time", "active": True}, ] response = client.get( - f"{API_BASE_URL}/v1/timelog/task_types/", + f"{API_BASE_URL}/v1/timelog/task_types", headers=get_regular_user_token_headers, + params={"active": False}, ) assert response.status_code == HTTPStatus.OK task_types = response.json() diff --git a/web/services/getTaskTypes.php b/web/services/getTaskTypes.php index f8656bed6..457490da7 100644 --- a/web/services/getTaskTypes.php +++ b/web/services/getTaskTypes.php @@ -55,7 +55,7 @@ break; } - $taskTypes = makeAPIRequest("/v1/timelog/task_types/"); + $taskTypes = makeAPIRequest("/v1/timelog/task_types"); if (array_key_exists('token_refresh_error', $taskTypes)) { $response['success'] = false; $response['error'] = 'token_refresh_error';