fix: require can_manage_household to manage notifiers and webhooks (#8885)
This commit is contained in:
1 parent
e645ee07d4
commit
7c524255f4
10 files changed
+78
-19
No files matched your search
@@ -141,11 +141,13 @@ Notifiers use the [Apprise library](https://github.com/caronc/apprise/wiki), whi
|
||||
- `json` and `jsons`
|
||||
- `xml` and `xmls`
|
||||
|
||||
Only users with the **Manage household** permission can view and change notifiers.
|
||||
|
||||
[Notifiers Demo](https://demo.mealie.io/household/notifiers){ .md-button .md-button--primary }
|
||||
|
||||
### Webhooks
|
||||
|
||||
Unlike notifiers, which are event-driven notifications, Webhooks allow you to send scheduled notifications to your desired endpoint. Webhooks are sent on the day of a scheduled meal plan, at the specified time, and contain the meal plan data in the request.
|
||||
Unlike notifiers, which are event-driven notifications, Webhooks allow you to send scheduled notifications to your desired endpoint. Webhooks are sent on the day of a scheduled meal plan, at the specified time, and contain the meal plan data in the request. Only users with the **Manage household** permission can view and change webhooks.
|
||||
|
||||
[Webhooks Demo](https://demo.mealie.io/household/webhooks){ .md-button .md-button--primary }
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ Each user can be configured to have varying levels of access. Some of these perm
|
||||
| Administrator | Access to administrator tools |
|
||||
| Invite | Generating invitation links for other users |
|
||||
| Manage group | Access to group management areas and settings |
|
||||
| Manage household | Household settings, notifiers, and webhooks |
|
||||
| Organize group data | Creating, updating, deleting, and merging group data such as foods, units, tags, categories, tools, labels, and recipe actions |
|
||||
|
||||
The **Manage group** and **Organize group data** permissions are separate. Users need **Organize group data** to add new foods, units, tags, categories, or tools, including when creating missing ingredients during recipe parsing.
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<template>
|
||||
<div>
|
||||
<p>
|
||||
You now need the <strong>Manage household</strong> permission to view or change notifiers and webhooks.
|
||||
Existing notifiers and webhooks keep running.
|
||||
</p>
|
||||
<p v-if="user?.canManage">
|
||||
You can turn this permission on for people in your household from the members page:
|
||||
<br>
|
||||
<v-btn class="mt-2" color="primary" to="/household/members">
|
||||
{{ $t("profile.manage-members") }}
|
||||
</v-btn>
|
||||
</p>
|
||||
<p v-else-if="!user?.canManageHousehold">
|
||||
If you need it, ask a group manager or your server admin.
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { AnnouncementMeta } from "~/composables/use-announcements";
|
||||
|
||||
const { user } = useMealieAuth();
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export const meta: AnnouncementMeta = {
|
||||
title: "Changes to notifiers and webhooks",
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="css">
|
||||
p {
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -952,7 +952,7 @@
|
||||
"user-can-manage-group": "User can manage group settings",
|
||||
"user-can-manage-group-hint": "User can manage the group's shared settings, like AI providers, and edit permissions for members of their household.",
|
||||
"user-can-manage-household": "User can manage household",
|
||||
"user-can-manage-household-hint": "User can manage the settings of the household they belong to, like its name, privacy, and recipe-editing rules.",
|
||||
"user-can-manage-household-hint": "User can manage the settings of the household they belong to, like its name, privacy, recipe-editing rules, notifiers, and webhooks.",
|
||||
"user-can-organize-group-data": "User can manage group data such as foods, units, tags, and categories",
|
||||
"user-can-organize-group-data-hint": "Create, edit, and delete foods, units, tags, categories, tools, labels, and recipe actions shared across the group.",
|
||||
"enable-advanced-features": "Enable advanced features",
|
||||
|
||||
@@ -200,7 +200,7 @@ interface OptionSection {
|
||||
}
|
||||
|
||||
definePageMeta({
|
||||
middleware: ["auth", "advanced-only"],
|
||||
middleware: ["auth", "advanced-only", "can-manage-household-only"],
|
||||
});
|
||||
|
||||
const api = useUserApi();
|
||||
|
||||
@@ -74,7 +74,7 @@ import GroupWebhookEditor from "~/components/Domain/Household/GroupWebhookEditor
|
||||
import { alert } from "~/composables/use-toast";
|
||||
|
||||
definePageMeta({
|
||||
middleware: ["auth", "advanced-only"],
|
||||
middleware: ["auth", "advanced-only", "can-manage-household-only"],
|
||||
});
|
||||
|
||||
const i18n = useI18n();
|
||||
|
||||
@@ -176,7 +176,7 @@
|
||||
</v-col>
|
||||
<AdvancedOnly>
|
||||
<v-col
|
||||
v-if="user.advanced"
|
||||
v-if="user.canManageHousehold"
|
||||
cols="12"
|
||||
sm="12"
|
||||
md="6"
|
||||
@@ -194,6 +194,7 @@
|
||||
</AdvancedOnly>
|
||||
<AdvancedOnly>
|
||||
<v-col
|
||||
v-if="user.canManageHousehold"
|
||||
cols="12"
|
||||
sm="12"
|
||||
md="6"
|
||||
|
||||
@@ -6,6 +6,7 @@ from pydantic import UUID4
|
||||
from mealie.routes._base.base_controllers import BaseUserController
|
||||
from mealie.routes._base.controller import controller
|
||||
from mealie.routes._base.mixins import HttpRepo
|
||||
from mealie.routes._base.permissions import Perm, not_found, require
|
||||
from mealie.routes._base.routers import MealieCrudRoute
|
||||
from mealie.schema.household.group_events import (
|
||||
GroupEventNotifierCreate,
|
||||
@@ -51,7 +52,7 @@ class GroupEventsNotifierController(BaseUserController):
|
||||
def mixins(self) -> HttpRepo:
|
||||
return HttpRepo(self.repo, self.logger, self.registered_exceptions, self.t("generic.server-error"))
|
||||
|
||||
@router.get("", response_model=GroupEventPagination)
|
||||
@router.get("", response_model=GroupEventPagination, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def get_all(self, q: PaginationQuery = Depends(PaginationQuery)):
|
||||
response = self.repo.page_all(
|
||||
pagination=q,
|
||||
@@ -61,16 +62,18 @@ class GroupEventsNotifierController(BaseUserController):
|
||||
response.set_pagination_guides(router.url_path_for("get_all"), q.model_dump())
|
||||
return response
|
||||
|
||||
@router.post("", response_model=GroupEventNotifierOut, status_code=201)
|
||||
@router.post(
|
||||
"", response_model=GroupEventNotifierOut, status_code=201, dependencies=[require(Perm.HOUSEHOLD_MANAGE)]
|
||||
)
|
||||
def create_one(self, data: GroupEventNotifierCreate):
|
||||
save_data = cast(data, GroupEventNotifierSave, group_id=self.group_id, household_id=self.household_id)
|
||||
return self.mixins.create_one(save_data)
|
||||
|
||||
@router.get("/{item_id}", response_model=GroupEventNotifierOut)
|
||||
@router.get("/{item_id}", response_model=GroupEventNotifierOut, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def get_one(self, item_id: UUID4):
|
||||
return self.mixins.get_one(item_id)
|
||||
|
||||
@router.put("/{item_id}", response_model=GroupEventNotifierOut)
|
||||
@router.put("/{item_id}", response_model=GroupEventNotifierOut, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def update_one(self, item_id: UUID4, data: GroupEventNotifierUpdate):
|
||||
if data.apprise_url is None:
|
||||
current_data: GroupEventNotifierPrivate = self.repo.get_one(
|
||||
@@ -80,7 +83,7 @@ class GroupEventsNotifierController(BaseUserController):
|
||||
|
||||
return self.mixins.update_one(data, item_id)
|
||||
|
||||
@router.delete("/{item_id}", status_code=204)
|
||||
@router.delete("/{item_id}", status_code=204, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def delete_one(self, item_id: UUID4):
|
||||
self.mixins.delete_one(item_id) # type: ignore
|
||||
|
||||
@@ -88,9 +91,11 @@ class GroupEventsNotifierController(BaseUserController):
|
||||
# Test Event Notifications
|
||||
|
||||
# TODO: properly re-implement this with new event listeners
|
||||
@router.post("/{item_id}/test", status_code=204)
|
||||
@router.post("/{item_id}/test", status_code=204, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def test_notification(self, item_id: UUID4):
|
||||
item: GroupEventNotifierPrivate = self.repo.get_one(item_id, override_schema=GroupEventNotifierPrivate)
|
||||
item: GroupEventNotifierPrivate | None = self.repo.get_one(item_id, override_schema=GroupEventNotifierPrivate)
|
||||
if item is None:
|
||||
raise not_found()
|
||||
|
||||
event_type = EventTypes.test_message
|
||||
test_event = Event(
|
||||
|
||||
@@ -7,6 +7,7 @@ from pydantic import UUID4
|
||||
from mealie.routes._base.base_controllers import BaseUserController
|
||||
from mealie.routes._base.controller import controller
|
||||
from mealie.routes._base.mixins import HttpRepo
|
||||
from mealie.routes._base.permissions import Perm, require
|
||||
from mealie.schema import mapper
|
||||
from mealie.schema.household.webhook import CreateWebhook, ReadWebhook, SaveWebhook, WebhookPagination
|
||||
from mealie.schema.response.pagination import PaginationQuery
|
||||
@@ -25,7 +26,7 @@ class ReadWebhookController(BaseUserController):
|
||||
def mixins(self) -> HttpRepo:
|
||||
return HttpRepo[CreateWebhook, SaveWebhook, CreateWebhook](self.repo, self.logger)
|
||||
|
||||
@router.get("", response_model=WebhookPagination)
|
||||
@router.get("", response_model=WebhookPagination, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def get_all(self, q: PaginationQuery = Depends(PaginationQuery)):
|
||||
response = self.repo.page_all(
|
||||
pagination=q,
|
||||
@@ -35,12 +36,12 @@ class ReadWebhookController(BaseUserController):
|
||||
response.set_pagination_guides(router.url_path_for("get_all"), q.model_dump())
|
||||
return response
|
||||
|
||||
@router.post("", response_model=ReadWebhook, status_code=201)
|
||||
@router.post("", response_model=ReadWebhook, status_code=201, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def create_one(self, data: CreateWebhook):
|
||||
save = mapper.cast(data, SaveWebhook, group_id=self.group_id, household_id=self.household_id)
|
||||
return self.mixins.create_one(save)
|
||||
|
||||
@router.post("/rerun")
|
||||
@router.post("/rerun", dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def rerun_webhooks(self):
|
||||
"""Manually re-fires all previously scheduled webhooks for today"""
|
||||
|
||||
@@ -48,19 +49,19 @@ class ReadWebhookController(BaseUserController):
|
||||
start_dt = datetime.combine(datetime.now(UTC).date(), start_time)
|
||||
post_group_webhooks(start_dt=start_dt, group_id=self.group.id, household_id=self.household.id)
|
||||
|
||||
@router.get("/{item_id}", response_model=ReadWebhook)
|
||||
@router.get("/{item_id}", response_model=ReadWebhook, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def get_one(self, item_id: UUID4):
|
||||
return self.mixins.get_one(item_id)
|
||||
|
||||
@router.post("/{item_id}/test")
|
||||
@router.post("/{item_id}/test", dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def test_one(self, item_id: UUID4, bg_tasks: BackgroundTasks):
|
||||
webhook = self.mixins.get_one(item_id)
|
||||
bg_tasks.add_task(post_test_webhook, webhook, "Test Webhook")
|
||||
|
||||
@router.put("/{item_id}", response_model=ReadWebhook)
|
||||
@router.put("/{item_id}", response_model=ReadWebhook, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def update_one(self, item_id: UUID4, data: CreateWebhook):
|
||||
return self.mixins.update_one(data, item_id)
|
||||
|
||||
@router.delete("/{item_id}", response_model=ReadWebhook)
|
||||
@router.delete("/{item_id}", response_model=ReadWebhook, dependencies=[require(Perm.HOUSEHOLD_MANAGE)])
|
||||
def delete_one(self, item_id: UUID4):
|
||||
return self.mixins.delete_one(item_id) # type: ignore
|
||||
@@ -67,9 +67,22 @@ EXPECTED_ROUTE_PERMISSIONS: dict[Perm, set[str]] = {
|
||||
"POST /api/households/invitations/email",
|
||||
},
|
||||
Perm.HOUSEHOLD_MANAGE: {
|
||||
"GET /api/households/events/notifications",
|
||||
"POST /api/households/events/notifications",
|
||||
"GET /api/households/events/notifications/{item_id}",
|
||||
"PUT /api/households/events/notifications/{item_id}",
|
||||
"DELETE /api/households/events/notifications/{item_id}",
|
||||
"POST /api/households/events/notifications/{item_id}/test",
|
||||
"POST /api/households/mealplans/ical",
|
||||
"DELETE /api/households/mealplans/ical",
|
||||
"PUT /api/households/preferences",
|
||||
"GET /api/households/webhooks",
|
||||
"POST /api/households/webhooks",
|
||||
"POST /api/households/webhooks/rerun",
|
||||
"GET /api/households/webhooks/{item_id}",
|
||||
"PUT /api/households/webhooks/{item_id}",
|
||||
"DELETE /api/households/webhooks/{item_id}",
|
||||
"POST /api/households/webhooks/{item_id}/test",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user