Skip to content

Commit

Permalink
Add enabled key to GET /trees (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub authored Feb 28, 2024
1 parent 38a4fc1 commit 0e3c4e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions gramps_webapi/api/resources/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
from webargs import fields
from werkzeug.security import safe_join

from ...auth import disable_enable_tree, get_tree_usage, set_tree_quota
from ...auth import (
disable_enable_tree,
get_tree_usage,
is_tree_disabled,
set_tree_quota,
)
from ...auth.const import (
PERM_ADD_TREE,
PERM_DISABLE_TREE,
Expand Down Expand Up @@ -68,7 +73,8 @@ def get_tree_details(tree_id: str) -> Dict[str, str]:
except ValueError:
abort(404)
usage = get_tree_usage(tree_id) or {}
return {"name": dbmgr.name, "id": tree_id, **usage}
enabled = not is_tree_disabled(tree=tree_id)
return {"name": dbmgr.name, "id": tree_id, **usage, "enabled": enabled}


def get_tree_path(tree_id: str) -> Optional[str]:
Expand Down
4 changes: 4 additions & 0 deletions gramps_webapi/data/apispec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10589,3 +10589,7 @@ definitions:
description: "The current number of people."
type: integer
example: 96
enabled:
description: "Whether the tree is enabled."
type: boolean
example: true
5 changes: 3 additions & 2 deletions tests/test_endpoints/test_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_list_trees_owner(self):
assert rv.status_code == 200
trees = rv.json
# owner can see only one tree
assert trees == [{"id": self.tree, "name": self.name}]
assert trees == [{"id": self.tree, "name": self.name, "enabled": True}]

def test_get_tree(self):
rv = self.client.post(
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_get_tree(self):
headers={"Authorization": f"Bearer {token}"},
)
assert rv.status_code == 200
assert rv.json == {"name": self.name, "id": self.tree}
assert rv.json == {"name": self.name, "id": self.tree, "enabled": True}

def test_post_tree(self):
rv = self.client.post(
Expand Down Expand Up @@ -162,6 +162,7 @@ def test_post_tree(self):
assert rv.json["name"] == "some name"
assert rv.json["quota_media"] == 1000000
assert rv.json["quota_people"] is None
assert rv.json["enabled"]

def test_rename_tree(self):
rv = self.client.post(
Expand Down

0 comments on commit 0e3c4e8

Please sign in to comment.