Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions gramps_webapi/api/resources/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@
from typing import Any, Dict, List, Optional, Set

import gramps.gen.filters as filters
from flask import Response, abort
from flask import Response, abort, current_app
from gramps.gen.db.base import DbReadBase
from gramps.gen.filters import GenericFilter
from gramps.gen.filters.rules import Rule
from gramps.gen.lib import Person
from marshmallow import Schema
from webargs import ValidationError, fields, validate

from ...const import GRAMPS_NAMESPACES
from ...auth.const import PERM_EDIT_CUSTOM_FILTER
from ...const import GRAMPS_NAMESPACES, TREE_MULTI
from ...types import Handle
from ..auth import require_permissions
from ..util import abort_with_message, use_args
from . import ProtectedResource
from .emit import GrampsJSONEncoder
Expand Down Expand Up @@ -261,6 +263,11 @@ def get(self, args: Dict[str, str], namespace: str) -> Response:
@use_args(CustomFilterSchema(), location="json")
def post(self, args: Dict, namespace: str) -> Response:
"""Create a custom filter."""
if current_app.config["TREE"] == TREE_MULTI:
abort_with_message(
405, "Custom filters cannot be edited in a multi-tree setup"
)
require_permissions([PERM_EDIT_CUSTOM_FILTER])
try:
namespace = GRAMPS_NAMESPACES[namespace]
except KeyError:
Expand All @@ -278,6 +285,11 @@ def post(self, args: Dict, namespace: str) -> Response:
@use_args(CustomFilterSchema(), location="json")
def put(self, args: Dict, namespace: str) -> Response:
"""Update a custom filter."""
if current_app.config["TREE"] == TREE_MULTI:
abort_with_message(
405, "Custom filters cannot be edited in a multi-tree setup"
)
require_permissions([PERM_EDIT_CUSTOM_FILTER])
try:
namespace = GRAMPS_NAMESPACES[namespace]
except KeyError:
Expand Down Expand Up @@ -320,6 +332,11 @@ def get(self, namespace: str, name: str) -> Response:
)
def delete(self, args: Dict, namespace: str, name: str) -> Response:
"""Delete a custom filter."""
if current_app.config["TREE"] == TREE_MULTI:
abort_with_message(
405, "Custom filters cannot be edited in a multi-tree setup"
)
require_permissions([PERM_EDIT_CUSTOM_FILTER])
try:
namespace = GRAMPS_NAMESPACES[namespace]
except KeyError:
Expand Down
2 changes: 2 additions & 0 deletions gramps_webapi/auth/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
PERM_EDIT_SETTINGS = "EditSettings"
PERM_TRIGGER_REINDEX = "TriggerReindex"
PERM_EDIT_NAME_GROUP = "EditNameGroup"
PERM_EDIT_CUSTOM_FILTER = "EditCustomFilter"
PERM_EDIT_TREE = "EditTree"
PERM_REPAIR_TREE = "RepairTree"
PERM_UPGRADE_TREE_SCHEMA = "UpgradeSchema"
Expand Down Expand Up @@ -92,6 +93,7 @@
PERM_EDIT_OBJ,
PERM_DEL_OBJ,
PERM_EDIT_NAME_GROUP,
PERM_EDIT_CUSTOM_FILTER,
}


Expand Down
Loading