no there are credentials to present

This commit is contained in:
Cayo Puigdefabregas 2024-03-11 13:37:49 +01:00
parent 541f378ee6
commit 94334c9c0e
3 changed files with 24 additions and 0 deletions

View File

@ -20,6 +20,7 @@
</div>
</div>
{% endif %}
{% if form.if_credentials %}
<div class="row">
<div class="col-sm-4">
{% bootstrap_form form %}
@ -29,6 +30,13 @@
<a class="btn btn-grey" href="{% url 'idhub:user_credentials' %}">{% trans "Cancel" %}</a>
<input class="btn btn-green-user" type="submit" name="submit" value="{% trans 'Send' %}" />
</div>
{% else %}
<div class="row">
<div class="col-sm-4">
{% trans 'Sorry no there are credentials to present' %}
</div>
</div>
{% endif %}
</form>
{% endblock %}

View File

@ -130,6 +130,7 @@ class DemandAuthorizationForm(forms.Form):
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user', None)
self.if_credentials = kwargs.pop('if_credentials', None)
super().__init__(*args, **kwargs)
self.fields['organization'].choices = [
(x.id, x.name) for x in Organization.objects.exclude(

View File

@ -427,9 +427,24 @@ class DemandAuthorizationView(MyWallet, FormView):
form_class = DemandAuthorizationForm
success_url = reverse_lazy('idhub:user_demand_authorization')
def get(self, *args, **kwargs):
response = super().get(*args, **kwargs)
creds_enable = VerificableCredential.objects.filter(
user=self.request.user,
status=VerificableCredential.Status.ENABLED.value,
).exists()
if not self.if_credentials and creds_enable:
return redirect(reverse_lazy('idhub:user_credentials_request'))
return response
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['user'] = self.request.user
self.if_credentials = VerificableCredential.objects.filter(
user=self.request.user,
status=VerificableCredential.Status.ISSUED.value,
).exists()
kwargs['if_credentials'] = self.if_credentials
return kwargs
def form_valid(self, form):