feat: admins only feature flag
This commit is contained in:
@ -15,7 +15,26 @@ router = APIRouter()
|
||||
async def home(
|
||||
request: Request, user=Depends(get_user), invites=Depends(get_invites)
|
||||
):
|
||||
from keycloak_collective_portal.config import (
|
||||
FEATURE_FLAG_ADMINS_ONLY,
|
||||
KEYCLOAK_ADMINS_GROUP,
|
||||
KEYCLOAK_GROUPS_KEY,
|
||||
)
|
||||
|
||||
context = {"request": request, "user": user, "invites": invites}
|
||||
|
||||
if FEATURE_FLAG_ADMINS_ONLY:
|
||||
context["message"] = "only admins can access this service"
|
||||
if KEYCLOAK_GROUPS_KEY not in user:
|
||||
return request.app.state.templates.TemplateResponse(
|
||||
"invalid.html", context=context
|
||||
)
|
||||
|
||||
if KEYCLOAK_ADMINS_GROUP not in user[KEYCLOAK_GROUPS_KEY]:
|
||||
return request.app.state.templates.TemplateResponse(
|
||||
"invalid.html", context=context
|
||||
)
|
||||
|
||||
return request.app.state.templates.TemplateResponse(
|
||||
"admin.html", context=context
|
||||
)
|
||||
|
Reference in New Issue
Block a user