Skip to content

Commit

Permalink
Merge pull request #1894 from T-CAIREM/au/event/feature/allow_partici…
Browse files Browse the repository at this point in the history
…pants_to_access_dataset

allow participants to access dataset through events
  • Loading branch information
tompollard authored Feb 23, 2023
2 parents 0688347 + 825623d commit 34465d3
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
21 changes: 21 additions & 0 deletions physionet-django/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ def is_accessible(self):
return False
return True

def has_access(self, user):
"""
checks if the user has access to the dataset for the Event
This method is independent of the PublishedProject.has_access method. it will only check if the user should
have access to the dataset for the event.
It is expected that the PublishedProject.has_access method will use this method to check if the user has access
in case the dataset access is made through an event.
"""
if not self.is_accessible():
return False

# check if the user is a participant of the event or the host of the event
# In addition to participants, host should also have access to the dataset of their own event
# we dont need to worry about cohosts here as they are already participants
if not self.event.participants.filter(user=user).exists() and not self.event.host == user:
return False

# TODO once Event Agreement/DUA is merged, check if the user has accepted the agreement

return True

def revoke_dataset_access(self):
"""
Revokes access to the dataset for the event.
Expand Down
45 changes: 45 additions & 0 deletions physionet-django/events/templates/events/event_datasets.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% load participation_status %}

<div class="container">
<h5>Datasets</h5>
<div class="card mb-3">
<div class="card-body">
{% if event_datasets %}
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Version</th>
<th scope="col">Access Type</th>
<th scope="col">Access</th>
</tr>
</thead>
<tbody>
{% for dataset in event_datasets %}
<tr>
<td>
<a href="{% url 'published_project' dataset.dataset.slug dataset.dataset.version %}">{{ dataset.dataset.title }}</a>
</td>
<td>{{ dataset.dataset.version }}</td>
<td>{{ dataset.get_access_type_display }}</td>
<td>
{% if not dataset.is_accessible %}
<a class="btn btn-success" href="#">Access Archieved</a>
{% elif is_waitlisted%}
<a class="btn btn-secondary" href="#">On waiting list</a>
{% elif user|has_access_to_event_dataset:dataset %}
<a class="btn btn-success" href="/environments/">Access here</a>
{% else %}
<p>Please register to the event for access</p>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No datasets available.</p>
{% endif %}
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions physionet-django/events/templates/events/event_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ <h4>Event Details</h4>
<hr>

{% include "events/event_participation.html" %}
<hr>
{% include "events/event_datasets.html" %}


</div>
Expand Down
5 changes: 5 additions & 0 deletions physionet-django/events/templatetags/participation_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ def is_on_waiting_list(user, event):
event=event,
status=EventApplication.EventApplicationStatus.WAITLISTED
).exists()


@register.filter(name='has_access_to_event_dataset')
def has_access_to_event_dataset(user, dataset):
return dataset.has_access(user)
5 changes: 5 additions & 0 deletions physionet-django/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,16 @@ def event_detail(request, event_slug):

# Handle Event Registration End #

# Handle Event Datastore Start #
event_datasets = event.datasets.filter(is_active=True)
# Handle Event Datastore End #

return render(
request,
'events/event_detail.html',
{'event': event,
'registration_allowed': registration_allowed,
'registration_error_message': registration_error_message,
'is_waitlisted': is_waitlisted,
'event_datasets': event_datasets,
})
17 changes: 17 additions & 0 deletions physionet-django/project/managers/publishedproject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import datetime

from django.db.models import Manager, Q
from events.models import Event, EventDataset
from project.models import AccessPolicy, DUASignature, DataAccessRequest
from user.models import Training, TrainingType

Expand Down Expand Up @@ -48,4 +51,18 @@ def accessible_by(self, user):
contributor_review_with_access | credentialed_with_dua_signed
)

# Event related logic
# get all projects that are accessible by user through Events(Used by `hdn-research-environment` package)
# get all active events that user is a participant/host of
events_all = Event.objects.filter(Q(host=user) | Q(participants__user=user))
active_events = set(events_all.filter(end_date__gte=datetime.now()))
# get all accessible datasets for the events
accessible_datasets = EventDataset.objects.filter(event__in=active_events, is_active=True)
# get all projects that are accessible to the user
accessible_projects_ids = []
for event_dataset in accessible_datasets:
if event_dataset.has_access(user):
accessible_projects_ids.append(event_dataset.dataset.id)

query |= Q(id__in=accessible_projects_ids)
return self.filter(query)

0 comments on commit 34465d3

Please sign in to comment.