mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
fix: display warning message if admin tries to delete other household recipe, remove delete option if user is not allowed to delete it
This commit is contained in:
parent
34af2ecace
commit
310e762010
3 changed files with 41 additions and 13 deletions
|
@ -12,7 +12,12 @@
|
||||||
@confirm="deleteRecipe()"
|
@confirm="deleteRecipe()"
|
||||||
>
|
>
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
{{ $t("recipe.delete-confirmation") }}
|
<template v-if="isAdminAndNotOwner">
|
||||||
|
{{ $t("recipe.admin-delete-confirmation") }}
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
{{ $t("recipe.delete-confirmation") }}
|
||||||
|
</template>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
</BaseDialog>
|
</BaseDialog>
|
||||||
<BaseDialog
|
<BaseDialog
|
||||||
|
@ -359,16 +364,6 @@ export default defineNuxtComponent({
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get Default Menu Items Specified in Props
|
|
||||||
for (const [key, value] of Object.entries(props.useItems)) {
|
|
||||||
if (value) {
|
|
||||||
const item = defaultItems[key];
|
|
||||||
if (item && (item.isPublic || isOwnGroup.value)) {
|
|
||||||
state.menuItems.push(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add leading and Appending Items
|
// Add leading and Appending Items
|
||||||
state.menuItems = [...state.menuItems, ...props.leadingItems, ...props.appendItems];
|
state.menuItems = [...state.menuItems, ...props.leadingItems, ...props.appendItems];
|
||||||
|
|
||||||
|
@ -382,6 +377,30 @@ export default defineNuxtComponent({
|
||||||
const recipeRefWithScale = computed(() =>
|
const recipeRefWithScale = computed(() =>
|
||||||
recipeRef.value ? { scale: props.recipeScale, ...recipeRef.value } : undefined,
|
recipeRef.value ? { scale: props.recipeScale, ...recipeRef.value } : undefined,
|
||||||
);
|
);
|
||||||
|
const isAdminAndNotOwner = computed(() => {
|
||||||
|
return (
|
||||||
|
$auth.user.value?.admin
|
||||||
|
&& $auth.user.value?.id !== recipeRef.value?.userId
|
||||||
|
);
|
||||||
|
});
|
||||||
|
const canDelete = computed(() => {
|
||||||
|
const user = $auth.user.value;
|
||||||
|
const recipe = recipeRef.value;
|
||||||
|
return user && recipe && (user.admin || user.id === recipe.userId);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get Default Menu Items Specified in Props
|
||||||
|
for (const [key, value] of Object.entries(props.useItems)) {
|
||||||
|
if (!value) continue;
|
||||||
|
|
||||||
|
// Skip delete if not allowed
|
||||||
|
if (key === "delete" && !canDelete.value) continue;
|
||||||
|
|
||||||
|
const item = defaultItems[key];
|
||||||
|
if (item && (item.isPublic || isOwnGroup.value)) {
|
||||||
|
state.menuItems.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function getShoppingLists() {
|
async function getShoppingLists() {
|
||||||
const { data } = await api.shopping.lists.getAll(1, -1, { orderBy: "name", orderDirection: "asc" });
|
const { data } = await api.shopping.lists.getAll(1, -1, { orderBy: "name", orderDirection: "asc" });
|
||||||
|
@ -521,6 +540,8 @@ export default defineNuxtComponent({
|
||||||
icon,
|
icon,
|
||||||
planTypeOptions,
|
planTypeOptions,
|
||||||
firstDayOfWeek,
|
firstDayOfWeek,
|
||||||
|
isAdminAndNotOwner,
|
||||||
|
canDelete,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -472,6 +472,7 @@
|
||||||
"comment": "Comment",
|
"comment": "Comment",
|
||||||
"comments": "Comments",
|
"comments": "Comments",
|
||||||
"delete-confirmation": "Are you sure you want to delete this recipe?",
|
"delete-confirmation": "Are you sure you want to delete this recipe?",
|
||||||
|
"admin-delete-confirmation": "You're about to delete a recipe that isn't yours using admin permissions. Are you sure?",
|
||||||
"delete-recipe": "Delete Recipe",
|
"delete-recipe": "Delete Recipe",
|
||||||
"description": "Description",
|
"description": "Description",
|
||||||
"disable-amount": "Disable Ingredient Amounts",
|
"disable-amount": "Disable Ingredient Amounts",
|
||||||
|
|
|
@ -64,6 +64,12 @@ class RecipeService(RecipeServiceBase):
|
||||||
raise exceptions.NoEntryFound("Recipe not found.")
|
raise exceptions.NoEntryFound("Recipe not found.")
|
||||||
return recipe
|
return recipe
|
||||||
|
|
||||||
|
def can_delete(self, recipe: Recipe) -> bool:
|
||||||
|
if self.user.admin:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return self.can_update(recipe)
|
||||||
|
|
||||||
def can_update(self, recipe: Recipe) -> bool:
|
def can_update(self, recipe: Recipe) -> bool:
|
||||||
if recipe.settings is None:
|
if recipe.settings is None:
|
||||||
raise exceptions.UnexpectedNone("Recipe Settings is None")
|
raise exceptions.UnexpectedNone("Recipe Settings is None")
|
||||||
|
@ -77,7 +83,7 @@ class RecipeService(RecipeServiceBase):
|
||||||
other_household = self.repos.households.get_one(recipe.household_id)
|
other_household = self.repos.households.get_one(recipe.household_id)
|
||||||
if not (other_household and other_household.preferences):
|
if not (other_household and other_household.preferences):
|
||||||
return False
|
return False
|
||||||
if not self.user.admin and other_household.preferences.lock_recipe_edits_from_other_households:
|
if other_household.preferences.lock_recipe_edits_from_other_households:
|
||||||
return False
|
return False
|
||||||
if recipe.settings.locked:
|
if recipe.settings.locked:
|
||||||
return False
|
return False
|
||||||
|
@ -423,7 +429,7 @@ class RecipeService(RecipeServiceBase):
|
||||||
def delete_one(self, slug_or_id: str | UUID) -> Recipe:
|
def delete_one(self, slug_or_id: str | UUID) -> Recipe:
|
||||||
recipe = self.get_one(slug_or_id)
|
recipe = self.get_one(slug_or_id)
|
||||||
|
|
||||||
if not self.can_update(recipe):
|
if not self.can_delete(recipe):
|
||||||
raise exceptions.PermissionDenied("You do not have permission to delete this recipe.")
|
raise exceptions.PermissionDenied("You do not have permission to delete this recipe.")
|
||||||
|
|
||||||
data = self.group_recipes.delete(recipe.id, "id")
|
data = self.group_recipes.delete(recipe.id, "id")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue