mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-11 02:13:12 -05:00
fix: Improve recipe bulk deletion (#6772)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from functools import cached_property
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from pydantic import UUID4
|
||||
|
||||
from mealie.core.dependencies.dependencies import get_temporary_zip_path
|
||||
from mealie.core.exceptions import PermissionDenied
|
||||
from mealie.core.security import create_file_token
|
||||
from mealie.routes._base import BaseUserController, controller
|
||||
from mealie.schema.group.group_exports import GroupDataExport
|
||||
@@ -15,8 +16,9 @@ from mealie.schema.recipe.recipe_bulk_actions import (
|
||||
DeleteRecipes,
|
||||
ExportRecipes,
|
||||
)
|
||||
from mealie.schema.response.responses import SuccessResponse
|
||||
from mealie.schema.response.responses import ErrorResponse, SuccessResponse
|
||||
from mealie.services.recipe.recipe_bulk_service import RecipeBulkActionsService
|
||||
from mealie.services.recipe.recipe_service import RecipeService
|
||||
|
||||
router = APIRouter(prefix="/bulk-actions")
|
||||
|
||||
@@ -27,6 +29,10 @@ class RecipeBulkActionsController(BaseUserController):
|
||||
def service(self) -> RecipeBulkActionsService:
|
||||
return RecipeBulkActionsService(self.repos, self.user, self.group)
|
||||
|
||||
@cached_property
|
||||
def recipe_service(self) -> RecipeService:
|
||||
return RecipeService(self.repos, self.user, self.household, self.translator)
|
||||
|
||||
# TODO Should these actions return some success response?
|
||||
@router.post("/tag")
|
||||
def bulk_tag_recipes(self, tag_data: AssignTags):
|
||||
@@ -42,7 +48,14 @@ class RecipeBulkActionsController(BaseUserController):
|
||||
|
||||
@router.post("/delete")
|
||||
def bulk_delete_recipes(self, delete_recipes: DeleteRecipes):
|
||||
self.service.delete_recipes(delete_recipes.recipes)
|
||||
# TODO: this route should be migrated to the standard recipe controller
|
||||
try:
|
||||
self.recipe_service.delete_many(delete_recipes.recipes)
|
||||
except PermissionDenied as e:
|
||||
self.logger.error("Permission Denied on recipe controller action")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN, detail=ErrorResponse.respond(message="Permission Denied")
|
||||
) from e
|
||||
|
||||
@router.post("/export", status_code=202)
|
||||
def bulk_export_recipes(self, export_recipes: ExportRecipes):
|
||||
|
||||
Reference in New Issue
Block a user