Skip to content

Commit

Permalink
Merge pull request #1876 from T-CAIREM/au/feature/event/allow_dua_cre…
Browse files Browse the repository at this point in the history
…ation_for_events

allow dua creation for events
  • Loading branch information
tompollard authored Feb 23, 2023
2 parents 34465d3 + 718fa2b commit 252e8e3
Show file tree
Hide file tree
Showing 11 changed files with 547 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
{% endif %}

<!-- legal -->
{% if perms.project.add_dua or perms.project.add_codeofconduct or perms.project.add_license %}
{% if perms.project.add_dua or perms.project.add_codeofconduct or perms.project.add_license or perms.events.add_eventagreement %}
<li class="nav-item" data-toggle="tooltip" data-placement="right">
{% if license_nav or dua_nav or code_of_conduct_nav %}
<a id="nav_credentialing_dropdown" class="nav-link nav-link-collapse drop" data-toggle="collapse" href="#license" data-parent="#sideAccordion" aria-expanded="true">
Expand All @@ -147,7 +147,7 @@
<span class="nav-link-text">Legal</span>
</a>
<!-- submenu -->
{% if license_nav or dua_nav or code_of_conduct_nav %}
{% if license_nav or dua_nav or code_of_conduct_nav or event_agreement_nav %}
<ul class="sidenav-second-level collapse show" id="license">
{% else %}
<ul class="sidenav-second-level collapse" id="license">
Expand All @@ -167,6 +167,11 @@
<a id="nav_code_of_conduct" class="nav-link" href="{% url 'code_of_conduct_list' %}">Code of Conduct</a>
</li>
{% endif %}
{% if perms.events.add_eventagreement %}
<li class="nav-item {% if event_agreement_nav %}active{% endif %}">
<a id="nav_event_agreement" class="nav-link" href="{% url 'event_agreement_list' %}">Event Agreements</a>
</li>
{% endif %}
</ul>
</li>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "console/base_console.html" %}

{% load static %}

{% block title %}{{ SITE_NAME }} - Event Agreements{% endblock %}

{% block content %}
<div class="card mb-3">
<div class="card-header">
{{ event_agreement.name }} - edit
</div>
<div class="card-body">
<form method="post" action="{% url 'event_agreement_detail' event_agreement.pk %}">
{% include "project/content_inline_form_snippet.html" with form=event_agreement_form %}
<button class="btn btn-primary btn-fixed" type="submit">Save</button>
</form>
</div>
</div>
{% endblock %}

{% block local_js_bottom %}
<script src="{% static 'custom/js/resize-ck.js' %}"></script>
<script src="{% static 'custom/js/enable-popover.js' %}"></script>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{% extends "console/base_console.html" %}

{% load static %}

{% block local_css %}
<link rel="stylesheet" type="text/css" href="{% static 'custom/css/pagination.css' %}">
{% endblock %}

{% block title %}{{ SITE_NAME }} - Event Agreements{% endblock %}

{% block content %}
<div class="card mb-3">
<div class="card-header">
Event Agreement <span class="badge badge-pill badge-info">{{ event_agreements|length }}</span>
</div>
<div class="card-body">
{% if event_agreements %}
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Version</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for event_agreement in event_agreements %}
<tr>
<td>
{{ event_agreement.name }}
{% if event_agreement.is_active %}
<span class="badge badge-success">Active</span>
{% else %}
<span class="badge badge-danger">Inactive</span>
{% endif %}
</td>
<td>{{ event_agreement.version }}</td>
<td>
<a href="{% url 'event_agreement_detail' event_agreement.pk %}" class="btn btn-sm btn-primary" role="button">Edit</a>
<a href="{% url 'event_agreement_new_version' event_agreement.pk %}" class="btn btn-sm btn-success" role="button">New version</a>
<button type="button" class="btn btn-sm btn-danger" data-toggle="modal" data-target="#remove-event-agreement-{{ event_agreement.pk }}">Delete</button>

