Skip to content

Commit 7a81540

Browse files
committed
Add permissions to custom filters
1 parent 78a6525 commit 7a81540

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

gramps_webapi/api/resources/filters.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424
from typing import Any, Dict, List, Optional, Set
2525

2626
import gramps.gen.filters as filters
27-
from flask import Response, abort
27+
from flask import Response, abort, current_app
2828
from gramps.gen.db.base import DbReadBase
2929
from gramps.gen.filters import GenericFilter
3030
from gramps.gen.filters.rules import Rule
3131
from gramps.gen.lib import Person
3232
from marshmallow import Schema
3333
from webargs import ValidationError, fields, validate
3434

35-
from ...const import GRAMPS_NAMESPACES
35+
from ...auth.const import PERM_EDIT_CUSTOM_FILTER
36+
from ...const import GRAMPS_NAMESPACES, TREE_MULTI
3637
from ...types import Handle
38+
from ..auth import require_permissions
3739
from ..util import abort_with_message, use_args
3840
from . import ProtectedResource
3941
from .emit import GrampsJSONEncoder
@@ -261,6 +263,11 @@ def get(self, args: Dict[str, str], namespace: str) -> Response:
261263
@use_args(CustomFilterSchema(), location="json")
262264
def post(self, args: Dict, namespace: str) -> Response:
263265
"""Create a custom filter."""
266+
if current_app.config["TREE"] == TREE_MULTI:
267+
abort_with_message(
268+
405, "Custom filters cannot be edited in a multi-tree setup"
269+
)
270+
require_permissions([PERM_EDIT_CUSTOM_FILTER])
264271
try:
265272
namespace = GRAMPS_NAMESPACES[namespace]
266273
except KeyError:
@@ -278,6 +285,11 @@ def post(self, args: Dict, namespace: str) -> Response:
278285
@use_args(CustomFilterSchema(), location="json")
279286
def put(self, args: Dict, namespace: str) -> Response:
280287
"""Update a custom filter."""
288+
if current_app.config["TREE"] == TREE_MULTI:
289+
abort_with_message(
290+
405, "Custom filters cannot be edited in a multi-tree setup"
291+
)
292+
require_permissions([PERM_EDIT_CUSTOM_FILTER])
281293
try:
282294
namespace = GRAMPS_NAMESPACES[namespace]
283295
except KeyError:
@@ -320,6 +332,11 @@ def get(self, namespace: str, name: str) -> Response:
320332
)
321333
def delete(self, args: Dict, namespace: str, name: str) -> Response:
322334
"""Delete a custom filter."""
335+
if current_app.config["TREE"] == TREE_MULTI:
336+
abort_with_message(
337+
405, "Custom filters cannot be edited in a multi-tree setup"
338+
)
339+
require_permissions([PERM_EDIT_CUSTOM_FILTER])
323340
try:
324341
namespace = GRAMPS_NAMESPACES[namespace]
325342
except KeyError:

gramps_webapi/auth/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
PERM_EDIT_SETTINGS = "EditSettings"
6363
PERM_TRIGGER_REINDEX = "TriggerReindex"
6464
PERM_EDIT_NAME_GROUP = "EditNameGroup"
65+
PERM_EDIT_CUSTOM_FILTER = "EditCustomFilter"
6566
PERM_EDIT_TREE = "EditTree"
6667
PERM_REPAIR_TREE = "RepairTree"
6768
PERM_UPGRADE_TREE_SCHEMA = "UpgradeSchema"
@@ -92,6 +93,7 @@
9293
PERM_EDIT_OBJ,
9394
PERM_DEL_OBJ,
9495
PERM_EDIT_NAME_GROUP,
96+
PERM_EDIT_CUSTOM_FILTER,
9597
}
9698

9799

0 commit comments

Comments
 (0)