From b2ce57f2d4df2069aa0a02a8c40f3e746eb4c129 Mon Sep 17 00:00:00 2001 From: Michael Scanlan Date: Thu, 19 Oct 2023 10:08:04 -0400 Subject: [PATCH 1/9] Add event functionality Adds invite event host functionality button temp --- .../templates/console/user_management.html | 4 ++++ physionet-django/console/urls.py | 1 + physionet-django/console/views.py | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/physionet-django/console/templates/console/user_management.html b/physionet-django/console/templates/console/user_management.html index 64900684ae..4ae02c704a 100644 --- a/physionet-django/console/templates/console/user_management.html +++ b/physionet-django/console/templates/console/user_management.html @@ -7,6 +7,10 @@ {% block content %}
+

{{ subject.get_full_name }} ({{ subject.username }})


Profile

diff --git a/physionet-django/console/urls.py b/physionet-django/console/urls.py index ace43bdac5..11e91f4cdc 100644 --- a/physionet-django/console/urls.py +++ b/physionet-django/console/urls.py @@ -156,6 +156,7 @@ path('event_agreements//delete/', views.event_agreement_delete, name='event_agreement_delete'), path('event_agreements//new-version/', views.event_agreement_new_version, name='event_agreement_new_version'), + path('console/user/manage//', views.event_invite_host, name='event_invite_host'), ] # Parameters for testing URLs (see physionet/test_urls.py) diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index 12991c989d..c35d432af4 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -3114,3 +3114,19 @@ def event_agreement_delete(request, pk): messages.success(request, "The Event Agreement has been deleted.") return redirect("event_agreement_list") + +@permission_required('user.view_all_events', 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') + user.groups.add(group) + user.save() + messages.success(request, f"{user} has been added to the Event Host group.") + except User.DoesNotExist: + messages.error(request, "User not found.") + + return redirect(reverse('user_management', args=[username])) From 152f53432f31c8017716a1954ed66a8fb02dfbb0 Mon Sep 17 00:00:00 2001 From: Michael Scanlan Date: Thu, 2 Nov 2023 15:05:54 -0400 Subject: [PATCH 2/9] fixed debian error --- physionet-django/console/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index c35d432af4..d4f2e064ea 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -3115,6 +3115,7 @@ def event_agreement_delete(request, pk): return redirect("event_agreement_list") + @permission_required('user.view_all_events', raise_exception=True) def event_invite_host(request, username): """ From 9cd28e2c1581bdade441a42bc27b02d04c8c7816 Mon Sep 17 00:00:00 2001 From: Michael Scanlan Date: Thu, 19 Oct 2023 10:08:04 -0400 Subject: [PATCH 3/9] Add event functionality Adds invite event host functionality button temp --- .../templates/console/user_management.html | 4 ++++ physionet-django/console/urls.py | 1 + physionet-django/console/views.py | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/physionet-django/console/templates/console/user_management.html b/physionet-django/console/templates/console/user_management.html index f82f3863ea..96a9bc3492 100644 --- a/physionet-django/console/templates/console/user_management.html +++ b/physionet-django/console/templates/console/user_management.html @@ -7,6 +7,10 @@ {% block content %}
+

{{ subject.get_full_name }} ({{ subject.username }})


Profile

diff --git a/physionet-django/console/urls.py b/physionet-django/console/urls.py index ace43bdac5..11e91f4cdc 100644 --- a/physionet-django/console/urls.py +++ b/physionet-django/console/urls.py @@ -156,6 +156,7 @@ path('event_agreements//delete/', views.event_agreement_delete, name='event_agreement_delete'), path('event_agreements//new-version/', views.event_agreement_new_version, name='event_agreement_new_version'), + path('console/user/manage//', views.event_invite_host, name='event_invite_host'), ] # Parameters for testing URLs (see physionet/test_urls.py) diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index 12991c989d..c35d432af4 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -3114,3 +3114,19 @@ def event_agreement_delete(request, pk): messages.success(request, "The Event Agreement has been deleted.") return redirect("event_agreement_list") + +@permission_required('user.view_all_events', 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') + user.groups.add(group) + user.save() + messages.success(request, f"{user} has been added to the Event Host group.") + except User.DoesNotExist: + messages.error(request, "User not found.") + + return redirect(reverse('user_management', args=[username])) From 1b81ea8f4c37ce5bbe2abe0280b1c333c597dcbe Mon Sep 17 00:00:00 2001 From: Michael Scanlan Date: Thu, 2 Nov 2023 15:05:54 -0400 Subject: [PATCH 4/9] fixed debian error --- physionet-django/console/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index c35d432af4..d4f2e064ea 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -3115,6 +3115,7 @@ def event_agreement_delete(request, pk): return redirect("event_agreement_list") + @permission_required('user.view_all_events', raise_exception=True) def event_invite_host(request, username): """ From a108095ce63e109177542c88e9ab7ac3761f34f8 Mon Sep 17 00:00:00 2001 From: Michael Scanlan Date: Fri, 3 Nov 2023 11:39:02 -0400 Subject: [PATCH 5/9] add request.method post to view --- physionet-django/console/views.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index d4f2e064ea..6519a15e3c 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -3121,13 +3121,14 @@ 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') - user.groups.add(group) - user.save() - messages.success(request, f"{user} has been added to the Event Host group.") - except User.DoesNotExist: - messages.error(request, "User not found.") + if request.method == 'POST': + try: + user = get_object_or_404(User, username=username) + group = Group.objects.get(name='Event Host') + user.groups.add(group) + user.save() + messages.success(request, f"{user} has been added to the Event Host group.") + except User.DoesNotExist: + messages.error(request, "User not found.") return redirect(reverse('user_management', args=[username])) From cc00a5727cdc4ff0de5f0f978e0e294418d879b8 Mon Sep 17 00:00:00 2001 From: Michael Scanlan Date: Mon, 27 Nov 2023 13:38:10 -0500 Subject: [PATCH 6/9] Migration file, invite_event_host perm req --- .../templates/console/user_management.html | 15 ++++++++++----- physionet-django/console/views.py | 2 +- .../migrations/0009_alter_event_options.py | 17 +++++++++++++++++ physionet-django/events/models.py | 1 + 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 physionet-django/events/migrations/0009_alter_event_options.py diff --git a/physionet-django/console/templates/console/user_management.html b/physionet-django/console/templates/console/user_management.html index 96a9bc3492..04cd28b40a 100644 --- a/physionet-django/console/templates/console/user_management.html +++ b/physionet-django/console/templates/console/user_management.html @@ -2,15 +2,21 @@ {% load static %} +{% load user_templatetags %} + {% block title %}User management{% endblock %} {% block content %}
- + {% if perms.self.invite_event_host%} + {% if user|has_group:'Event Host' %} + + {% endif %} + {% endif %}

