1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-19 21:29:40 +02:00
mealie/frontend/composables/recipes/use-recipe-permissions.ts

45 lines
1 KiB
TypeScript
Raw Normal View History

import { computed, Ref } from "@nuxtjs/composition-api";
2024-08-31 21:54:10 -05:00
import { Recipe } from "~/lib/api/types/recipe";
import { HouseholdSummary } from "~/lib/api/types/household";
2024-08-31 21:54:10 -05:00
import { UserOut } from "~/lib/api/types/user";
export function useRecipePermissions(
recipe: Recipe,
recipeHousehold: Ref<HouseholdSummary | undefined>,
user: UserOut | null,
) {
const canEditRecipe = computed(() => {
// Check recipe owner
if (!user?.id) {
return false;
}
if (user.id === recipe.userId) {
return true;
}
2024-08-31 21:54:10 -05:00
// Check group and household
if (user.groupId !== recipe.groupId) {
return false;
}
if (user.householdId !== recipe.householdId) {
if (!recipeHousehold.value?.preferences) {
return false;
}
if (recipeHousehold.value?.preferences.lockRecipeEditsFromOtherHouseholds) {
return false;
}
}
2024-08-31 21:54:10 -05:00
// Check recipe
if (recipe.settings?.locked) {
return false;
}
2024-08-31 21:54:10 -05:00
return true;
});
2024-08-31 21:54:10 -05:00
return {
canEditRecipe,
}
2024-08-31 21:54:10 -05:00
}