2424from typing import Any , Dict , List , Optional , Set
2525
2626import gramps .gen .filters as filters
27- from flask import Response , abort
27+ from flask import Response , abort , current_app
2828from gramps .gen .db .base import DbReadBase
2929from gramps .gen .filters import GenericFilter
3030from gramps .gen .filters .rules import Rule
3131from gramps .gen .lib import Person
3232from marshmallow import Schema
3333from 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
3637from ...types import Handle
38+ from ..auth import require_permissions
3739from ..util import abort_with_message , use_args
3840from . import ProtectedResource
3941from .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 :
0 commit comments