23
23
from typing import Any , Dict , List , Optional , Set
24
24
25
25
import gramps .gen .filters as filters
26
- from flask import Response , abort
26
+ from flask import Response , abort , current_app
27
27
from gramps .gen .db .base import DbReadBase
28
28
from gramps .gen .filters import GenericFilter
29
29
from marshmallow import Schema
30
30
from webargs import ValidationError , fields , validate
31
31
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
34
34
from ...types import Handle
35
+ from ..auth import require_permissions
36
+ from ..util import abort_with_message , use_args
35
37
from . import ProtectedResource
36
38
from .emit import GrampsJSONEncoder
37
39
@@ -235,6 +237,11 @@ def get(self, args: Dict[str, str], namespace: str) -> Response:
235
237
@use_args (CustomFilterSchema (), location = "json" )
236
238
def post (self , args : Dict , namespace : str ) -> Response :
237
239
"""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 ])
238
245
try :
239
246
namespace = GRAMPS_NAMESPACES [namespace ]
240
247
except KeyError :
@@ -252,6 +259,11 @@ def post(self, args: Dict, namespace: str) -> Response:
252
259
@use_args (CustomFilterSchema (), location = "json" )
253
260
def put (self , args : Dict , namespace : str ) -> Response :
254
261
"""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 ])
255
267
try :
256
268
namespace = GRAMPS_NAMESPACES [namespace ]
257
269
except KeyError :
@@ -294,6 +306,11 @@ def get(self, namespace: str, name: str) -> Response:
294
306
)
295
307
def delete (self , args : Dict , namespace : str , name : str ) -> Response :
296
308
"""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 ])
297
314
try :
298
315
namespace = GRAMPS_NAMESPACES [namespace ]
299
316
except KeyError :
0 commit comments