{{ subject.get_full_name }} ({{ subject.username }})


Profile

@@ -211,6 +217,5 @@

Credentialing history

  • No applications found.
  • {% endfor %} -
    {% endblock %} diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index 6519a15e3c..164369ba7f 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -3116,7 +3116,7 @@ def event_agreement_delete(request, pk): return redirect("event_agreement_list") -@permission_required('user.view_all_events', raise_exception=True) +@permission_required('user.invite_event_host', raise_exception=True) def event_invite_host(request, username): """ Gives the user permissions to be an event host diff --git a/physionet-django/events/migrations/0009_alter_event_options.py b/physionet-django/events/migrations/0009_alter_event_options.py new file mode 100644 index 0000000000..64dd00e32f --- /dev/null +++ b/physionet-django/events/migrations/0009_alter_event_options.py @@ -0,0 +1,17 @@ +# 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')]}, + ), + ] diff --git a/physionet-django/events/models.py b/physionet-django/events/models.py index 0c253c58b6..a6fbe22266 100644 --- a/physionet-django/events/models.py +++ b/physionet-django/events/models.py @@ -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): From 5adc38d55831f85dca47b5d8678875e7e3f015dc Mon Sep 17 00:00:00 2001 From: Michael Scanlan <67070862+mscanlan-git@users.noreply.github.com> Date: Mon, 27 Nov 2023 13:49:04 -0500 Subject: [PATCH 7/9] fix line length --- .../events/migrations/0009_alter_event_options.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/physionet-django/events/migrations/0009_alter_event_options.py b/physionet-django/events/migrations/0009_alter_event_options.py index 64dd00e32f..cc51607733 100644 --- a/physionet-django/events/migrations/0009_alter_event_options.py +++ b/physionet-django/events/migrations/0009_alter_event_options.py @@ -12,6 +12,8 @@ class Migration(migrations.Migration): 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')]}, + 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')]}, ), ] From 759ef48cd3a334d028b7f1d150696bcc0f1dd4ee Mon Sep 17 00:00:00 2001 From: Michael Scanlan <67070862+mscanlan-git@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:13:03 -0500 Subject: [PATCH 8/9] fixed whitespaces cleaned formatting --- .../events/migrations/0009_alter_event_options.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/physionet-django/events/migrations/0009_alter_event_options.py b/physionet-django/events/migrations/0009_alter_event_options.py index cc51607733..9032560191 100644 --- a/physionet-django/events/migrations/0009_alter_event_options.py +++ b/physionet-django/events/migrations/0009_alter_event_options.py @@ -12,8 +12,12 @@ class Migration(migrations.Migration): 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')]}, + 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'), + ] + }, ), ] From fadf4548b5d7cbd340b279e7fd3514c4a87ea61f Mon Sep 17 00:00:00 2001 From: Michael Scanlan Date: Wed, 13 Dec 2023 12:01:23 -0500 Subject: [PATCH 9/9] Add error pop-up if admin is trying to add a user to event host group --- .../templates/console/user_management.html | 6 +++--- physionet-django/console/views.py | 17 +++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/physionet-django/console/templates/console/user_management.html b/physionet-django/console/templates/console/user_management.html index 04cd28b40a..270f36ad65 100644 --- a/physionet-django/console/templates/console/user_management.html +++ b/physionet-django/console/templates/console/user_management.html @@ -9,13 +9,13 @@ {% block content %}
    - {% if perms.self.invite_event_host%} - {% if user|has_group:'Event Host' %} + {% if perms.self.invite_event_host %} - {% endif %} + {% elif is_event_host %} +

    {{ subject.username }} is already an Event host.

    {% endif %}

    {{ subject.get_full_name }} ({{ subject.username }})


    diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index 164369ba7f..171d2890fa 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -3121,14 +3121,19 @@ def event_invite_host(request, username): """ Gives the user permissions to be an event host """ - if request.method == 'POST': - try: - user = get_object_or_404(User, username=username) - group = Group.objects.get(name='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.") - except User.DoesNotExist: - messages.error(request, "User not found.") + 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]))