Skip to content
Open
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
1 change: 1 addition & 0 deletions app/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Flow:
port : str
Port on which the message bus is listening for messages.
"""

def __init__(
self,
host=cfg["hosts.message_bus"],
Expand Down
15 changes: 15 additions & 0 deletions app/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ def user_id(self):
return self.get_secure_cookie("user_id")

def get_current_user(self):
user = self._signed_in_user()
if user is not None:
return user
# Anonymous read-only access (opt-in via app.anonymous_access): serve the
# configured "View only" account when nobody is signed in.
cfg = self.application.cfg
if not cfg.get("app.anonymous_access", False):
return None
username = cfg.get("app.anonymous_user") or "anonymous"
with DBSession() as session:
return session.scalars(
sqlalchemy.select(User).where(User.username == username)
).first()

def _signed_in_user(self):
if self.user_id() is None:
return
user_id = int(self.user_id())
Expand Down
Loading