Skip to content

Commit

Permalink
feat: implement delete by pilot ID (preliminary)
Browse files Browse the repository at this point in the history
  • Loading branch information
martynia committed Nov 28, 2024
1 parent 4209217 commit bf613c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions diracx-db/src/diracx/db/os/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ async def search(

return hits

async def delete(self, query: list[dict[str, Any]]) -> None:

# Delete multiple documents by query.

body = {}
if query:
body["query"] = apply_search_filters(self.fields, query)
await self.client.delete_by_query(body=body, index=f"{self.index_prefix}*")

Check warning on line 249 in diracx-db/src/diracx/db/os/utils.py

View check run for this annotation

Codecov / codecov/patch

diracx-db/src/diracx/db/os/utils.py#L246-L249

Added lines #L246 - L249 were not covered by tests


def require_type(operator, field_name, field_type, allowed_types):
if field_type not in allowed_types:
Expand Down
16 changes: 15 additions & 1 deletion diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,26 @@ async def get_logs(
db: PilotLogsDB,
check_permissions: CheckPilotLogsPolicyCallable,
):
logger.warning(f"Retrieving message for pilot ID '{pilot_id}'")
logger.warning(f"Retrieving logs for pilot ID '{pilot_id}'")
await check_permissions(action=ActionType.QUERY, pilot_db=db)

Check warning on line 71 in diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

View check run for this annotation

Codecov / codecov/patch

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py#L70-L71

Added lines #L70 - L71 were not covered by tests

result = await db.search(

Check warning on line 73 in diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

View check run for this annotation

Codecov / codecov/patch

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py#L73

Added line #L73 was not covered by tests
["Message"],
[{"parameter": "PilotID", "operator": "eq"} | {"value": pilot_id}],
[{"parameter": "LineNumber", "direction": "asc"}],
)
if not result:
return [f"No logs for pilot ID = {pilot_id}"]
return result

Check warning on line 80 in diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

View check run for this annotation

Codecov / codecov/patch

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py#L78-L80

Added lines #L78 - L80 were not covered by tests


@router.delete("/delete")
async def delete_by_pilot_id(
pilot_id: int,
db: PilotLogsDB,
check_permissions: CheckPilotLogsPolicyCallable,
):
logger.warning(f"Deleting logs for pilot ID '{pilot_id}'")
await check_permissions(action=ActionType.DELETE, pilot_db=db)
await db.delete([{"parameter": "PilotID", "operator": "eq"} | {"value": pilot_id}])
return f"Logs for pilot ID '{pilot_id}' successfully deleted"

Check warning on line 92 in diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

View check run for this annotation

Codecov / codecov/patch

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py#L89-L92

Added lines #L89 - L92 were not covered by tests

0 comments on commit bf613c8

Please sign in to comment.