2323from typing import Any , Dict , List , Optional , Set
2424
2525import gramps .gen .filters as filters
26- from flask import Response , abort
26+ from flask import Response , abort , current_app
2727from gramps .gen .db .base import DbReadBase
2828from gramps .gen .filters import GenericFilter
2929from marshmallow import Schema
3030from 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
3434from ...types import Handle
35+ from ..auth import require_permissions
36+ from ..util import abort_with_message , use_args
3537from . import ProtectedResource
3638from .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 :
0 commit comments