ixg_platform/apps/core/views.py
ixgadmin 19d67555da Add public buyer self-registration
A UK buyer can now create their own account at /portal/signup/. The screen
creates a Keycloak user through a least-privilege service account
(ixg-provisioning: manage-users, view-users) and the matching Django row as
a buyer, then sends them through the normal sign-in flow to the portal.

Staff status is derived from the role in the OIDC backend rather than
asserted, so a self-registered buyer is not staff and does not become staff
on a later sign-in. The platform root and the RBAC middleware now route
each role to its own portal, which also fixes a redirect loop that the
staff fix exposed for non-staff buyers.
2026-09-21 11:30:29 +00:00

27 lines
1 KiB
Python

from django.contrib.auth.views import redirect_to_login
from django.shortcuts import redirect
from django.views import View
class RoleRedirectView(View):
"""Send a signed-in user to their own portal; send visitors to sign-in.
The platform root is shared by all three portals, so it cannot point at one
of them. It used to hard-code ``/admin/``, which bounced a buyer off an area
they cannot enter; the destination now depends on the role.
``/`` deliberately sits outside every RBAC route prefix, so
``RBACMiddleware`` can redirect a wrong-role request here (via
``LOGIN_REDIRECT_URL``) without looping back into a route it would redirect
again.
"""
def get(self, request):
user = request.user
if not user.is_authenticated:
return redirect_to_login(request.get_full_path())
if user.role == "admin" or user.is_superuser:
return redirect("/admin/")
if user.role == "ops":
return redirect("/ops/")
return redirect("/portal/")