Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add invite event host button on user management page #2123

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
11 changes: 10 additions & 1 deletion physionet-django/console/templates/console/user_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

{% load static %}

{% load user_templatetags %}

{% block title %}User management{% endblock %}

{% block content %}

<div class="col-md-9 no-pd">
{% if perms.self.invite_event_host %}
<form action="{% url 'event_invite_host' subject.username %}" method="post" class="form-signin" onsubmit="return confirm('Are you sure you would like to add this user as an event host?')">
{% csrf_token %}
<button class="btn btn-success btn-fixed" id="invite_host_button">Invite event host</button>
</form>
{% elif is_event_host %}
<p>{{ subject.username }} is already an Event host.</p>
{% endif %}
<h1>{{ subject.get_full_name }} ({{ subject.username }})</h1>
<br />
<h3>Profile</h3>
Expand Down Expand Up @@ -207,6 +217,5 @@ <h3>Credentialing history</h3>
<li>No applications found.</li>
{% endfor %}
</ul>

</div>
{% endblock %}
1 change: 1 addition & 0 deletions physionet-django/console/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
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'),
path('console/user/manage/<username>/', views.event_invite_host, name='event_invite_host'),

# Courses/On Platform Training
path('courses/', training_views.courses, name='courses'),
Expand Down
23 changes: 23 additions & 0 deletions physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3315,3 +3315,26 @@ def event_agreement_delete(request, pk):
messages.success(request, "The Event Agreement has been deleted.")

return redirect("event_agreement_list")


@permission_required('user.invite_event_host', raise_exception=True)
def event_invite_host(request, username):
"""
Gives the user permissions to be an event host
"""
try:
user = get_object_or_404(User, username=username)
group = Group.objects.get(name='Event Host')
is_event_host = user.groups.filter(name='Event Host').exists()

if not is_event_host and request.method == 'POST':
user.groups.add(group)
user.save()
messages.success(request, f"{user} has been added to the Event Host group.")
elif is_event_host:
messages.error(request, f"{user} is already an Event Host.")

except User.DoesNotExist:
messages.error(request, "User not found.")

return redirect(reverse('user_management', args=[username]))
23 changes: 23 additions & 0 deletions physionet-django/events/migrations/0009_alter_event_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.9 on 2023-11-17 20:27

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('events', '0008_alter_event_description'),
]

operations = [
migrations.AlterModelOptions(
name='event',
options={
'permissions': [
('view_all_events', 'Can view all events in the console'),
('invite_event_host', 'Can grant event host status to a user'),
('view_event_menu', 'Can view event menu in the navbar'),
]
},
),
]
1 change: 1 addition & 0 deletions physionet-django/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Event(models.Model):
class Meta:
unique_together = ('title', 'host')
permissions = [('view_all_events', 'Can view all events in the console'),
('invite_event_host', 'Can grant event host status to a user'),
('view_event_menu', 'Can view event menu in the navbar')]

def save(self, *args, **kwargs):
Expand Down
Loading