<div class="modal fade" id="remove-event-agreement-{{ event_agreement.pk }}" tabindex="1" role="dialog" aria-hidden="true">
<form method="post" action="{% url 'event_agreement_delete' event_agreement.pk %}">
{% csrf_token %}
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete agreement</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete the agreement?</p>
</div>
<div class="modal-footer">
<button class="btn btn-danger" type="submit">Delete</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</form>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include "console/pagination.html" with pagination=event_agreements %}
</div>
{% else %}
<p>No event agreements available.</p>
{% endif %}
</div>
</div>
<div class="card mb-3">
<div class="card-header">
New Event Agreement
</div>
<div class="card-body">
<form method="post" action="{% url 'event_agreement_list' %}">
{% include "project/content_inline_form_snippet.html" with form=event_agreement_form %}
<button class="btn btn-primary btn-fixed" type="submit">Create</button>
</form>
</div>
</div>
{% endblock %}

{% block local_js_bottom %}
<script src="{% static 'custom/js/resize-ck.js' %}"></script>
<script src="{% static 'custom/js/enable-popover.js' %}"></script>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "console/base_console.html" %}

{% load static %}

{% block title %}{{ SITE_NAME }} - Event Agreements{% endblock %}

{% block content %}
<div class="card mb-3">
<div class="card-header">
{{ event_agreement.name }} - new version
</div>
<div class="card-body">
<form method="post" action="{% url 'event_agreement_new_version' event_agreement.pk %}">
{% include "project/content_inline_form_snippet.html" with form=event_agreement_form %}
<button class="btn btn-primary btn-fixed" type="submit">Create</button>
</form>
</div>
</div>
{% endblock %}

{% block local_js_bottom %}
<script src="{% static 'custom/js/resize-ck.js' %}"></script>
<script src="{% static 'custom/js/enable-popover.js' %}"></script>
{% endblock %}
172 changes: 172 additions & 0 deletions physionet-django/console/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from background_task.tasks import tasks
from django.test.utils import get_runner
from django.urls import reverse
from events.models import EventAgreement
from project.models import (
ActiveProject,
ArchivedProject,
Expand Down Expand Up @@ -614,3 +615,174 @@ def test_frontpage_button_delete(self):
reverse("frontpage_button_delete", args=(self.button_1.pk,)), follow=True)
self.assertRedirects(response, reverse("frontpage_buttons"), status_code=302)
self.assertEqual(FrontPageButton.objects.count(), frontpage_button_count - 1)


class TestEventAgreements(TestMixin):
""" Test that all views are behaving as expected """

def setUp(self):
"""Setup for tests"""

super().setUp()
self.event_agreement_name = "test event agreement"
self.event_agreement_version = "0.1"
self.event_agreement_version_invalid = "1"
self.event_agreement_version_new_version = "0.2"
self.event_agreement_slug = "pyvo3g6nuc"
self.event_agreement_slug_new_version = "a1b2c3d4e5"
self.updated_event_agreement_name = "updated test event agreement"
self.event_agreement_html_content = "<p>My test Event Agreement test content</p>"
self.event_agreement_access_template = "<p>My test Event Agreement test content</p>"

self.client.login(username='admin', password='Tester11!')

def test_add_event_agreement_valid(self):
"""tests the view that adds a valid event agreement"""

# Create an event Agreement
response = self.client.post(
reverse('event_agreement_list'),
data={
'name': self.event_agreement_name,
'version': self.event_agreement_version,
'slug': self.event_agreement_slug,
'is_active': True,
'html_content': self.event_agreement_html_content,
'access_template': self.event_agreement_access_template
})
self.assertEqual(response.status_code, 200)
event_agreement = EventAgreement.objects.get(slug=self.event_agreement_slug)
self.assertEqual(event_agreement.name, self.event_agreement_name)
return event_agreement

def test_add_event_agreement_invalid(self):
"""tests the view that adds an invalid event agreement"""

# Try to Create an Invalid event Agreement
response = self.client.post(
reverse('event_agreement_list'),
data={
'name': self.event_agreement_name,
'version': self.event_agreement_version_invalid,
'slug': self.event_agreement_slug,
'is_active': True,
'html_content': self.event_agreement_html_content,
'access_template': self.event_agreement_access_template
})

self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'console/event_agreement_list.html')

def test_edit_event_agreement_valid(self):
"""tests the view that edits a valid event agreement"""

event_agreement = self.test_add_event_agreement_valid()

