Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Added a web_admin role
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Oct 16, 2024
1 parent cbf0b77 commit 0caefd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ dmypy.json
# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# PyCharm and IntelliJ files
.idea/


11 changes: 9 additions & 2 deletions api/routes/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,19 @@ async def redirect_callback(code: str, state: Optional[str] = None):
user_data.get('email', '')
)

names = [group.name for group in user.groups]

# Check if the user is in the admin group to set the appropriate database role
role = "web_user"
if "admin" in names:
role = "web_admin"

access_token = create_access_token(
data={
"sub": user.sub,
"role": "web_user", # For PostgREST
"role": role, # For PostgREST
"groups": [group.id for group in user.groups],
"group_names": [group.name for group in user.groups]
"group_names": names
}
)

Expand Down

0 comments on commit 0caefd4

Please sign in to comment.