Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require permissions for custom filters #513

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
23 changes: 20 additions & 3 deletions gramps_webapi/api/resources/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
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 marshmallow import Schema
from webargs import ValidationError, fields, validate

from ..util import abort_with_message, use_args
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 @@ -235,6 +237,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 @@ -252,6 +259,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 @@ -294,6 +306,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 All @@ -88,6 +89,7 @@
PERM_EDIT_OBJ,
PERM_DEL_OBJ,
PERM_EDIT_NAME_GROUP,
PERM_EDIT_CUSTOM_FILTER,
}


Expand Down
Loading