# Edit the event Agreement
response = self.client.post(
reverse('event_agreement_detail', args=[event_agreement.pk]),
data={
'name': self.updated_event_agreement_name,
'version': self.event_agreement_version,
'slug': self.event_agreement_slug,
'is_active': True,
'html_content': self.event_agreement_html_content,
'access_template': self.event_agreement_access_template
})

self.assertEqual(response.status_code, 200)
event_agreement = EventAgreement.objects.get(slug=self.event_agreement_slug)
self.assertEqual(event_agreement.name, self.updated_event_agreement_name)

def test_edit_event_agreement_invalid_version(self):
"""tests the view that edits an invalid event agreement(invalid version)"""

event_agreement = self.test_add_event_agreement_valid()

# Edit the event Agreement
response = self.client.post(
reverse('event_agreement_detail', args=[event_agreement.pk]),
data={
'name': self.updated_event_agreement_name,
'version': self.event_agreement_version_invalid,
'slug': self.event_agreement_slug,
'is_active': True,
'html_content': self.event_agreement_html_content,
'access_template': self.event_agreement_access_template
})

self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'console/event_agreement_detail.html')

def test_delete_event_agreement(self):
"""tests the view that deletes an event agreement"""

event_agreement = self.test_add_event_agreement_valid()

# Delete the event Agreement
response = self.client.post(
reverse('event_agreement_delete', args=[event_agreement.pk]))

self.assertEqual(response.status_code, 302)
self.assertEqual(EventAgreement.objects.filter(slug=self.event_agreement_slug).exists(), False)

def test_event_agreement_new_version_valid(self):
"""tests the view that adds a valid new version of event agreement"""

event_agreement = self.test_add_event_agreement_valid()

# Create an event Agreement
response = self.client.post(
reverse('event_agreement_new_version', args=[event_agreement.pk]),
data={
'name': self.event_agreement_name,
'version': self.event_agreement_version_new_version,
'slug': self.event_agreement_slug_new_version,
'is_active': True,
'html_content': self.event_agreement_html_content,
'access_template': self.event_agreement_access_template
})

self.assertEqual(response.status_code, 302)
event_agreement = EventAgreement.objects.get(slug=self.event_agreement_slug_new_version)
self.assertEqual(event_agreement.version, self.event_agreement_version_new_version)

def test_event_agreement_new_version_invalid_slug(self):
"""tests the view that adds an invalid new version of event agreement(invalid slug)"""

event_agreement = self.test_add_event_agreement_valid()

# Create an event Agreement
response = self.client.post(
reverse('event_agreement_new_version', args=[event_agreement.pk]),
data={
'name': self.event_agreement_name,
'version': self.event_agreement_version_new_version,
'slug': self.event_agreement_slug,
'is_active': True,
'html_content': self.event_agreement_html_content,
'access_template': self.event_agreement_access_template
})

self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'console/event_agreement_new_version.html')

def test_event_agreement_new_version_invalid_version(self):
"""tests the view that adds an invalid new version of event agreement(invalid version)"""

event_agreement = self.test_add_event_agreement_valid()

# Create an event Agreement
response = self.client.post(
reverse('event_agreement_new_version', args=[event_agreement.pk]),
data={
'name': self.event_agreement_name,
'version': self.event_agreement_version_invalid,
'slug': self.event_agreement_slug_new_version,
'is_active': True,
'html_content': self.event_agreement_html_content,
'access_template': self.event_agreement_access_template
})

self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'console/event_agreement_new_version.html')
7 changes: 6 additions & 1 deletion physionet-django/console/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,10 @@
# Lists of event components
path('event/', views.event,
name='event'),
path('event/manage/<event_slug>', views.event_management, name='event_management')
path('event/manage/<event_slug>', views.event_management, name='event_management'),
path('event_agreements/', views.event_agreement_list, name='event_agreement_list'),
path('event_agreements/<int:pk>/', views.event_agreement_detail, name='event_agreement_detail'),
path('event_agreements/<int:pk>/delete/', views.event_agreement_delete, name='event_agreement_delete'),
path('event_agreements/<int:pk>/new-version/', views.event_agreement_new_version,
name='event_agreement_new_version'),
]
Loading

0 comments on commit 252e8e3

Please sign in to comment.