stages/otp_static: fix redirect URL after setup, fix stage not being passed to setup

This commit is contained in:
Jens Langhammer 2020-09-25 19:38:51 +02:00
parent 74d3cfbba0
commit 4ee22f8ec1
4 changed files with 7 additions and 4 deletions

View File

@ -11,7 +11,7 @@ class OTPStaticStageSerializer(ModelSerializer):
class Meta: class Meta:
model = OTPStaticStage model = OTPStaticStage
fields = ["pk", "name", "token_count"] fields = ["pk", "name", "configure_flow", "token_count"]
class OTPStaticStageViewSet(ModelViewSet): class OTPStaticStageViewSet(ModelViewSet):

View File

@ -32,7 +32,7 @@ class OTPStaticStageForm(forms.ModelForm):
class Meta: class Meta:
model = OTPStaticStage model = OTPStaticStage
fields = ["name", "token_count"] fields = ["name", "configure_flow", "token_count"]
widgets = { widgets = {
"name": forms.TextInput(), "name": forms.TextInput(),

View File

@ -26,7 +26,7 @@
</ul> </ul>
{% if not state %} {% if not state %}
{% if stage.configure_flow %} {% if stage.configure_flow %}
<a href="{% url 'passbook_flows:configure' stage_uuid=stage.stage_uuid %}" class="pf-c-button pf-m-primary">{% trans "Enable Static Tokens" %}</a> <a href="{% url 'passbook_flows:configure' stage_uuid=stage.stage_uuid %}?next={{ request.get_full_path }}" class="pf-c-button pf-m-primary">{% trans "Enable Static Tokens" %}</a>
{% endif %} {% endif %}
{% else %} {% else %}
<a href="{% url 'passbook_stages_otp_static:disable' stage_uuid=stage.stage_uuid %}" class="pf-c-button pf-m-danger">{% trans "Disable Static Tokens" %}</a> <a href="{% url 'passbook_stages_otp_static:disable' stage_uuid=stage.stage_uuid %}" class="pf-c-button pf-m-danger">{% trans "Disable Static Tokens" %}</a>

View File

@ -2,12 +2,13 @@
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect from django.shortcuts import get_object_or_404, redirect
from django.views import View from django.views import View
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django_otp.plugins.otp_static.models import StaticDevice, StaticToken from django_otp.plugins.otp_static.models import StaticDevice, StaticToken
from passbook.audit.models import Event from passbook.audit.models import Event
from passbook.stages.otp_static.models import OTPStaticStage
class UserSettingsView(LoginRequiredMixin, TemplateView): class UserSettingsView(LoginRequiredMixin, TemplateView):
@ -18,6 +19,8 @@ class UserSettingsView(LoginRequiredMixin, TemplateView):
# TODO: Check if OTP Stage exists and applies to user # TODO: Check if OTP Stage exists and applies to user
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs = super().get_context_data(**kwargs) kwargs = super().get_context_data(**kwargs)
stage = get_object_or_404(OTPStaticStage, pk=self.kwargs["stage_uuid"])
kwargs["stage"] = stage
static_devices = StaticDevice.objects.filter( static_devices = StaticDevice.objects.filter(
user=self.request.user, confirmed=True user=self.request.user, confirmed=True
) )