From 5fba59176ddb8b40afc8b24fb2374376a3a3641d Mon Sep 17 00:00:00 2001
From: rutvikrj26
Date: Mon, 27 May 2024 20:17:47 -0400
Subject: [PATCH 01/12] updated queries and views to allow cohosts to both
see/respond to participation requests
---
physionet-django/events/models.py | 6 +++++
.../events/templates/events/event_home.html | 2 +-
physionet-django/events/views.py | 22 ++++++++++++++++---
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/physionet-django/events/models.py b/physionet-django/events/models.py
index 0842c97d36..10a98f02ba 100644
--- a/physionet-django/events/models.py
+++ b/physionet-django/events/models.py
@@ -59,6 +59,12 @@ def get_cohosts(self):
"""
return self.participants.filter(is_cohost=True)
+ def get_cohost_ids(self):
+ """
+ Returns a list of cohost ids for the event.
+ """
+ return self.participants.filter(is_cohost=True).values_list('user', flat=True)
+
class EventParticipant(models.Model):
"""
diff --git a/physionet-django/events/templates/events/event_home.html b/physionet-django/events/templates/events/event_home.html
index 34488c14ba..cef23ff269 100644
--- a/physionet-django/events/templates/events/event_home.html
+++ b/physionet-django/events/templates/events/event_home.html
@@ -82,7 +82,7 @@
{{ event.title }}
Registration status: On waiting list
{% endif %}
- {% if event.host == user %}
+ {% if user == event.host or user.id in event.get_cohost_ids %}
Share the class code: {{ url_prefix }}{% url 'event_detail' event.slug %}
diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py
index 6cb962511e..5c493bfaa2 100644
--- a/physionet-django/events/views.py
+++ b/physionet-django/events/views.py
@@ -109,6 +109,9 @@ def event_home(request):
form_error = False
+ cohost_ids = EventParticipant.objects.filter(
+ user=user, is_cohost=True).values_list("event__id", flat=True)
+
# handle notifications to join an event
if request.method == "POST" and "participation_response" in request.POST.keys():
formset = EventApplicationResponseFormSet(request.POST)
@@ -123,7 +126,13 @@ def event_home(request):
event_application = form.save(commit=False)
event = event_application.event
- if event.host != user:
+ # if user is not a host or a participant with cohort status, they don't have permission to accept/reject
+ if not (
+ event.host == user
+ or EventParticipant.objects.filter(
+ event=event, user=user, is_cohost=True
+ ).exists()
+ ):
messages.error(
request,
"You don't have permission to accept/reject this application",
@@ -228,14 +237,21 @@ def event_home(request):
# get all participation requests for Active events where the current user is the host and the participants are
# waiting for a response
+
+ # making the query to get all the participation requests for the events
+ # where the user is the host or an event participant with cohort status
participation_requests = EventApplication.objects.filter(
- status=EventApplication.EventApplicationStatus.WAITLISTED
- ).filter(event__host=user, event__end_date__gte=datetime.now())
+ Q(event__host=user) | Q(event__id__in=cohost_ids),
+ status=EventApplication.EventApplicationStatus.WAITLISTED,
+ event__end_date__gte=datetime.now(),
+ )
+
participation_response_formset = EventApplicationResponseFormSet(
queryset=participation_requests
)
invitation_response_formset = InvitationResponseFormSet(
queryset=CohostInvitation.get_user_invitations(user))
+
return render(
request,
"events/event_home.html",
From 8398fdf16472d20bf0d9cc57960b2b2fa87d0ac3 Mon Sep 17 00:00:00 2001
From: rutvikrj26
Date: Mon, 27 May 2024 21:10:48 -0400
Subject: [PATCH 02/12] removed redundant comments
---
physionet-django/events/views.py | 3 ---
1 file changed, 3 deletions(-)
diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py
index 5c493bfaa2..8030a449c5 100644
--- a/physionet-django/events/views.py
+++ b/physionet-django/events/views.py
@@ -235,9 +235,6 @@ def event_home(request):
},
]
- # get all participation requests for Active events where the current user is the host and the participants are
- # waiting for a response
-
# making the query to get all the participation requests for the events
# where the user is the host or an event participant with cohort status
participation_requests = EventApplication.objects.filter(
From c3d5bd1e9fed7b80049c523e430e59993f5d904c Mon Sep 17 00:00:00 2001
From: rutvikrj26
Date: Wed, 29 May 2024 11:55:26 -0400
Subject: [PATCH 03/12] Addressing the comments (improved UI for clarity &
better security to ensure proper dataacess only during the event
---
.../console/event_management_manage_dataset.html | 3 +++
physionet-django/console/views.py | 1 +
physionet-django/events/models.py | 6 ++++--
.../events/templates/events/event_home.html | 4 +++-
.../templates/events/event_notifications.html | 16 ++++++++++++++++
physionet-django/events/views.py | 7 +++++++
6 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/physionet-django/console/templates/console/event_management_manage_dataset.html b/physionet-django/console/templates/console/event_management_manage_dataset.html
index 6db04a7d52..91d6c7e647 100644
--- a/physionet-django/console/templates/console/event_management_manage_dataset.html
+++ b/physionet-django/console/templates/console/event_management_manage_dataset.html
@@ -4,6 +4,9 @@
Add a dataset to the event
+
By adding a dataset, all participants (approved by {{ event.host.username }} or their cohosts) will be allowed to access this
+ dataset for the duration of the event (from {{ event.start_date }} to {{ event.end_date }}). There are currently {{ event.participants.count }} approved
+ participants in this event. Note that once a dataset is added to the event, the dates of the event cannot be changed.