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/")