Skip to content

Commit

Permalink
consider react router routes in caddy file (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur authored Aug 18, 2024
1 parent 50ba20b commit 07b7362
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
19 changes: 18 additions & 1 deletion docker/cloud/etc/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
}
}

@ExceptBackendPaths {
not {
path /oidc/callback
path /probe/
path /api/
}
}

forward_auth @ExceptPaths :8010 {
uri /verify
}
Expand All @@ -19,5 +27,14 @@ handle_path /api/* {
reverse_proxy :8000
}

# Will server /index.html for all paths except the ones for the backend.
# The point is that react router will take over URL.
# For example:
# /home/e87e06ed-66ee-482f-9be5-ee85501d59c4 -> index.html
# /document/42533b61-c856-491c-8e65-a901d9c777c4 -> index.html
# /api/users/me -> won't be handled here, but in the backend part
handle @ExceptBackendPaths {
try_files {path} /index.html
}
root * /usr/share/html/ui
file_server browse
file_server
22 changes: 10 additions & 12 deletions papermerge/core/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ def get_current_user(
total_scopes.extend(scopes.SCOPES.keys())
# augment user scopes with permissions associated to local groups
if len(token_data.groups) > 0:
total_scopes.extend(
db.get_user_scopes_from_groups(
engine=engine,
user_id=UUID(token_data.user_id),
groups=token_data.groups
)
s = db.get_user_scopes_from_groups(
engine=engine,
user_id=UUID(token_data.user_id),
groups=token_data.groups
)
total_scopes.extend(s)

elif remote_user: # get user from headers
# Using here external identity provider i.e.
Expand All @@ -111,13 +110,12 @@ def get_current_user(
total_scopes.extend(scopes.SCOPES.keys())
# augment user scopes with permissions associated to local groups
if len(remote_user.groups) > 0:
total_scopes.extend(
db.get_user_scopes_from_groups(
engine=engine,
user_id=user.id,
groups=remote_user.groups
)
s = db.get_user_scopes_from_groups(
engine=engine,
user_id=user.id,
groups=remote_user.groups
)
total_scopes.extend(s)

if user is None:
raise HTTPException(
Expand Down
2 changes: 2 additions & 0 deletions papermerge/core/db/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ def get_user_scopes_from_groups(
user_id: UUID,
groups: list[str]
) -> list[str]:

with Session(engine) as session:
db_user = session.get(User, user_id)

if db_user is None:
logger.debug(f"User with user_id {user_id} not found")
return []

db_groups = session.scalars(
Expand Down

0 comments on commit 07b7362

Please sign in to comment.