From 4e1891884d405e31965373aeac0df0238048f2ec Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Wed, 28 Jul 2021 10:48:52 +0200 Subject: [PATCH 1/6] add ParticipationPseudonymView --- castellum/execution/urls.py | 6 ++++++ castellum/execution/views.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/castellum/execution/urls.py b/castellum/execution/urls.py index 799563742..416414423 100644 --- a/castellum/execution/urls.py +++ b/castellum/execution/urls.py @@ -36,6 +36,7 @@ from .views import ParticipationDetailView from .views import ParticipationDropoutConfirmView from .views import ParticipationDropoutView from .views import ParticipationPseudonymsView +from .views import ParticipationPseudonymView from .views import ParticipationUpdateView from .views import ProgressView from .views import ResolveView @@ -64,6 +65,11 @@ urlpatterns = [ ParticipationPseudonymsView.as_view(), name='participation-pseudonyms', ), + path( + '//pseudonyms//', + ParticipationPseudonymView.as_view(), + name='participation-pseudonym', + ), path( '//dropout/', ParticipationDropoutView.as_view(), diff --git a/castellum/execution/views.py b/castellum/execution/views.py index 73a12eaa7..c635f2827 100644 --- a/castellum/execution/views.py +++ b/castellum/execution/views.py @@ -38,6 +38,7 @@ from django.views.generic import FormView from django.views.generic import ListView from django.views.generic import TemplateView from django.views.generic import UpdateView +from django.views.generic import View from castellum.appointments.mixins import BaseAppointmentsUpdateView from castellum.appointments.mixins import BaseCalendarView @@ -199,6 +200,13 @@ class ParticipationPseudonymsView(ParticipationDetailMixin, DetailView): return context +class ParticipationPseudonymView(ParticipationDetailMixin, View): + def get(self, request, *args, **kwargs): + domain = get_object_or_404(self.study.domains, key=kwargs['domain']) + pseudonym = get_pseudonym(self.subject, domain.key) + return HttpResponse(pseudonym) + + class ParticipationDropoutView(ParticipationDetailMixin, DetailView): template_name = 'execution/participation_dropout.html' tab = 'overview' -- GitLab From dfbd73f550d273dcebf730b8f10cffe13c5ad879 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Wed, 28 Jul 2021 10:49:16 +0200 Subject: [PATCH 2/6] monitor ParticipationPseudonymView --- castellum/execution/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/castellum/execution/views.py b/castellum/execution/views.py index c635f2827..2efd3f293 100644 --- a/castellum/execution/views.py +++ b/castellum/execution/views.py @@ -204,6 +204,11 @@ class ParticipationPseudonymView(ParticipationDetailMixin, View): def get(self, request, *args, **kwargs): domain = get_object_or_404(self.study.domains, key=kwargs['domain']) pseudonym = get_pseudonym(self.subject, domain.key) + + monitoring_logger.info('Pseudonym access: domain {} by {}'.format( + domain.key, self.request.user.pk + )) + return HttpResponse(pseudonym) -- GitLab From 00a64645e412f6c59e5ab764adbd8256bc385fe6 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Wed, 28 Jul 2021 11:13:28 +0200 Subject: [PATCH 3/6] link to pseudonym view in execution participation detail --- .../execution/participation_detail.html | 18 +++++++++++++----- castellum/execution/views.py | 4 +--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/castellum/execution/templates/execution/participation_detail.html b/castellum/execution/templates/execution/participation_detail.html index c105b696f..0479cc7a9 100644 --- a/castellum/execution/templates/execution/participation_detail.html +++ b/castellum/execution/templates/execution/participation_detail.html @@ -2,19 +2,27 @@ {% load i18n utils auth %} {% block content %} - {% if pseudonyms|length > 1 %} + {% if domains|length > 1 %}

{% translate 'Pseudonyms' %}

- {% for domain, pseudonym in pseudonyms %} + {% for domain in domains %}
{{ domain }}
-
{{ pseudonym }}
+
+ + {% translate 'get pseudonym' %} + +
{% endfor %}
{% else %}
{% translate 'Pseudonym' %}
- {% for domain, pseudonym in pseudonyms %} -
{{ pseudonym }}
+ {% for domain in domains %} +
+ + {% translate 'get pseudonym' %} + +
{% endfor %}
{% endif %} diff --git a/castellum/execution/views.py b/castellum/execution/views.py index 2efd3f293..21f2fba60 100644 --- a/castellum/execution/views.py +++ b/castellum/execution/views.py @@ -168,9 +168,7 @@ class ParticipationDetailView(ParticipationDetailMixin, DetailView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['pseudonyms'] = [ - (d, get_pseudonym(self.subject, d.key)) for d in self.study.domains.all() - ] + context['domains'] = self.study.domains.all() return context -- GitLab From 00149883d841777677f2b2093691946ce9a09fc9 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Wed, 28 Jul 2021 11:13:54 +0200 Subject: [PATCH 4/6] load pseudonym inline --- .../templates/execution/participation_detail.html | 4 ++-- castellum/static/js/utils.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/castellum/execution/templates/execution/participation_detail.html b/castellum/execution/templates/execution/participation_detail.html index 0479cc7a9..54afacf58 100644 --- a/castellum/execution/templates/execution/participation_detail.html +++ b/castellum/execution/templates/execution/participation_detail.html @@ -8,7 +8,7 @@ {% for domain in domains %}
{{ domain }}
- + {% translate 'get pseudonym' %}
@@ -19,7 +19,7 @@
{% translate 'Pseudonym' %}
{% for domain in domains %}
- + {% translate 'get pseudonym' %}
diff --git a/castellum/static/js/utils.js b/castellum/static/js/utils.js index 62f4de501..6592fbf38 100644 --- a/castellum/static/js/utils.js +++ b/castellum/static/js/utils.js @@ -90,6 +90,13 @@ }, 800); }); + $$.on(document, 'click', '[data-js="replace-me"]', function(event) { + event.preventDefault(); + fetch(this.href, {credentials: 'same-origin'}) + .then(response => response.text()) + .then(pseudonym => this.parentElement.textContent = pseudonym); + }); + $.fn.select2.defaults.set('theme', 'bootstrap4'); $('[data-js="select2"]').select2(); $('[data-js="select2-tags"]').select2({tags: true}); -- GitLab From b5fa6bf4df3ea303ae7fedf8db2247184c03a74c Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Wed, 28 Jul 2021 11:31:21 +0200 Subject: [PATCH 5/6] use monitor pseudonym access also in ParticipationPseudonymsView --- .../execution/participation_pseudonyms.html | 8 ++++++-- castellum/execution/views.py | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/castellum/execution/templates/execution/participation_pseudonyms.html b/castellum/execution/templates/execution/participation_pseudonyms.html index 8035b2d4d..60a9c8997 100644 --- a/castellum/execution/templates/execution/participation_pseudonyms.html +++ b/castellum/execution/templates/execution/participation_pseudonyms.html @@ -15,11 +15,15 @@ - {% for domain, pseudonym in pseudonyms %} + {% for domain in domains %} {{ domain|display:'key' }} {{ domain|display:'name' }} - {{ pseudonym }} + + + {% translate 'get pseudonym' %} + + {% endfor %} diff --git a/castellum/execution/views.py b/castellum/execution/views.py index 21f2fba60..264c9fcb3 100644 --- a/castellum/execution/views.py +++ b/castellum/execution/views.py @@ -192,13 +192,19 @@ class ParticipationPseudonymsView(ParticipationDetailMixin, DetailView): context['subject'] = None context['participation'] = None - context['pseudonyms'] = [ - (d, get_pseudonym(self.subject, d.key)) for d in self.study.domains.all() - ] + context['domains'] = self.study.domains.all() + return context class ParticipationPseudonymView(ParticipationDetailMixin, View): + def has_permission(self): + return ( + super().has_permission() + or self.request.user.has_perm('subjects.export_subject') + or self.request.user.has_perm('subjects.delete_subject') + ) + def get(self, request, *args, **kwargs): domain = get_object_or_404(self.study.domains, key=kwargs['domain']) pseudonym = get_pseudonym(self.subject, domain.key) -- GitLab From 359a32f6f9563596447ce6ba304546c616e12327 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Wed, 28 Jul 2021 12:38:51 +0200 Subject: [PATCH 6/6] add loading animation --- castellum/static/js/utils.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/castellum/static/js/utils.js b/castellum/static/js/utils.js index 6592fbf38..1ae90745b 100644 --- a/castellum/static/js/utils.js +++ b/castellum/static/js/utils.js @@ -92,9 +92,15 @@ $$.on(document, 'click', '[data-js="replace-me"]', function(event) { event.preventDefault(); + + var spinner = document.createElement('i'); + spinner.className = 'fa fa-spinner fa-pulse'; + this.append(spinner); + fetch(this.href, {credentials: 'same-origin'}) .then(response => response.text()) - .then(pseudonym => this.parentElement.textContent = pseudonym); + .then(pseudonym => this.parentElement.textContent = pseudonym) + .catch(() => spinner.remove()); }); $.fn.select2.defaults.set('theme', 'bootstrap4'); -- GitLab