Skip to content

Commit 2176ea9

Browse files
committed
Add permissions to custom filters
1 parent 9a51c41 commit 2176ea9

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

gramps_webapi/api/resources/filters.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323
from typing import Any, Dict, List, Optional, Set
2424

2525
import gramps.gen.filters as filters
26-
from flask import Response, abort
26+
from flask import Response, abort, current_app
2727
from gramps.gen.db.base import DbReadBase
2828
from gramps.gen.filters import GenericFilter
2929
from marshmallow import Schema
3030
from webargs import ValidationError, fields, validate
3131

32-
from ..util import abort_with_message, use_args
33-
from ...const import GRAMPS_NAMESPACES
32+
from ...auth.const import PERM_EDIT_CUSTOM_FILTER
33+
from ...const import GRAMPS_NAMESPACES, TREE_MULTI
3434
from ...types import Handle
35+
from ..auth import require_permissions
36+
from ..util import abort_with_message, use_args
3537
from . import ProtectedResource
3638
from .emit import GrampsJSONEncoder
3739

@@ -235,6 +237,11 @@ def get(self, args: Dict[str, str], namespace: str) -> Response:
235237
@use_args(CustomFilterSchema(), location="json")
236238
def post(self, args: Dict, namespace: str) -> Response:
237239
"""Create a custom filter."""
240+
if current_app.config["TREE"] == TREE_MULTI:
241+
abort_with_message(
242+
405, "Custom filters cannot be edited in a multi-tree setup"
243+
)
244+
require_permissions([PERM_EDIT_CUSTOM_FILTER])
238245
try:
239246
namespace = GRAMPS_NAMESPACES[namespace]
240247
except KeyError:
@@ -252,6 +259,11 @@ def post(self, args: Dict, namespace: str) -> Response:
252259
@use_args(CustomFilterSchema(), location="json")
253260
def put(self, args: Dict, namespace: str) -> Response:
254261
"""Update a custom filter."""
262+
if current_app.config["TREE"] == TREE_MULTI:
263+
abort_with_message(
264+
405, "Custom filters cannot be edited in a multi-tree setup"
265+
)
266+
require_permissions([PERM_EDIT_CUSTOM_FILTER])
255267
try:
256268
namespace = GRAMPS_NAMESPACES[namespace]
257269
except KeyError:
@@ -294,6 +306,11 @@ def get(self, namespace: str, name: str) -> Response:
294306
)
295307
def delete(self, args: Dict, namespace: str, name: str) -> Response:
296308
"""Delete a custom filter."""
309+
if current_app.config["TREE"] == TREE_MULTI:
310+
abort_with_message(
311+
405, "Custom filters cannot be edited in a multi-tree setup"
312+
)
313+
require_permissions([PERM_EDIT_CUSTOM_FILTER])
297314
try:
298315
namespace = GRAMPS_NAMESPACES[namespace]
299316
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"
@@ -88,6 +89,7 @@
8889
PERM_EDIT_OBJ,
8990
PERM_DEL_OBJ,
9091
PERM_EDIT_NAME_GROUP,
92+
PERM_EDIT_CUSTOM_FILTER,
9193
}
9294

9395

0 commit comments

Comments
 (0)