Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add login redirect #161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions django_sql_dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
JsonResponse,
StreamingHttpResponse,
)
from django.shortcuts import get_object_or_404, render
from django.utils.safestring import mark_safe

from psycopg2.extensions import quote_ident
from django.shortcuts import get_object_or_404, redirect, render

from .models import Dashboard
from .utils import (
Expand Down Expand Up @@ -341,9 +338,9 @@ def _dashboard_index(
},
json_dumps_params={
"indent": 2,
"default": lambda o: o.isoformat()
if hasattr(o, "isoformat")
else str(o),
"default": lambda o: (
o.isoformat() if hasattr(o, "isoformat") else str(o)
),
},
)

Expand Down Expand Up @@ -392,7 +389,8 @@ def dashboard(request, slug, json_mode=False):
# Can current user see it, based on view_policy?
view_policy = dashboard.view_policy
owner = dashboard.owned_by
denied = HttpResponseForbidden("You cannot access this dashboard")
login_url = f"/admin/login/?next={request.path}"
denied = redirect(login_url)
denied["cache-control"] = "private"
if view_policy == Dashboard.ViewPolicies.PRIVATE:
if request.user != owner:
Expand Down