Fix: Allow Last Made to be Updated on Locked Recipes (#2140)

* allow certain props to be updated on locked recipe

* pytest

* added "last_made" to hardcoded datetime fields

* refactored last made to its own route

* codegen/types

* updated pytest
This commit is contained in:
Michael Genson
2023-02-21 21:59:22 -06:00
committed by GitHub
parent a6c46a7420
commit fd03d468d4
9 changed files with 88 additions and 5 deletions

View File

@@ -16,7 +16,7 @@ class AlchemyExporter(BaseService):
engine: base.Engine
meta: MetaData
look_for_datetime = {"created_at", "update_at", "date_updated", "timestamp", "expires_at", "locked_at"}
look_for_datetime = {"created_at", "update_at", "date_updated", "timestamp", "expires_at", "locked_at", "last_made"}
look_for_date = {"date_added", "date"}
look_for_time = {"scheduled_time"}

View File

@@ -247,6 +247,7 @@ class RecipeService(BaseService):
Args:
slug (str): recipe slug
new_data (Recipe): the new recipe data
Raises:
exceptions.PermissionDenied (403)
@@ -275,7 +276,7 @@ class RecipeService(BaseService):
def patch_one(self, slug: str, patch_data: Recipe) -> Recipe:
recipe: Recipe | None = self._pre_update_check(slug, patch_data)
recipe = self.repos.recipes.by_group(self.group.id).get_one(slug)
recipe = self._get_recipe(slug)
if recipe is None:
raise exceptions.NoEntryFound("Recipe not found.")
@@ -285,6 +286,11 @@ class RecipeService(BaseService):
self.check_assets(new_data, recipe.slug)
return new_data
def update_last_made(self, slug: str, timestamp: datetime) -> Recipe:
# we bypass the pre update check since any user can update a recipe's last made date, even if it's locked
recipe = self._get_recipe(slug)
return self.repos.recipes.by_group(self.group.id).patch(recipe.slug, {"last_made": timestamp})
def delete_one(self, slug) -> Recipe:
recipe = self._get_recipe(slug)