24
24
from typing import Any , Dict , List , Optional , Set
25
25
26
26
import gramps .gen .filters as filters
27
- from flask import Response , abort
27
+ from flask import Response , abort , current_app
28
28
from gramps .gen .db .base import DbReadBase
29
29
from gramps .gen .filters import GenericFilter
30
30
from gramps .gen .filters .rules import Rule
31
31
from gramps .gen .lib import Person
32
32
from marshmallow import Schema
33
33
from webargs import ValidationError , fields , validate
34
34
35
- from ...const import GRAMPS_NAMESPACES
35
+ from ...auth .const import PERM_EDIT_CUSTOM_FILTER
36
+ from ...const import GRAMPS_NAMESPACES , TREE_MULTI
36
37
from ...types import Handle
38
+ from ..auth import require_permissions
37
39
from ..util import abort_with_message , use_args
38
40
from . import ProtectedResource
39
41
from .emit import GrampsJSONEncoder
@@ -261,6 +263,11 @@ def get(self, args: Dict[str, str], namespace: str) -> Response:
261
263
@use_args (CustomFilterSchema (), location = "json" )
262
264
def post (self , args : Dict , namespace : str ) -> Response :
263
265
"""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 ])
264
271
try :
265
272
namespace = GRAMPS_NAMESPACES [namespace ]
266
273
except KeyError :
@@ -278,6 +285,11 @@ def post(self, args: Dict, namespace: str) -> Response:
278
285
@use_args (CustomFilterSchema (), location = "json" )
279
286
def put (self , args : Dict , namespace : str ) -> Response :
280
287
"""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 ])
281
293
try :
282
294
namespace = GRAMPS_NAMESPACES [namespace ]
283
295
except KeyError :
@@ -320,6 +332,11 @@ def get(self, namespace: str, name: str) -> Response:
320
332
)
321
333
def delete (self , args : Dict , namespace : str , name : str ) -> Response :
322
334
"""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 ])
323
340
try :
324
341
namespace = GRAMPS_NAMESPACES [namespace ]
325
342
except KeyError :
0 commit comments