Skip to content

Commit e510784

Browse files
authored
Some more minor fixes for 1.1.1 (#395)
* Forward logging properly * Handle tree=None properly
1 parent 3b1e725 commit e510784

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

gramps_webapi/api/resources/token.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ def post(self, args):
153153
abort_with_message(403, "Not allowed in single-tree setup")
154154
if tree and not tree_exists(tree):
155155
abort(404)
156-
if get_all_user_details(tree=tree):
156+
if get_all_user_details(
157+
# only include treeless users in single-tree setup
158+
tree=tree,
159+
include_treeless=current_app.config["TREE"] != TREE_MULTI,
160+
):
157161
# users already exist!
158162
abort_with_message(405, "Users already exist")
159163
if tree:

gramps_webapi/api/resources/user.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@ def get(self):
125125
require_permissions([PERM_VIEW_OTHER_USER])
126126
tree = get_tree_from_jwt()
127127
# return only this tree's users
128-
return jsonify(get_all_user_details(tree=tree)), 200
128+
# only include treeless users in single-tree setup
129+
is_single = current_app.config["TREE"] != TREE_MULTI
130+
details = get_all_user_details(tree=tree, include_treeless=is_single)
131+
return (
132+
jsonify(details),
133+
200,
134+
)
129135

130136
def post(self):
131137
"""Add one or more users."""

gramps_webapi/app.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ def create_app(config: Optional[Dict[str, Any]] = None):
8080

8181
app.logger.setLevel(logging.INFO)
8282

83-
# when using gunicorn, make sure flask log messages are shown
84-
gunicorn_logger = logging.getLogger("gunicorn.error")
85-
app.logger.handlers = gunicorn_logger.handlers
86-
app.logger.setLevel(gunicorn_logger.level)
87-
8883
# load default config
8984
app.config.from_object(DefaultConfig)
9085

gramps_webapi/auth/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,22 @@ def get_user_details(username: str) -> Optional[Dict[str, Any]]:
213213
return _get_user_detail(user)
214214

215215

216-
def get_all_user_details(tree: Optional[str]) -> List[Dict[str, Any]]:
216+
def get_all_user_details(
217+
tree: Optional[str], include_treeless=False
218+
) -> List[Dict[str, Any]]:
217219
"""Return details about all users.
218220
219221
If tree is None, return all users regardless of tree.
220222
If tree is not None, only return users of given tree.
223+
224+
If include_treeless is True, include also users with empty tree ID.
221225
"""
222226
query = user_db.session.query(User) # pylint: disable=no-member
223227
if tree:
224-
query = query.filter(sa.or_(User.tree == tree, User.tree.is_(None)))
228+
if include_treeless:
229+
query = query.filter(sa.or_(User.tree == tree, User.tree.is_(None)))
230+
else:
231+
query = query.filter(User.tree == tree)
225232
users = query.all()
226233
return [_get_user_detail(user) for user in users]
227234

gramps_webapi/wsgi.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Gramps Web API - A RESTful API for the Gramps genealogy program
33
#
4-
# Copyright (C) 2020 David Straub
4+
# Copyright (C) 2020-2023 David Straub
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU Affero General Public License as published by
@@ -17,6 +17,13 @@
1717
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
#
1919

20+
import logging
21+
2022
from .app import create_app
2123

2224
app = create_app()
25+
26+
# when using gunicorn, make sure flask log messages are shown
27+
gunicorn_logger = logging.getLogger("gunicorn.error")
28+
app.logger.handlers = gunicorn_logger.handlers
29+
app.logger.setLevel(gunicorn_logger.level)

0 commit comments

Comments
 (0)