From 24c891424cbcd0c595ed883ef5814066dcac7edf Mon Sep 17 00:00:00 2001 From: Oliver Stolpe Date: Wed, 27 Nov 2024 13:34:21 +0100 Subject: [PATCH] feat: rework group manager interface (#311) (#344) --- Makefile | 13 + Pipfile.lock | 25 +- adminsec/templates/adminsec/overview.html | 7 +- adminsec/templates/adminsec/requests.html | 35 + .../adminsec/termsandconditions_list.html | 3 +- adminsec/tests/test_rules.py | 156 ++- adminsec/tests/test_views.py | 18 +- adminsec/views.py | 55 +- hpcaccess/static/js/project.js | 97 +- hpcaccess/templates/base.html | 6 + hpcaccess/templates/pages/login.html | 14 +- requirements/base.txt | 29 - requirements/ldap.txt | 3 - requirements/local.txt | 36 - requirements/production.txt | 9 - usersec/forms.py | 159 ++- .../0027_hpcgroup_date_modified_and_more.py | 209 +++ ...ojectcreaterequest_description_and_more.py | 33 + ...cprojectcreaterequest_delegate_and_more.py | 38 + usersec/models.py | 39 +- usersec/rules.py | 80 +- usersec/serializers.py | 20 + usersec/templates/usersec/form_field.html | 20 + .../templates/usersec/hpcgroup_detail.html | 1 - ...hpcgroupchangerequest_approve_confirm.html | 2 +- .../hpcgroupchangerequest_delete_confirm.html | 9 + .../hpcgroupchangerequest_deny_confirm.html | 2 +- .../usersec/hpcgroupchangerequest_detail.html | 93 +- .../usersec/hpcgroupchangerequest_form.html | 154 ++- ...hpcgroupchangerequest_retract_confirm.html | 2 +- ...hpcgroupcreaterequest_approve_confirm.html | 2 +- .../hpcgroupcreaterequest_delete_confirm.html | 7 + .../hpcgroupcreaterequest_deny_confirm.html | 2 +- .../usersec/hpcgroupcreaterequest_detail.html | 282 ++-- .../usersec/hpcgroupcreaterequest_form.html | 206 ++- ...hpcgroupcreaterequest_retract_confirm.html | 2 +- .../hpcgroupinvitation_reject_confirm.html | 2 +- .../templates/usersec/hpcproject_detail.html | 1 - ...cprojectchangerequest_approve_confirm.html | 2 +- ...pcprojectchangerequest_delete_confirm.html | 9 + .../hpcprojectchangerequest_deny_confirm.html | 2 +- .../hpcprojectchangerequest_detail.html | 108 +- .../usersec/hpcprojectchangerequest_form.html | 144 -- ...cprojectchangerequest_retract_confirm.html | 9 - ...cprojectcreaterequest_approve_confirm.html | 2 +- ...pcprojectcreaterequest_delete_confirm.html | 9 + .../hpcprojectcreaterequest_deny_confirm.html | 2 +- .../hpcprojectcreaterequest_detail.html | 325 +++-- .../usersec/hpcprojectcreaterequest_form.html | 326 +++-- ...cprojectcreaterequest_retract_confirm.html | 2 +- .../hpcprojectinvitation_reject_confirm.html | 2 +- usersec/templates/usersec/hpcuser_detail.html | 1 - .../hpcuserchangerequest_approve_confirm.html | 2 +- .../hpcuserchangerequest_delete_confirm.html | 9 + .../hpcuserchangerequest_deny_confirm.html | 2 +- .../usersec/hpcuserchangerequest_detail.html | 60 +- .../usersec/hpcuserchangerequest_form.html | 136 +- .../hpcuserchangerequest_retract_confirm.html | 2 +- .../hpcusercreaterequest_approve_confirm.html | 2 +- .../hpcusercreaterequest_delete_confirm.html | 9 + .../hpcusercreaterequest_deny_confirm.html | 2 +- .../usersec/hpcusercreaterequest_detail.html | 77 +- .../usersec/hpcusercreaterequest_form.html | 148 +-- .../hpcusercreaterequest_retract_confirm.html | 2 +- .../templates/usersec/modules/comments.html | 12 +- .../templates/usersec/modules/confirm.html | 63 +- usersec/templates/usersec/modules/manage.html | 193 +++ .../usersec/modules/overview_group.html | 4 +- .../usersec/modules/overview_projects.html | 8 +- .../modules/request_buttons_admin.html | 14 +- .../usersec/modules/request_buttons_user.html | 34 +- .../usersec/modules/request_grid.html | 111 -- .../modules/request_grid_group_change.html | 32 - .../modules/request_grid_group_create.html | 25 - .../modules/request_grid_group_delete.html | 29 - .../modules/request_grid_no_permission.html | 19 - .../modules/request_grid_project_change.html | 43 - .../modules/request_grid_project_create.html | 33 - .../modules/request_grid_project_delete.html | 29 - .../modules/request_grid_user_change.html | 36 - .../modules/request_grid_user_create.html | 33 - .../modules/request_grid_user_delete.html | 29 - .../usersec/modules/request_status_card.html | 27 + .../usersec/modules/resources_active.html | 8 +- usersec/templates/usersec/overview.html | 45 +- usersec/templatetags/common.py | 18 +- usersec/tests/factories.py | 2 +- usersec/tests/test_forms.py | 6 +- usersec/tests/test_rules.py | 1173 ++++++++++++++--- usersec/tests/test_templatetags.py | 8 +- usersec/tests/test_views.py | 691 ++++++---- usersec/tests/test_views_api.py | 63 + usersec/urls.py | 102 +- usersec/views.py | 541 +++++--- usersec/views_api.py | 24 + 95 files changed, 4090 insertions(+), 2630 deletions(-) create mode 100644 adminsec/templates/adminsec/requests.html delete mode 100644 requirements/base.txt delete mode 100644 requirements/ldap.txt delete mode 100644 requirements/local.txt delete mode 100644 requirements/production.txt create mode 100644 usersec/migrations/0027_hpcgroup_date_modified_and_more.py create mode 100644 usersec/migrations/0028_alter_hpcprojectcreaterequest_description_and_more.py create mode 100644 usersec/migrations/0029_hpcprojectcreaterequest_delegate_and_more.py create mode 100644 usersec/templates/usersec/form_field.html create mode 100644 usersec/templates/usersec/hpcgroupchangerequest_delete_confirm.html create mode 100644 usersec/templates/usersec/hpcgroupcreaterequest_delete_confirm.html create mode 100644 usersec/templates/usersec/hpcprojectchangerequest_delete_confirm.html delete mode 100644 usersec/templates/usersec/hpcprojectchangerequest_form.html delete mode 100644 usersec/templates/usersec/hpcprojectchangerequest_retract_confirm.html create mode 100644 usersec/templates/usersec/hpcprojectcreaterequest_delete_confirm.html create mode 100644 usersec/templates/usersec/hpcuserchangerequest_delete_confirm.html create mode 100644 usersec/templates/usersec/hpcusercreaterequest_delete_confirm.html create mode 100644 usersec/templates/usersec/modules/manage.html delete mode 100644 usersec/templates/usersec/modules/request_grid.html delete mode 100644 usersec/templates/usersec/modules/request_grid_group_change.html delete mode 100644 usersec/templates/usersec/modules/request_grid_group_create.html delete mode 100644 usersec/templates/usersec/modules/request_grid_group_delete.html delete mode 100644 usersec/templates/usersec/modules/request_grid_no_permission.html delete mode 100644 usersec/templates/usersec/modules/request_grid_project_change.html delete mode 100644 usersec/templates/usersec/modules/request_grid_project_create.html delete mode 100644 usersec/templates/usersec/modules/request_grid_project_delete.html delete mode 100644 usersec/templates/usersec/modules/request_grid_user_change.html delete mode 100644 usersec/templates/usersec/modules/request_grid_user_create.html delete mode 100644 usersec/templates/usersec/modules/request_grid_user_delete.html create mode 100644 usersec/templates/usersec/modules/request_status_card.html create mode 100644 usersec/tests/test_views_api.py create mode 100644 usersec/views_api.py diff --git a/Makefile b/Makefile index 217d6a9..7b61a76 100644 --- a/Makefile +++ b/Makefile @@ -57,3 +57,16 @@ _migrate: migrations .PHONY: migrate migrate: _migrate format + + +.PHONY: test-coverage +test-coverage: + coverage run --source=adminsec,usersec --omit={adminsec,usersec}/migrations/*,*.html manage.py test -v2 --settings=config.settings.test + coverage report + coverage html + +.PHONY: test-coverage-keepdb +test-coverage-keepdb: + coverage run --source=adminsec,usersec --omit={adminsec,usersec}/migrations/*,*.html manage.py test -v2 --settings=config.settings.test --keepdb + coverage report + coverage html diff --git a/Pipfile.lock b/Pipfile.lock index b28c902..bb4ce85 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -77,11 +77,11 @@ }, "async-timeout": { "hashes": [ - "sha256:4640d96be84d82d02ed59ea2b7105a0f7b33abe8703703cd0ab0bf87c427522f", - "sha256:7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028" + "sha256:49675ec889daacfe65ff66d2dde7dd1447a6f4b2f23721022e4ba121f8772a85", + "sha256:904719a4bd6e0520047d0ddae220aabee67b877f7ca17bf8cea20f67f6247ae0" ], "markers": "python_full_version < '3.11.3'", - "version": "==4.0.3" + "version": "==5.0.0" }, "billiard": { "hashes": [ @@ -367,7 +367,6 @@ "sha256:f46304d6f0c6ab8e52770addfa2fc41e6629495548862279641972b6215451cd", "sha256:f7b178f11ed3664fd0e995a47ed2b5ff0a12d893e41dd0494f406d1cf555cab7" ], - "markers": "python_version >= '3.7'", "version": "==43.0.3" }, "defusedxml": { @@ -1317,11 +1316,11 @@ }, "faker": { "hashes": [ - "sha256:4f7f133560b9d4d2a915581f4ba86f9a6a83421b89e911f36c4c96cff58135a5", - "sha256:93e8b70813f76d05d98951154681180cb795cfbcff3eced7680d963bcc0da2a9" + "sha256:4a82b2908cd19f3bba1a4da2060cc4eb18a40410ccdf9350d071d79dc92fe3ce", + "sha256:aa31b52cdae3673d6a78b4857c7bcdc0e98f201a5cb77d7827fa9e6b5876da94" ], "markers": "python_version >= '3.8'", - "version": "==30.8.1" + "version": "==30.8.2" }, "fastdiff": { "hashes": [ @@ -2221,11 +2220,11 @@ }, "werkzeug": { "hashes": [ - "sha256:1bc0c2310d2fbb07b1dd1105eba2f7af72f322e1e455f2f93c993bee8c8a5f17", - "sha256:a8dd59d4de28ca70471a34cba79bed5f7ef2e036a76b3ab0835474246eb41f8d" + "sha256:208a2e31a4a54c8b3d2244f2079ca1d3851629a7a7d546646059c64fb746023a", + "sha256:6f2a0d38f25ba5a75c36c45b4ae350c7a23b57e3b974e9eb2d6851f2c648c00d" ], "index": "pypi", - "version": "==3.0.6" + "version": "==3.1.0" } }, "ldap-packages": { @@ -2327,11 +2326,11 @@ }, "whitenoise": { "hashes": [ - "sha256:11042f39f1dcfbb3814726b9364703af6901706582d988e96494cfefdc3a89e2", - "sha256:196ba04ca0a80f4a3f99f88381864f218a28b5fb5b44d29feea484d501fa0ba3" + "sha256:486bd7267a375fa9650b136daaec156ac572971acc8bf99add90817a530dd1d4", + "sha256:df12dce147a043d1956d81d288c6f0044147c6d2ab9726e5772ac50fb45d2280" ], "index": "pypi", - "version": "==6.8.1" + "version": "==6.8.2" } } } diff --git a/adminsec/templates/adminsec/overview.html b/adminsec/templates/adminsec/overview.html index 43d0ff2..0e95ee5 100644 --- a/adminsec/templates/adminsec/overview.html +++ b/adminsec/templates/adminsec/overview.html @@ -4,16 +4,13 @@

- Welcome {% if user.first_name or user.last_name %} {{ user.first_name }} {{ user.last_name }}{% else %}{{ user.username }}{% endif %} - — + Welcome {% if user.first_name or user.last_name %} {{ user.first_name }} {{ user.last_name }}{% else %}{{ user.username }}{% endif %}! - Open Requests - Terms & Conditions

- {% include "usersec/modules/request_grid.html" %} + {% include "adminsec/requests.html" %} {% endblock content %} diff --git a/adminsec/templates/adminsec/requests.html b/adminsec/templates/adminsec/requests.html new file mode 100644 index 0000000..ce28360 --- /dev/null +++ b/adminsec/templates/adminsec/requests.html @@ -0,0 +1,35 @@ +{% load common %} + + + + + + + + + + + + {% for obj in pending_requests %} + + + + + + + {% empty %} + + + + {% endfor %} + +
Request TypeRequesterCreatedModified
+ + + {{ obj.get_request_type }} + + {{ obj.requester.name }}{{ obj.date_created|date:"Y-m-d H:i" }}{{ obj.date_modified|date:"Y-m-d H:i" }}
+ No pending requests. +
+ + diff --git a/adminsec/templates/adminsec/termsandconditions_list.html b/adminsec/templates/adminsec/termsandconditions_list.html index f86a451..4f1c46a 100644 --- a/adminsec/templates/adminsec/termsandconditions_list.html +++ b/adminsec/templates/adminsec/termsandconditions_list.html @@ -5,8 +5,7 @@

Terms & Conditions - - Go To Overview +

diff --git a/adminsec/tests/test_rules.py b/adminsec/tests/test_rules.py index 9db0985..1634c4a 100644 --- a/adminsec/tests/test_rules.py +++ b/adminsec/tests/test_rules.py @@ -62,7 +62,9 @@ def test_admin_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_user_detail_view(self): url = reverse( @@ -79,7 +81,9 @@ def test_hpc_user_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_project_detail_view(self): url = reverse( @@ -96,7 +100,9 @@ def test_hpc_project_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_detail_view(self): url = reverse( @@ -113,7 +119,9 @@ def test_hpc_group_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_create_request_approve_view_get(self): self.hpc_group_create_request.name = "new_group" @@ -133,7 +141,9 @@ def test_hpc_group_create_request_approve_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_create_request_approve_view_post(self): self.hpc_group_create_request.name = "new_group" @@ -166,8 +176,11 @@ def rollback_callback(): 302, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Successfully approved request for group creation."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_group_create_request_deny_view_get(self): url = reverse( @@ -184,7 +197,9 @@ def test_hpc_group_create_request_deny_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_create_request_deny_view_post(self): url = reverse( @@ -214,8 +229,11 @@ def rollback_callback(): redirect_url=reverse("adminsec:overview"), req_kwargs=data, rollback_callback=rollback_callback, + messages_exp=["Successfully denied request for group creation."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_group_create_request_revision_view_get(self): url = reverse( @@ -232,7 +250,9 @@ def test_hpc_group_create_request_revision_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_create_request_revision_view_post(self): url = reverse( @@ -262,6 +282,7 @@ def rollback_callback(): req_kwargs=data, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Successfully requested revision for group creation."], ) self.assert_permissions_on_url( bad_users, @@ -270,6 +291,7 @@ def rollback_callback(): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) def test_hpc_group_create_request_detail_view(self): @@ -287,7 +309,9 @@ def test_hpc_group_create_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_change_request_approve_view_get(self): url = reverse( @@ -304,7 +328,9 @@ def test_hpc_group_change_request_approve_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_change_request_approve_view_post(self): url = reverse( @@ -332,8 +358,11 @@ def rollback_callback(): 302, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Successfully approved request for group update."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_group_change_request_deny_view_get(self): url = reverse( @@ -350,7 +379,9 @@ def test_hpc_group_change_request_deny_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_change_request_deny_view_post(self): url = reverse( @@ -380,8 +411,11 @@ def rollback_callback(): redirect_url=reverse("adminsec:overview"), req_kwargs=data, rollback_callback=rollback_callback, + messages_exp=["Successfully denied request for group update."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_group_change_request_revision_view_get(self): url = reverse( @@ -398,7 +432,9 @@ def test_hpc_group_change_request_revision_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_change_request_revision_view_post(self): url = reverse( @@ -428,6 +464,7 @@ def rollback_callback(): req_kwargs=data, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Successfully requested revision for group update."], ) self.assert_permissions_on_url( bad_users, @@ -436,6 +473,7 @@ def rollback_callback(): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) def test_hpc_group_change_request_detail_view(self): @@ -453,7 +491,9 @@ def test_hpc_group_change_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_user_create_request_approve_view_get(self): url = reverse( @@ -470,7 +510,9 @@ def test_hpc_user_create_request_approve_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @patch("adminsec.ldap.LdapConnector.connect") @patch("adminsec.ldap.LdapConnector.get_ldap_username_domain_by_mail") @@ -509,8 +551,11 @@ def rollback_callback(): 302, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Request approved and invitation created."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_user_create_request_deny_view_get(self): url = reverse( @@ -527,7 +572,9 @@ def test_hpc_user_create_request_deny_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_user_create_request_deny_view_post(self): url = reverse( @@ -557,8 +604,11 @@ def rollback_callback(): redirect_url=reverse("adminsec:overview"), req_kwargs=data, rollback_callback=rollback_callback, + messages_exp=["Successfully denied request for user creation."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_user_create_request_revision_view_get(self): url = reverse( @@ -575,7 +625,9 @@ def test_hpc_user_create_request_revision_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_user_create_request_revision_view_post(self): url = reverse( @@ -605,6 +657,7 @@ def rollback_callback(): req_kwargs=data, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Successfully requested revision for user creation."], ) self.assert_permissions_on_url( bad_users, @@ -613,6 +666,7 @@ def rollback_callback(): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) def test_hpc_user_create_request_detail_view(self): @@ -630,7 +684,9 @@ def test_hpc_user_create_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_user_change_request_approve_view_get(self): url = reverse( @@ -647,7 +703,9 @@ def test_hpc_user_change_request_approve_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_user_change_request_approve_view_post(self): url = reverse( @@ -675,8 +733,11 @@ def rollback_callback(): 302, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Successfully approved request for user update."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_user_change_request_deny_view_get(self): url = reverse( @@ -693,7 +754,9 @@ def test_hpc_user_change_request_deny_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_user_change_request_deny_view_post(self): url = reverse( @@ -723,8 +786,11 @@ def rollback_callback(): redirect_url=reverse("adminsec:overview"), req_kwargs=data, rollback_callback=rollback_callback, + messages_exp=["Successfully denied request for user update."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_user_change_request_revision_view_get(self): url = reverse( @@ -741,7 +807,9 @@ def test_hpc_user_change_request_revision_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_user_change_request_revision_view_post(self): url = reverse( @@ -771,6 +839,7 @@ def rollback_callback(): req_kwargs=data, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Successfully requested revision for user update."], ) self.assert_permissions_on_url( bad_users, @@ -779,6 +848,7 @@ def rollback_callback(): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) def test_hpc_user_change_request_detail_view(self): @@ -796,7 +866,9 @@ def test_hpc_user_change_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_project_create_request_approve_view_get(self): self.hpc_project_create_request.name = "new_project" @@ -816,7 +888,9 @@ def test_hpc_project_create_request_approve_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_project_create_request_approve_view_post(self): self.hpc_project_create_request.name = "new_project" @@ -848,8 +922,11 @@ def rollback_callback(): 302, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Successfully approved request for project creation."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_project_create_request_deny_view_get(self): url = reverse( @@ -866,7 +943,9 @@ def test_hpc_project_create_request_deny_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_project_create_request_deny_view_post(self): url = reverse( @@ -896,8 +975,11 @@ def rollback_callback(): redirect_url=reverse("adminsec:overview"), req_kwargs=data, rollback_callback=rollback_callback, + messages_exp=["Request successfully denied."], + ) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) def test_hpc_project_create_request_revision_view_get(self): url = reverse( @@ -914,7 +996,9 @@ def test_hpc_project_create_request_revision_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_project_create_request_revision_view_post(self): url = reverse( @@ -945,6 +1029,7 @@ def rollback_callback(): req_kwargs=data, redirect_url=reverse("adminsec:overview"), rollback_callback=rollback_callback, + messages_exp=["Successfully requested revision for project creation."], ) self.assert_permissions_on_url( bad_users, @@ -953,6 +1038,7 @@ def rollback_callback(): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) def test_hpc_project_create_request_detail_view(self): @@ -970,4 +1056,6 @@ def test_hpc_project_create_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) diff --git a/adminsec/tests/test_views.py b/adminsec/tests/test_views.py index b4388c8..316f5f1 100644 --- a/adminsec/tests/test_views.py +++ b/adminsec/tests/test_views.py @@ -55,7 +55,7 @@ def test_get(self): self.assertEqual(response.status_code, 200) self.assertEqual( - list(response.context["hpcgroupcreaterequests"]), + list(response.context["pending_requests"]), list(HpcGroupCreateRequest.objects.active()), ) @@ -1477,8 +1477,9 @@ def setUp(self): status=REQUEST_STATUS_ACTIVE, name="new_project", folders={"tier1": "/path/new_project"}, + delegate=self.hpc_delegate, ) - self.obj.members.add(self.hpc_member, self.hpc_delegate) + self.obj.members.add(self.hpc_owner, self.hpc_delegate, self.hpc_member) def test_get(self): with self.login(self.user_hpcadmin): @@ -1492,6 +1493,7 @@ def test_get(self): self.assertIsNotNone(response.context["form"]) def test_post(self): + self.maxDiff = None with self.login(self.user_hpcadmin): response = self.client.post( reverse( @@ -1521,16 +1523,20 @@ def test_post(self): hpcproject = HpcProject.objects.get(name=self.obj.name) hpcproject_version = hpcproject.version_history.last() - invitation1 = HpcProjectInvitation.objects.first() - invitation2 = HpcProjectInvitation.objects.last() + invitation1, invitation2 = list(HpcProjectInvitation.objects.all()) self.assertEqual(invitation1.user, self.hpc_member) self.assertEqual(invitation2.user, self.hpc_delegate) self.assertEqual(hpcproject.group.owner, self.hpc_owner) self.assertEqual(hpcproject.name, self.obj.name) - self.assertEqual(list(hpcproject.members.all()), [self.hpc_owner]) - self.assertEqual(list(hpcproject_version.members.all()), [self.hpc_owner]) + self.assertEqual( + list(hpcproject.members.all()), [self.hpc_owner, self.hpc_member, self.hpc_delegate] + ) + self.assertEqual( + list(hpcproject_version.members.all()), + [self.hpc_owner, self.hpc_member, self.hpc_delegate], + ) self.assertEqual(len(mail.outbox), 3) diff --git a/adminsec/views.py b/adminsec/views.py index 5ddf5d2..0566010 100644 --- a/adminsec/views.py +++ b/adminsec/views.py @@ -1,4 +1,6 @@ import unicodedata +from datetime import datetime +from itertools import chain from django.conf import settings from django.contrib import messages @@ -9,7 +11,6 @@ from django.shortcuts import render from django.urls import reverse, reverse_lazy from django.utils import timezone -from django.utils.datetime_safe import datetime from django.views import View from django.views.generic import ( CreateView, @@ -174,32 +175,16 @@ def get_context_data(self, **kwargs): # Used as switch in template context["admin"] = True - # Add open HpcGroupCreateRequest - context["hpcgroupcreaterequests"] = HpcGroupCreateRequest.objects.active() - - # Add open HpcUserCreateRequest - context["hpcusercreaterequests"] = HpcUserCreateRequest.objects.active() - - # Add open HpcProjectCreateRequest - context["hpcprojectcreaterequests"] = HpcProjectCreateRequest.objects.active() - - # Add open HpcUserChangeRequest - context["hpcuserchangerequests"] = HpcUserChangeRequest.objects.active() - - # Add open HpcGroupChangeRequest - context["hpcgroupchangerequests"] = HpcGroupChangeRequest.objects.active() - - # Add open HpcProjectChangeRequest - context["hpcprojectchangerequests"] = HpcProjectChangeRequest.objects.active() - - # Add open HpcGroupDeleteRequest - context["hpcgroupdeleterequests"] = None - - # Add open HpcUserDeleteRequest - context["hpcuserdeleterequests"] = None - - # Add open HpcProjectDeleteRequest - context["hpcprojectdeleterequests"] = None + context["pending_requests"] = list( + chain( + HpcGroupCreateRequest.objects.active(), + HpcGroupChangeRequest.objects.active(), + HpcProjectCreateRequest.objects.active(), + HpcProjectChangeRequest.objects.active(), + HpcUserCreateRequest.objects.active(), + HpcUserChangeRequest.objects.active(), + ) + ) return context @@ -240,6 +225,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() context["hpc_group_name_suggestion"] = obj.name if obj.name else name tier1_work = folders.get("tier1_work") tier1_scratch = folders.get("tier1_scratch") @@ -490,6 +476,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() context["admin"] = True return context @@ -659,6 +646,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() context["admin"] = True return context @@ -822,6 +810,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() context["hpc_project_name_suggestion"] = name tier1_work = folders.get("tier1_work") tier1_scratch = folders.get("tier1_scratch") @@ -970,12 +959,14 @@ def post(self, request, *args, **kwargs): creator=self.request.user, status=OBJECT_STATUS_ACTIVE, expiration=obj.expiration, + delegate=obj.delegate, ) - project.members.add(obj.group.owner) - project.version_history.last().members.add(obj.group.owner) + members = list(obj.members.all()) + project.members.add(*members) + project.get_latest_version().members.add(*members) # Create invitations for users - for member in obj.members.all(): + for member in members: if member == obj.group.owner: continue @@ -1084,6 +1075,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() context["admin"] = True return context @@ -1237,6 +1229,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() context["admin"] = True return context @@ -1244,7 +1237,7 @@ def get_context_data(self, **kwargs): class HpcProjectChangeRequestRevisionView(HpcPermissionMixin, UpdateView): """HPC project change request revision view.""" - template_name = "usersec/hpcprojectchangerequest_form.html" + template_name = "usersec/hpcprojectcreaterequest_form.html" model = HpcProjectChangeRequest form_class = HpcProjectChangeRequestForm slug_field = "uuid" diff --git a/hpcaccess/static/js/project.js b/hpcaccess/static/js/project.js index d1ed616..7f8c9c2 100644 --- a/hpcaccess/static/js/project.js +++ b/hpcaccess/static/js/project.js @@ -1,30 +1,10 @@ /* Project specific Javascript goes here. */ -var delegate_id = null; - - -function buildSelectedMembers() { - $("#membersSelected").empty(); - - $("#id_members option:selected").each(function () { - let id = $(this).val(); - let element = '' + $(this).text(); - if (id !== delegate_id && id !== $("#submit").data("owner-id").toString()) { - element += ' X'; - } - element += ''; - $("#membersSelected").append(element); - }); - - $(".cancelMember").on('click', cancelMember) -} - - function mergeToJson() { - var content = []; + var content = [] $(".mergeToJson").each(function () { - content.push('"' + $(this).attr("name") + '": "' + $(this).val() + '"'); + content.push('"' + $(this).attr("name") + '": ' + $(this).val()); }); $("#id_resources_requested").val("{" + content.join(", ") + "}") } @@ -40,64 +20,31 @@ function jsonToFields() { } -function addOwnerMember() { - var members = $("#id_members").val(); - members.push($("#submit").data("owner-id").toString()); - $("#id_members").val(members); -} - - -function addDelegateMember() { - var members = $("#id_members").val(); - delegate_id = $("#id_delegate").val(); - var position = members.indexOf(delegate_id); - - if (position === -1) { - console.error("Delegate (" + delegate_id + ") not found in list. List of members: " + members) - return - } - - if (delegate_id) { - members.splice(position, 1); - $("#id_members").val(members); - } - - if (delegate_id) { - members.push(delegate_id); - $("#id_members").val(members); - } - - buildSelectedMembers(); -} - - -function addMember() { - var member_id = $("#id_members_dropdown").val(); - - if (member_id) { - var members = $("#id_members").val(); - - members.push(member_id); - $("#id_members").val(members); +function buildSelectedMembers() { + $("#membersSelected").empty(); + $("#id_members option:selected").each(function () { + const id = $(this).val(); + const isOwner = id === $("#submit").data("owner-id").toString(); + let cancelButton = ''; + if (!isOwner) { + cancelButton = ` + + `; + } - buildSelectedMembers(); - } + let element = `
  • + ${$(this).text()} + ${cancelButton} +
  • `; + $("#membersSelected").append(element); + }); + $(".cancelMember").on('click', cancelMember) } function cancelMember() { var member_id = $(this).data("member-id"); - var members = $("#id_members").val(); - var position = members.indexOf(member_id.toString()); - - if (position === -1) { - console.error("Member (" + member_id + ") not found in list. List of members: " + members) - return - } - - members.splice(position, 1); - - $("#id_members").val(members); - + $(`#id_delegate option[value='${member_id}']`).remove(); + $(`#id_members option[value='${member_id}']`).remove(); buildSelectedMembers(); } diff --git a/hpcaccess/templates/base.html b/hpcaccess/templates/base.html index e4650f1..96ab46e 100644 --- a/hpcaccess/templates/base.html +++ b/hpcaccess/templates/base.html @@ -65,6 +65,12 @@ integrity="sha384-FItuQ+AF7gqljIq5rozCj0vTwFbFlxfi7HCL/AHpP6jtDXICPcQyHXOceH/poGUw" crossorigin="anonymous" > + {% else %} {# Custom Javascript includes #} {% for js_inc in custom_js_includes %} diff --git a/hpcaccess/templates/pages/login.html b/hpcaccess/templates/pages/login.html index 894ec28..11dc229 100644 --- a/hpcaccess/templates/pages/login.html +++ b/hpcaccess/templates/pages/login.html @@ -4,11 +4,10 @@ {% block content %}
    - -

    - Welcome to HPC Access. -

    -

    +

    + Welcome to HPC Access! +

    +

    This website allows users of the BIH HPC cluster to

    -
    -

    +


    +

    Please log in using your Charité or MDC account.

    @@ -40,7 +39,6 @@
    str: + return obj.user.name + + class Meta: + model = HpcUser + fields = [ + "id", + "username", + "primary_group", + "full_name", + ] + + class HpcUserVersionSerializer(HpcUserAbstractSerializer, serializers.ModelSerializer): """Serializer for HpcUserVersion model.""" diff --git a/usersec/templates/usersec/form_field.html b/usersec/templates/usersec/form_field.html new file mode 100644 index 0000000..f4085d2 --- /dev/null +++ b/usersec/templates/usersec/form_field.html @@ -0,0 +1,20 @@ +
    + {% if field.errors %} + + {% endif %} +
    + {{ field }} + +
    + {% if field.help_text %} +

    {{ field.help_text }}

    + {% endif %} +
    diff --git a/usersec/templates/usersec/hpcgroup_detail.html b/usersec/templates/usersec/hpcgroup_detail.html index 1992a7f..9666eca 100644 --- a/usersec/templates/usersec/hpcgroup_detail.html +++ b/usersec/templates/usersec/hpcgroup_detail.html @@ -14,7 +14,6 @@

    - Go to Overview {% if not admin %} -
    -

    - HPC Group Change Request - - {{ object.display_status }} - - - {% if admin %} - {% include "usersec/modules/request_buttons_admin.html" %} - {% else %} - {% include "usersec/modules/request_buttons_user.html" %} - {% endif %} - -

    +

    + Request to Change the Group + + {% if admin %} + {% include "usersec/modules/request_buttons_admin.html" %} + {% else %} + {% include "usersec/modules/request_buttons_user.html" %} + {% endif %} + +

    + +{% if not admin %} + {% include "usersec/modules/request_status_card.html" %} +{% endif %} +
    +
    +
    + {% include "usersec/modules/resources_requested.html" with object=object %} + +
    Requester
    +
    {{ object.requester }}
    + +
    Description
    +
    {{ object.description }}
    + +
    Delegate
    +
    {{ object.delegate|default:"No delegate" }}
    + +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    +
    -
    - {% if object.status == "ACTIVE" %} -
    -
    - We are working on your request and you will receive an email once we approve it. -
    -
    - {% elif object.status == "RETRACTED" %} -
    -
    - You have retracted your group change request. - Click "Re-activate" to re-apply for the change. -
    -
    - {% elif object.status == "REVISION" %} -
    -
    - We have asked for you to revise your group change request. - See our comment and please answer any question. -
    -
    - {% endif %} -
    -
    -
    - {% include "usersec/modules/resources_requested.html" with object=object %} - -
    Requester
    -
    {{ object.requester }}
    - -
    Description
    -
    {{ object.description }}
    - -
    Delegate
    -
    {{ object.delegate|default:"No delegate" }}
    - -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    -
    -
    - {% include "usersec/modules/comments.html" %} -
    -
    +
    + {% include "usersec/modules/comments.html" %}
    +
    {% endblock content %} diff --git a/usersec/templates/usersec/hpcgroupchangerequest_form.html b/usersec/templates/usersec/hpcgroupchangerequest_form.html index a6bae67..e979a66 100644 --- a/usersec/templates/usersec/hpcgroupchangerequest_form.html +++ b/usersec/templates/usersec/hpcgroupchangerequest_form.html @@ -5,95 +5,91 @@ {% block content %} -
    -

    - {% if update %} - Update HPC group change request +

    + {% if update %} + {% if admin %} + Request Revision {% else %} - Request HPC group change + Update Group Request {% endif %} -

    -
    + {% else %} + Change Group Request + {% endif %} +

    {% include "usersec/modules/comments.html" %} -
    -
    - {% csrf_token %} - {% if admin %} -
    -
    Resource Quotas
    -
    -
    - {% for key, value in object.resources_requested.items %} -
    {{ key }}
    -
    {{ value }}
    - {% endfor %} -
    -
    - -
    Requester
    -
    {{ object.requester.username }}
    - -
    Description
    -
    {{ object.description }}
    - -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    - {% endif %} + + {% csrf_token %} + {% if admin %} +
    + {% include "usersec/modules/resources_requested.html" with object=object %} + +
    Requester
    +
    {{ object.requester.username }}
    + +
    Description
    +
    {{ object.description }}
    + +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    +
    + {% endif %} + + {% for field in form.hidden_fields %} + {{ field }} + {% endfor %} - {% for field in form.hidden_fields %} - {{ field }} - {% endfor %} - - {% for field in form.visible_fields %} -
    - {% if field.errors %} - - {% endif %} -
    - - {% if field.field.required %} - {{ field.label }}* - {% else %} - {{ field.label }} - {% endif %} - - {{ field }} -
    - {% if field.help_text %} -

    {{ field.help_text|safe }}

    - {% endif %} -
    - {% endfor %} + {% if admin %} +
    + {% endif %} + {% include "usersec/form_field.html" with field=form.description %} + {% include "usersec/form_field.html" with field=form.delegate %} + {% include "usersec/form_field.html" with field=form.expiration %} + +

    Resources

    + +
    +
    +
    Tier 1
    + {% include "usersec/form_field.html" with field=form.tier1_scratch %} +
    +
    +
    Tier 2
    + {% include "usersec/form_field.html" with field=form.tier2_unmirrored %} +
    +
    +
    +
    + {% include "usersec/form_field.html" with field=form.tier1_work %} +
    +
    + {% include "usersec/form_field.html" with field=form.tier2_mirrored %} +
    +
    + + {% if admin %} +
    + {% endif %} + + {% include "usersec/form_field.html" with field=form.comment %} + +
    + Cancel + + -
    -
    + {% else %} + Submit + {% endif %} + + {% endblock content %} {% block inline_javascript %} diff --git a/usersec/templates/usersec/hpcgroupchangerequest_retract_confirm.html b/usersec/templates/usersec/hpcgroupchangerequest_retract_confirm.html index 87cce4d..69b2267 100644 --- a/usersec/templates/usersec/hpcgroupchangerequest_retract_confirm.html +++ b/usersec/templates/usersec/hpcgroupchangerequest_retract_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Retract" object_type="HPC group change request" %} + {% include "usersec/modules/confirm.html" with action="Retract" object_type="request to change the group" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcgroupcreaterequest_approve_confirm.html b/usersec/templates/usersec/hpcgroupcreaterequest_approve_confirm.html index 6b37a6f..45fc1da 100644 --- a/usersec/templates/usersec/hpcgroupcreaterequest_approve_confirm.html +++ b/usersec/templates/usersec/hpcgroupcreaterequest_approve_confirm.html @@ -2,6 +2,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Approve" object_type="HPC group create request" %} + {% include "usersec/modules/confirm.html" with action="Approve" object_type="request to create a group" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcgroupcreaterequest_delete_confirm.html b/usersec/templates/usersec/hpcgroupcreaterequest_delete_confirm.html new file mode 100644 index 0000000..5f938b6 --- /dev/null +++ b/usersec/templates/usersec/hpcgroupcreaterequest_delete_confirm.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} + +{% block content %} + + {% include "usersec/modules/confirm.html" with action="Delete" object_type="request to create a group" %} + +{% endblock content %} diff --git a/usersec/templates/usersec/hpcgroupcreaterequest_deny_confirm.html b/usersec/templates/usersec/hpcgroupcreaterequest_deny_confirm.html index b515fb9..321bbc5 100644 --- a/usersec/templates/usersec/hpcgroupcreaterequest_deny_confirm.html +++ b/usersec/templates/usersec/hpcgroupcreaterequest_deny_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Deny" object_type="HPC group create request" %} + {% include "usersec/modules/confirm.html" with action="Deny" object_type="request to create a group" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcgroupcreaterequest_detail.html b/usersec/templates/usersec/hpcgroupcreaterequest_detail.html index eb96f21..dddd18a 100644 --- a/usersec/templates/usersec/hpcgroupcreaterequest_detail.html +++ b/usersec/templates/usersec/hpcgroupcreaterequest_detail.html @@ -4,167 +4,141 @@ {% block content %} -
    -
    -

    - HPC Group Request - - {{ object.display_status }} - - - {% if admin %} - {% include "usersec/modules/request_buttons_admin.html" %} - {% else %} - {% include "usersec/modules/request_buttons_user.html" with omit_home_button=1 %} - {% endif %} - -

    -
    -
    - {% if object.status == "ACTIVE" %} -
    -
    - We are working on your request and you will receive an email once we approve it. - Once your request has been approved, you can adjust the amount of resources that you applied for. -
    -
    - {% elif object.status == "RETRACTED" %} -
    -
    - You have retracted your group creation request. - Click "Re-activate" to re-apply for group creation. -
    -
    - {% elif object.status == "REVISION" %} -
    -
    - We have asked for you to revise your group request. - See our comment and please answer any question and/or update the resource requests. -
    -
    - {% endif %} - {% if admin %} -
    -
    - Note that you explicitly need to set the POSIX group name and the folder path for the group before approval. -
      -
    • POSIX name not yet submitted
    • -
    • Folder path not yet submitted
    • -
    -
    -
    - {% endif %} -
    -
    -
    - {% include "usersec/modules/resources_requested.html" with object=object %} +

    + Group Request + + {% if admin %} + {% include "usersec/modules/request_buttons_admin.html" %} + {% else %} + {% include "usersec/modules/request_buttons_user.html" with omit_home_button=1 %} + {% endif %} + + +

    + +{% if admin %} +
    +
    + Note that you explicitly need to set the POSIX group name and the folder path for the group before approval. +
      +
    • POSIX name not yet submitted
    • +
    • Folder path not yet submitted
    • +
    +
    +
    +{% else %} + {% include "usersec/modules/request_status_card.html" %} +{% endif %} + +
    + {% if admin %} +
    +
    + {% include "usersec/modules/resources_requested.html" with object=object %} -
    Requester
    -
    {{ object.requester.first_name }} {{ object.requester.last_name }} ({{ object.requester.username }})
    +
    Requester
    +
    {{ object.requester.first_name }} {{ object.requester.last_name }} ({{ object.requester.username }})
    - {% if admin %} -
    - POSIX Name - - - -
    -
    -
    - -
    -
    -
    +
    + POSIX Name + + + +
    +
    +
    + +
    +
    +
    -
    - Folders - - - -
    -
    -
    Tier 1
    -
    - Work - -
    -
    -
    - Scratch - -
    -
    -
    Tier 2
    -
    - Unmirrored - -
    -
    -
    - Mirrored - -
    -
    -
    - -
    -
    - {% endif %} +
    + Folders + + + +
    +
    +
    Tier 1
    +
    + Work + +
    +
    +
    + Scratch + +
    +
    +
    Tier 2
    +
    + Unmirrored + +
    +
    +
    + Mirrored + +
    +
    +
    + +
    +
    -
    Description
    -
    {{ object.description }}
    +
    Description
    +
    {{ object.description }}
    -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    -
    -
    - {% include "usersec/modules/comments.html" %} -
    -
    +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    +
    + {% endif %} +
    + {% include "usersec/modules/comments.html" %}
    -
    {% csrf_token %}
    +
    +
    {% csrf_token %}
    {% endblock content %} {% block inline_javascript %} diff --git a/usersec/templates/usersec/hpcgroupcreaterequest_form.html b/usersec/templates/usersec/hpcgroupcreaterequest_form.html index 0547d8d..d1d098d 100644 --- a/usersec/templates/usersec/hpcgroupcreaterequest_form.html +++ b/usersec/templates/usersec/hpcgroupcreaterequest_form.html @@ -4,139 +4,128 @@ {% block content %} -

    +

    {% if update %} - Update HPC group request + {% if admin %} + Request Revision + {% else %} + Update Group Request + {% endif %} {% else %} - Request HPC group + Create Group Request {% endif %} -

    + + {% if not admin %} -

    - As the first step is for principal investigators and group leaders to create a group on the cluster which gives their group/lab members a primary entity on the cluster. -

    -

    - Only "group leaders" can do this. - Example of group leaders are principal investigators, leaders of scientific or technical units, and junior group leaders. +

    + The first step for principal investigators and group leaders is to create a + group on the cluster. + Only "group leaders" can do this! + Example of group leaders are principal investigators, leaders of scientific or technical units, + and junior group leaders. As a group leader, you take responsibility for the action of your users on the cluster. Please provide a link to your group at Charite/MDC in the comment field for verification. -

    -

    You can add members to your groups and designate a delegate later on in the process.

    {% endif %} - {% include "usersec/modules/comments.html" %} +{% include "usersec/modules/comments.html" %} -
    -
    - {% csrf_token %} - {% if admin %} -
    - {% include "usersec/modules/resources_requested.html" with object=object %} + + {% csrf_token %} + {% if admin %} +
    + {% include "usersec/modules/resources_requested.html" with object=object %} -
    Requester
    -
    {{ object.requester.username }}
    +
    Requester
    +
    {{ object.requester.username }}
    -
    Description
    -
    {{ object.description }}
    +
    Description
    +
    {{ object.description }}
    -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    - {% endif %} +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    +
    + {% endif %} - {% for field in form.hidden_fields %} - {{ field }} - {% endfor %} + {% for field in form.hidden_fields %} + {{ field }} + {% endfor %} + + {% if admin %} +
    + {% endif %} - {% for field in form.visible_fields %} -
    - {% if field.errors %} - - {% endif %} -
    - - {% if field.field.required %} - {{ field.label }}* - {% else %} - {{ field.label }} - {% endif %} + {% include "usersec/form_field.html" with field=form.description %} + + {% if not admin %} +
    +
    + + + + +
    +

    + You must confirm that you are a group leader before you can submit the form. +

    +
    + {% if terms_list %} +

    Terms & Conditions

    + {% for obj in terms_list %} +

    {{ obj.title }}

    +

    {{ obj.text }}

    +
    + + + +
    - {% if field.help_text %} -

    {{ field.help_text|safe }}

    - {% endif %} +
    {% endfor %} + {% endif %} + {% endif %} + {% if admin %} +
    + {% endif %} + + {% include "usersec/form_field.html" with field=form.comment %} - {% if not admin %} -
    -
    - - - - -
    -

    - You must confirm that you are a group leader before you can submit the form. -

    -
    -

    Terms & Conditions

    - {% for obj in terms_list %} -

    {{ obj.title }}

    -

    {{ obj.text }}

    -
    - - - - -
    - {% endfor %} - {% endif %} - {% if update %} - - - Cancel - + {% if admin or update %} + - {% if update %} - {% if admin %} - - Request Revision - {% else %} - - Update - {% endif %} - {% else %} - - Submit - {% endif %} - - -
    + > + Cancel + + {% endif %} + + {% endblock content %} {% block inline_javascript %} + {% if not admin %} {{ block.super }} + {% endif %} {% endblock inline_javascript %} diff --git a/usersec/templates/usersec/hpcgroupcreaterequest_retract_confirm.html b/usersec/templates/usersec/hpcgroupcreaterequest_retract_confirm.html index 05600ef..7214a60 100644 --- a/usersec/templates/usersec/hpcgroupcreaterequest_retract_confirm.html +++ b/usersec/templates/usersec/hpcgroupcreaterequest_retract_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Retract" object_type="HPC group create request" %} + {% include "usersec/modules/confirm.html" with action="Retract" object_type="request to create a group" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcgroupinvitation_reject_confirm.html b/usersec/templates/usersec/hpcgroupinvitation_reject_confirm.html index 0c640f4..2d39c37 100644 --- a/usersec/templates/usersec/hpcgroupinvitation_reject_confirm.html +++ b/usersec/templates/usersec/hpcgroupinvitation_reject_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Reject" object_type="HPC group invitation" %} + {% include "usersec/modules/confirm.html" with action="Reject" object_type="group invitation" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcproject_detail.html b/usersec/templates/usersec/hpcproject_detail.html index 3f64e90..ca3e19e 100644 --- a/usersec/templates/usersec/hpcproject_detail.html +++ b/usersec/templates/usersec/hpcproject_detail.html @@ -14,7 +14,6 @@

    - Go to Overview {% if not admin %} -
    -

    - HPC Project Change Request - - {{ object.display_status }} - - - {% if admin %} - {% include "usersec/modules/request_buttons_admin.html" %} - {% else %} - {% include "usersec/modules/request_buttons_user.html" %} - {% endif %} - -

    -
    -
    -
    -
    -
    - {% include "usersec/modules/resources_requested.html" with object=object %} +

    + Request Project + + {% if admin %} + {% include "usersec/modules/request_buttons_admin.html" %} + {% else %} + {% include "usersec/modules/request_buttons_user.html" %} + {% endif %} + +

    -
    Requester
    -
    - {{ object.requester.name }} - {{ object.requester.hpcuser_user.first.username }} -
    +
    +
    +
    + {% include "usersec/modules/resources_requested.html" with object=object %} -
    Delegate
    -
    - {% if object.delegate %} - {{ object.delegate.user.name }} {{ object.delegate.username }} - {% else %} - No delegate. - {% endif %} -
    + {% if admin %} +
    Requester
    +
    + {{ object.requester.name }} + ({{ object.requester.hpcuser_user.first.username }}) +
    -
    Members
    -
    -
      - {% for member in object.members.all %} -
    • - {{ member.user.name }} {{ member.username }} -
    • - {% endfor %} -
    -
    +
    Associated Group
    +
    + AG {{ object.project.group.name.capitalize }} + — {{ object.project.group.owner.user.name }} + ({{ object.project.group.owner.username }}) +
    + {% endif %} -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    -
    -
    - {% include "usersec/modules/comments.html" %} -
    -
    -
    +
    Delegate
    +
    + {% if object.delegate %} + {{ object.delegate.user.name }} + ({{ object.delegate.username }}, AG {{ object.delegate.primary_group.name }}) + {% else %} + No delegate. + {% endif %} +
    + +
    Members
    +
    +
      + {% for member in object.members.all %} +
    • + {{ member.user.name }} ({{ member.username }}, AG {{ member.primary_group.name }}) +
    • + {% endfor %} +
    +
    + +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    + +
    +
    + {% include "usersec/modules/comments.html" %}
    +
    {% endblock content %} diff --git a/usersec/templates/usersec/hpcprojectchangerequest_form.html b/usersec/templates/usersec/hpcprojectchangerequest_form.html deleted file mode 100644 index 0ed1a8f..0000000 --- a/usersec/templates/usersec/hpcprojectchangerequest_form.html +++ /dev/null @@ -1,144 +0,0 @@ -{% extends 'base.html' %} - -{% load crispy_forms_tags %} -{% load common %} - -{% block content %} - -
    -

    - {% if update %} - Update HPC Project Change Request — {{ project.name }} ({{ project.group.owner.user.name }}) - {% else %} - Request HPC Project Change — {{ project.name }} ({{ project.group.owner.user.name }}) - {% endif %} -

    -
    - - {% include "usersec/modules/comments.html" %} - -
    -
    - {% csrf_token %} - {% if admin %} -
    -
    Resource Quotas
    -
    -
    - {% for key, value in object.resources_requested.items %} -
    {{ key }}
    -
    {{ value }}
    - {% endfor %} -
    -
    - -
    Requester
    -
    {{ object.requester.username }}
    - -
    Description
    -
    {{ object.description }}
    - -
    Members {{ object.members.count }}
    -
    -
      - {% for member in object.members.all %} -
    • {{ member }}
    • - {% endfor %} -
    -
    - -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    - {% endif %} - - {% for field in form.hidden_fields %} - {{ field }} - {% endfor %} - - {% for field in form.visible_fields %} -
    - {% if field.errors %} - - {% endif %} -
    - - {% if field.field.required %} - {{ field.label }}* - {% else %} - {{ field.label }} - {% endif %} - - {{ field }} - {% if field.label == "Select Members" %} - - {% endif %} -
    - {% if field.help_text %} -

    {{ field.help_text|safe }}

    - {% endif %} - {% if field.label == "Select Members" %} -
    Members selected
    -
    - No members selected. -
    - {% endif %} -
    - {% endfor %} - - {% if update %} - - - Cancel - - {% endif %} - -
    -
    -{% endblock content %} - -{% block inline_javascript %} - {{ block.super }} - -{% endblock inline_javascript %} diff --git a/usersec/templates/usersec/hpcprojectchangerequest_retract_confirm.html b/usersec/templates/usersec/hpcprojectchangerequest_retract_confirm.html deleted file mode 100644 index dfad2e6..0000000 --- a/usersec/templates/usersec/hpcprojectchangerequest_retract_confirm.html +++ /dev/null @@ -1,9 +0,0 @@ -{% extends 'base.html' %} - -{% load common %} - -{% block content %} - - {% include "usersec/modules/confirm.html" with action="Retract" object_type="HPC project change request" %} - -{% endblock content %} diff --git a/usersec/templates/usersec/hpcprojectcreaterequest_approve_confirm.html b/usersec/templates/usersec/hpcprojectcreaterequest_approve_confirm.html index 668b6c2..a1c6996 100644 --- a/usersec/templates/usersec/hpcprojectcreaterequest_approve_confirm.html +++ b/usersec/templates/usersec/hpcprojectcreaterequest_approve_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Approve" object_type="HPC project create request" %} + {% include "usersec/modules/confirm.html" with action="Approve" object_type="request to create a project" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcprojectcreaterequest_delete_confirm.html b/usersec/templates/usersec/hpcprojectcreaterequest_delete_confirm.html new file mode 100644 index 0000000..7f5e7ae --- /dev/null +++ b/usersec/templates/usersec/hpcprojectcreaterequest_delete_confirm.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} + +{% load common %} + +{% block content %} + + {% include "usersec/modules/confirm.html" with action="Delete" object_type="request to create a project" %} + +{% endblock content %} diff --git a/usersec/templates/usersec/hpcprojectcreaterequest_deny_confirm.html b/usersec/templates/usersec/hpcprojectcreaterequest_deny_confirm.html index 33d1f50..2405a0f 100644 --- a/usersec/templates/usersec/hpcprojectcreaterequest_deny_confirm.html +++ b/usersec/templates/usersec/hpcprojectcreaterequest_deny_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Deny" object_type="HPC project create request" %} + {% include "usersec/modules/confirm.html" with action="Deny" object_type="request to create a project" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcprojectcreaterequest_detail.html b/usersec/templates/usersec/hpcprojectcreaterequest_detail.html index 079b8db..347b666 100644 --- a/usersec/templates/usersec/hpcprojectcreaterequest_detail.html +++ b/usersec/templates/usersec/hpcprojectcreaterequest_detail.html @@ -4,188 +4,174 @@ {% block content %} -
    -
    -

    - HPC Project Request - - {{ object.display_status }} - - - {% if admin %} - {% include "usersec/modules/request_buttons_admin.html" %} - {% else %} - {% include "usersec/modules/request_buttons_user.html" %} - {% endif %} - -

    -
    -
    - {% if admin %} -
    -
    - Note that you explicitly need to set the POSIX project name and the folder path for the project before approval. -
      -
    • POSIX name not yet submitted
    • -
    • Folder path not yet submitted
    • -
    -
    -
    - {% endif %} -
    -
    -
    - {% include "usersec/modules/resources_requested.html" with object=object %} +

    + Request Project + + {% if admin %} + {% include "usersec/modules/request_buttons_admin.html" %} + {% else %} + {% include "usersec/modules/request_buttons_user.html" %} + {% endif %} + +

    -
    Requester
    -
    - {{ object.requester.name }} - ({{ object.requester.hpcuser_user.first.username }}) -
    +{% if admin %} +
    +
    + Note that you explicitly need to set the POSIX project name and the folder path for the project before approval. +
      +
    • POSIX name not yet submitted
    • +
    • Folder path not yet submitted
    • +
    +
    +
    +{% else %} + {% include "usersec/modules/request_status_card.html" %} +{% endif %} -
    Requested Name
    -
    {{ object.name_requested }}
    +
    +
    +
    + {% include "usersec/modules/resources_requested.html" with object=object %} - {% if admin %} -
    - POSIX Name - - - -
    -
    -
    - -
    -
    -
    +
    Requested Name
    +
    {{ object.name_requested }}
    -
    - Folders - - - -
    -
    -
    Tier 1
    -
    - Work - -
    -
    -
    - Scratch - -
    -
    -
    Tier 2
    -
    - Unmirrored - -
    -
    -
    - Mirrored - -
    -
    -
    - -
    - {% endif %} + {% if admin %} +
    Requester
    +
    + {{ object.requester.name }} + ({{ object.requester.hpcuser_user.first.username }}) +
    -
    Delegate
    -
    - {% if object.delegate %} - {{ object.delegate.user.name }} - {{ object.delegate.username }} - {% else %} - No delegate. - {% endif %} -
    +
    Associated Group
    +
    + AG {{ object.group.name.capitalize }} + — {{ object.group.owner.user.name }} + ({{ object.group.owner.username }}) +
    -
    Members
    -
    -
      - {% for member in object.members.all %} -
    • - {{ member.user.name }} ({{ member.username }}) -
    • - {% endfor %} -
    -
    +
    + POSIX Name + + + +
    +
    +
    + +
    +
    +
    -
    Associated Group
    -
    - AG {{ object.group.name.capitalize }} -
    -
    Owner
    -
    - {{ object.group.owner.user.name }} - ({{ object.group.owner.username }}) -
    - {% if object.group.delegate %} -
    Delegate
    -
    - {{ object.group.delegate.user.name }} - ({{ object.group.delegate.username }}) -
    - {% endif %} -
    -
    -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    +
    + Folders + + + +
    +
    +
    Tier 1
    +
    + Work + +
    +
    +
    + Scratch + +
    -
    - {% include "usersec/modules/comments.html" %} +
    Tier 2
    +
    + Unmirrored + +
    -
    -
    +
    + Mirrored + +
    +
    +
    + +
    + + {% endif %} + +
    Delegate
    +
    + {% if object.delegate %} + {{ object.delegate.user.name }} + ({{ object.delegate.username }}, AG {{ object.delegate.primary_group.name }}) + {% else %} + No delegate. + {% endif %} +
    + +
    Members
    +
    +
      + {% for member in object.members.all %} +
    • + {{ member.user.name }} ({{ member.username }}, AG {{ member.primary_group.name }}) +
    • + {% endfor %} +
    +
    + +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    +
    +
    +
    + {% include "usersec/modules/comments.html" %}
    +
    {% endblock content %} {% block inline_javascript %} + {% if admin %} + {% endif %} {% endblock inline_javascript %} diff --git a/usersec/templates/usersec/hpcprojectcreaterequest_form.html b/usersec/templates/usersec/hpcprojectcreaterequest_form.html index 2466ee6..cea646e 100644 --- a/usersec/templates/usersec/hpcprojectcreaterequest_form.html +++ b/usersec/templates/usersec/hpcprojectcreaterequest_form.html @@ -5,132 +5,254 @@ {% block content %} -
    -

    - {% if update %} - Update HPC Project Request +

    + {% if update %} + {% if admin %} + Request Revision {% else %} - Request HPC Project + Update Project Request {% endif %} -

    -
    + {% else %} + Create Project Request + {% endif %} +

    {% include "usersec/modules/comments.html" %} -
    -
    - {% csrf_token %} - {% if admin %} -
    - {% include "usersec/modules/resources_requested.html" with object=object %} - -
    Requester
    -
    {{ object.requester.username }}
    - -
    Description
    -
    {{ object.description }}
    - -
    Members {{ object.members.count }}
    -
    -
      - {% for member in object.members.all %} -
    • {{ member }}
    • - {% endfor %} -
    -
    - -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    - {% endif %} + + {% csrf_token %} + {% if admin %} +
    + {% include "usersec/modules/resources_requested.html" with object=object %} + +
    Requester
    +
    {{ object.requester.username }}
    + +
    Description
    +
    {{ object.description }}
    + +
    Members {{ object.members.count }}
    +
    +
      + {% for member in object.members.all %} +
    • {{ member }}
    • + {% endfor %} +
    +
    + +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    +
    + {% endif %} + + {% for field in form.hidden_fields %} + {{ field }} + {% endfor %} + + {% if admin %} +
    + {% endif %} + {{ form.members }} + + {% include "usersec/form_field.html" with field=form.name_requested %} + {% include "usersec/form_field.html" with field=form.description %} + {% include "usersec/form_field.html" with field=form.expiration %} + +

    Delegate

    + + {{ form.delegate }} - {% for field in form.hidden_fields %} - {{ field }} - {% endfor %} - - {% for field in form.visible_fields %} -
    - {% if field.errors %} - - {% endif %} -
    - - {% if field.field.required %} - {{ field.label }}* - {% else %} - {{ field.label }} - {% endif %} - - {{ field }} - {% if field.label == "Select Members" %} - - {% endif %} -
    - {% if field.help_text %} -

    {{ field.help_text|safe }}

    - {% endif %} - {% if field.label == "Select Members" %} -
    Members selected
    -
    - No members selected. -
    - {% endif %} +

    Members

    + +
      +
    +
    + +
    + +

    Resources

    + +
    +
    +
    Tier 1
    + {% include "usersec/form_field.html" with field=form.tier1_scratch %} +
    +
    +
    Tier 2
    + {% include "usersec/form_field.html" with field=form.tier2_unmirrored %} +
    +
    +
    +
    + {% include "usersec/form_field.html" with field=form.tier1_work %} +
    +
    + {% include "usersec/form_field.html" with field=form.tier2_mirrored %}
    - {% endfor %} +
    + {% if admin %} +
    + {% endif %} + {% include "usersec/form_field.html" with field=form.comment %} + + + Cancel + + - -
    + {% else %} + Submit Project Request + {% endif %} + + {% endblock content %} +{% block css %} + {{ block.super }} + +{% endblock css %} + {% block inline_javascript %} {{ block.super }} {% endblock inline_javascript %} diff --git a/usersec/templates/usersec/hpcprojectcreaterequest_retract_confirm.html b/usersec/templates/usersec/hpcprojectcreaterequest_retract_confirm.html index 7cc039c..12ef508 100644 --- a/usersec/templates/usersec/hpcprojectcreaterequest_retract_confirm.html +++ b/usersec/templates/usersec/hpcprojectcreaterequest_retract_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Retract" object_type="HPC project create request" %} + {% include "usersec/modules/confirm.html" with action="Retract" object_type="request to create a project" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcprojectinvitation_reject_confirm.html b/usersec/templates/usersec/hpcprojectinvitation_reject_confirm.html index a777db3..68b3723 100644 --- a/usersec/templates/usersec/hpcprojectinvitation_reject_confirm.html +++ b/usersec/templates/usersec/hpcprojectinvitation_reject_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Reject" object_type="HPC project invitation" %} + {% include "usersec/modules/confirm.html" with action="Reject" object_type="project invitation" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcuser_detail.html b/usersec/templates/usersec/hpcuser_detail.html index 7644d96..97b7c9a 100644 --- a/usersec/templates/usersec/hpcuser_detail.html +++ b/usersec/templates/usersec/hpcuser_detail.html @@ -14,7 +14,6 @@

    - Go to Overview {% if not admin %} -
    -

    - HPC User Change Request - - {{ object.display_status }} - - - {% if admin %} - {% include "usersec/modules/request_buttons_admin.html" %} - {% else %} - {% include "usersec/modules/request_buttons_user.html" %} - {% endif %} - -

    -
    -
    -
    -
    -
    -
    User
    -
    {{ object.user }}
    +

    + Extend User Expiration + + {% if admin %} + {% include "usersec/modules/request_buttons_admin.html" %} + {% else %} + {% include "usersec/modules/request_buttons_user.html" %} + {% endif %} + +

    -
    Requester
    -
    {{ object.requester }}
    +
    +
    +
    + {% if admin %} +
    Requester
    +
    {{ object.requester }}
    + {% endif %} -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    -
    -
    - {% include "usersec/modules/comments.html" %} -
    -
    -
    +
    User
    +
    {{ object.user }}
    + +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    + +
    +
    + {% include "usersec/modules/comments.html" %}
    +
    {% endblock content %} diff --git a/usersec/templates/usersec/hpcuserchangerequest_form.html b/usersec/templates/usersec/hpcuserchangerequest_form.html index 81f50f3..4f712e5 100644 --- a/usersec/templates/usersec/hpcuserchangerequest_form.html +++ b/usersec/templates/usersec/hpcuserchangerequest_form.html @@ -4,89 +4,75 @@ {% block content %} -
    -

    - {% if update %} - Update HPC User Change Request - {% else %} - Request HPC User Change - {% endif %} -

    -
    +

    + {% if update %} + {% if admin %} + Request Revision + {% else %} + Update User Change Request + {% endif %} + {% else %} + Create User Change Request + {% endif %} + — + {{ user }} +

    -
    - Change request is for user {{ user }} -
    +{% include "usersec/modules/comments.html" %} - {% include "usersec/modules/comments.html" %} +
    + {% csrf_token %} + {% if admin %} +
    +
    Requester
    +
    {{ object.requester.username }}
    -
    - - {% csrf_token %} - {% if admin %} -
    -
    Requester
    -
    {{ object.requester.username }}
    +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    +
    + {% endif %} -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    - {% endif %} + {% for field in form.hidden_fields %} + {{ field }} + {% endfor %} - {% for field in form.hidden_fields %} - {{ field }} - {% endfor %} - - {% for field in form.visible_fields %} -
    + {% if field.help_text %} +

    {{ field.help_text|safe }}

    + {% endif %} +

    + {% endfor %} + + + Cancel + + + {% endblock content %} diff --git a/usersec/templates/usersec/hpcuserchangerequest_retract_confirm.html b/usersec/templates/usersec/hpcuserchangerequest_retract_confirm.html index a25bbf8..5ba2966 100644 --- a/usersec/templates/usersec/hpcuserchangerequest_retract_confirm.html +++ b/usersec/templates/usersec/hpcuserchangerequest_retract_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Retract" object_type="HPC user change request" %} + {% include "usersec/modules/confirm.html" with action="Retract" object_type="request to change a user" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcusercreaterequest_approve_confirm.html b/usersec/templates/usersec/hpcusercreaterequest_approve_confirm.html index 1543e30..16d98c2 100644 --- a/usersec/templates/usersec/hpcusercreaterequest_approve_confirm.html +++ b/usersec/templates/usersec/hpcusercreaterequest_approve_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Approve" object_type="HPC user create request" %} + {% include "usersec/modules/confirm.html" with action="Approve" object_type="request to invite a user" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcusercreaterequest_delete_confirm.html b/usersec/templates/usersec/hpcusercreaterequest_delete_confirm.html new file mode 100644 index 0000000..f3efa20 --- /dev/null +++ b/usersec/templates/usersec/hpcusercreaterequest_delete_confirm.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} + +{% load common %} + +{% block content %} + + {% include "usersec/modules/confirm.html" with action="Delete" object_type="request to invite a user" %} + +{% endblock content %} diff --git a/usersec/templates/usersec/hpcusercreaterequest_deny_confirm.html b/usersec/templates/usersec/hpcusercreaterequest_deny_confirm.html index cdeb3b3..0a50199 100644 --- a/usersec/templates/usersec/hpcusercreaterequest_deny_confirm.html +++ b/usersec/templates/usersec/hpcusercreaterequest_deny_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Deny" object_type="HPC user create request" %} + {% include "usersec/modules/confirm.html" with action="Deny" object_type="request to invite a user" %} {% endblock content %} diff --git a/usersec/templates/usersec/hpcusercreaterequest_detail.html b/usersec/templates/usersec/hpcusercreaterequest_detail.html index d83ea24..03947b2 100644 --- a/usersec/templates/usersec/hpcusercreaterequest_detail.html +++ b/usersec/templates/usersec/hpcusercreaterequest_detail.html @@ -4,47 +4,42 @@ {% block content %} -
    -
    -

    - HPC User Request - - {{ object.display_status }} - - - {% if admin %} - {% include "usersec/modules/request_buttons_admin.html" %} - {% else %} - {% include "usersec/modules/request_buttons_user.html" %} - {% endif %} - -

    -
    -
    -
    -
    -
    -
    Requester
    -
    {{ object.requester }}
    - -
    Email
    -
    {{ object.email }}
    - -
    Group
    - {% if admin %} -
    {{ object.group.name }}
    - {% else %} -
    {{ object.group.name }}
    - {% endif %} -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    -
    -
    - {% include "usersec/modules/comments.html" %} -
    -
    -
    +

    + User Invitation Request + + {% if admin %} + {% include "usersec/modules/request_buttons_admin.html" %} + {% else %} + {% include "usersec/modules/request_buttons_user.html" %} + {% endif %} + +

    + +{% if not admin %} + {% include "usersec/modules/request_status_card.html" %} +{% endif %} + +
    +
    +
    + {% if admin %} +
    Requester
    +
    {{ object.requester }}
    + +
    Group
    +
    {{ object.group.name }}
    + {% endif %} + +
    Invitee
    +
    {{ object.email }}
    + +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    +
    +
    +
    + {% include "usersec/modules/comments.html" %}
    +
    {% endblock content %} diff --git a/usersec/templates/usersec/hpcusercreaterequest_form.html b/usersec/templates/usersec/hpcusercreaterequest_form.html index 02524fc..51610a2 100644 --- a/usersec/templates/usersec/hpcusercreaterequest_form.html +++ b/usersec/templates/usersec/hpcusercreaterequest_form.html @@ -4,105 +4,85 @@ {% block content %} -
    -

    - {% if update %} - Update HPC User Request - {% else %} - Request HPC User - {% endif %} -

    -
    +

    + {% if update %} + Update User Invitation + {% else %} + Invite User + {% endif %} +

    -

    +

    You can invite users with a Charite and MDC account to your group. - The user first has to accept the invitation and then HPC administration will approve the request after a sanity check. - Users can only be member of one group. + The user has to accept the invitation and then HPC administration will approve the request. + Users only can be member of one group. If a user should collaborate with another group, request an additional project and invite all relevant members to that project.

    {% include "usersec/modules/comments.html" %} -
    -
    - {% csrf_token %} - {% if admin %} -
    -
    Resource Quotas
    -
    -
    - {% for key, value in object.resources_requested.items %} -
    {{ key }}
    -
    {{ value }}
    - {% endfor %} -
    -
    + + {% csrf_token %} + {% if admin %} +
    +
    Resource Quotas
    +
    +
    + {% for key, value in object.resources_requested.items %} +
    {{ key }}
    +
    {{ value }}
    + {% endfor %} +
    +
    -
    Requester
    -
    {{ object.requester.username }}
    +
    Requester
    +
    {{ object.requester.username }}
    -
    Description
    -
    {{ object.description }}
    +
    Description
    +
    {{ object.description }}
    -
    Expiration
    -
    {{ object.expiration|date:"Y-m-d" }}
    -
    - {% endif %} +
    Expiration
    +
    {{ object.expiration|date:"Y-m-d" }}
    +
    + {% endif %} - {% for field in form.hidden_fields %} - {{ field }} - {% endfor %} + {% for field in form.hidden_fields %} + {{ field }} + {% endfor %} - {% for field in form.visible_fields %} -
    - {% if field.errors %} - - {% endif %} -
    - - {% if field.field.required %} - {{ field.label }}* - {% else %} - {{ field.label }} - {% endif %} - - {{ field }} -
    - {% if field.help_text %} -

    {{ field.help_text|safe }}

    - {% endif %} -
    - {% endfor %} + {% include "usersec/form_field.html" with field=form.email %} + {% include "usersec/form_field.html" with field=form.expiration %} + {% include "usersec/form_field.html" with field=form.comment %} + {% if update %} + + + Cancel + + {% else %} + + Cancel + + {% endif %} + -
    -
    + {% else %} + Submit + {% endif %} + + {% endblock content %} diff --git a/usersec/templates/usersec/hpcusercreaterequest_retract_confirm.html b/usersec/templates/usersec/hpcusercreaterequest_retract_confirm.html index 5528852..d26f014 100644 --- a/usersec/templates/usersec/hpcusercreaterequest_retract_confirm.html +++ b/usersec/templates/usersec/hpcusercreaterequest_retract_confirm.html @@ -4,6 +4,6 @@ {% block content %} - {% include "usersec/modules/confirm.html" with action="Retract" object_type="HPC user create request" %} + {% include "usersec/modules/confirm.html" with action="Retract" object_type="request to invite a user" %} {% endblock content %} diff --git a/usersec/templates/usersec/modules/comments.html b/usersec/templates/usersec/modules/comments.html index c5dbfa5..7f62f83 100644 --- a/usersec/templates/usersec/modules/comments.html +++ b/usersec/templates/usersec/modules/comments.html @@ -1,16 +1,18 @@ -{% if object.get_comment_history %} -
    +
    Comments
      {% for comment in object.get_comment_history %}
    • - {{ comment.1|date:"Y-d-m H:i" }} - {{ comment.0 }} + + {{ comment.1|date:"Y-m-d H:i" }} + {{ comment.0 }} + {{ comment.2 }}
    • + {% empty %} +
    • No comments.
    • {% endfor %}
    -{% endif %} diff --git a/usersec/templates/usersec/modules/confirm.html b/usersec/templates/usersec/modules/confirm.html index b82d1ef..d8f62ed 100644 --- a/usersec/templates/usersec/modules/confirm.html +++ b/usersec/templates/usersec/modules/confirm.html @@ -1,35 +1,30 @@ -
    -

    - {{ action }} {{ object_type }} -

    -
    +

    + {{ action }} {{ object_type }} +

    -
    -
    - {% csrf_token %} -

    - Are you sure you want to - - {{ action|upper }} - - the {{ object_type }}? -

    - {{ form }} - - - Cancel - - -
    -
    +
    + {% csrf_token %} +

    + Are you sure you want to + + {{ action|upper }} + + the {{ object_type }}? +

    + + + Cancel + + +
    diff --git a/usersec/templates/usersec/modules/manage.html b/usersec/templates/usersec/modules/manage.html new file mode 100644 index 0000000..3829f86 --- /dev/null +++ b/usersec/templates/usersec/modules/manage.html @@ -0,0 +1,193 @@ +{% load common %} + + + + +

    Open Requests

    + + + + + + + + + + + + + {% for obj in requests %} + + + + + + + + {% empty %} + + + + {% endfor %} + +
    Request TypeCreatedModifiedStatus
    {{ obj.get_request_type }}{{ obj.date_created|date:"Y-m-d H:i" }}{{ obj.date_modified|date:"Y-m-d H:i" }}{{ obj.status }} +
    + {% if is_decided %} + + + + {% endif %} + + + +
    +
    + No pending requests. +
    + +

    Group Members

    + + + + + + + + + + + + + {% for member in object.primary_group.hpcuser.all|order_by:"user__name" %} + + + + + + + + {% empty %} + + + + {% endfor %} + +
    NameUsernameJoinedExpires
    {{ member.user.name }}{{ member.username }}{{ member.date_created|date:"Y-m-d H:i" }}{{ member.expiration|date:"Y-m-d H:i" }} + +
    + No users. +
    + +

    Projects

    + + + + + + + + + + + + + {% for project in object.hpcproject_members.all|order_by:"name" %} + + + + + + + + {% empty %} + + + + {% endfor %} + +
    NameDelegateCreatedExpires
    {{ project.name }}{{ project.delegate.user.name|default:"None" }}{{ project.date_created|date:"Y-m-d H:i" }}{{ project.expiration|date:"Y-m-d H:i" }} + +
    + No projects. +
    + +{% block inline_javascript %} + + + +{% endblock inline_javascript %} \ No newline at end of file diff --git a/usersec/templates/usersec/modules/overview_group.html b/usersec/templates/usersec/modules/overview_group.html index 24e265b..1450dce 100644 --- a/usersec/templates/usersec/modules/overview_group.html +++ b/usersec/templates/usersec/modules/overview_group.html @@ -5,7 +5,7 @@

    AG {{ object.primary_group.name.capitalize }} {% if object.hpcgroup_owner.exists %} - Owner + Owner {% elif object.hpcgroup_delegate.exists %} Delegate {% else %} @@ -50,7 +50,7 @@

    diff --git a/usersec/templates/usersec/modules/overview_projects.html b/usersec/templates/usersec/modules/overview_projects.html index 2986d25..4ab485a 100644 --- a/usersec/templates/usersec/modules/overview_projects.html +++ b/usersec/templates/usersec/modules/overview_projects.html @@ -4,7 +4,9 @@

    Projects - {{ object.hpcproject_members.count }} + + {{ object.hpcproject_members.count }} +

    @@ -80,7 +82,7 @@

    - {{ form_project_select.projects }} -

    - {% endif %} -
    -
    -
      - {% for obj in hpcprojectchangerequests %} -
    • - {{ obj.project.name_requested }} - - {{ obj.display_status }} - -
      - {{ obj.requester.username }} - {{ obj.date_created|date:"Y-d-m H:i" }} -
      -
    • - {% empty %} -
    • No requests.
    • - {% endfor %} -
    -
    diff --git a/usersec/templates/usersec/modules/request_grid_project_create.html b/usersec/templates/usersec/modules/request_grid_project_create.html deleted file mode 100644 index 75c2090..0000000 --- a/usersec/templates/usersec/modules/request_grid_project_create.html +++ /dev/null @@ -1,33 +0,0 @@ -{% load common %} - -
    -
    -
    - {% if admin %} - - Create Requests - {% else %} - - - Request New Project - - {% endif %} -
    -
    -
      - {% for obj in hpcprojectcreaterequests %} -
    • - {{ obj.name_requested }} - - {{ obj.display_status }} - -
      - {{ obj.requester.username }} - {{ obj.date_created|date:"Y-d-m H:i" }} -
      -
    • - {% empty %} -
    • No requests.
    • - {% endfor %} -
    -
    diff --git a/usersec/templates/usersec/modules/request_grid_project_delete.html b/usersec/templates/usersec/modules/request_grid_project_delete.html deleted file mode 100644 index 73b6ab8..0000000 --- a/usersec/templates/usersec/modules/request_grid_project_delete.html +++ /dev/null @@ -1,29 +0,0 @@ -{% load common %} - -
    -
    -
    - {% if admin %} - - Delete Requests - {% else %} - - - Delete Project - - {% endif %} -
    -
    -
      - {% for obj in hpcprojectdeleterequests %} -
    • - {{ obj.requester.username }} - - {{ obj.display_status }} - -
    • - {% empty %} -
    • No requests.
    • - {% endfor %} -
    -
    diff --git a/usersec/templates/usersec/modules/request_grid_user_change.html b/usersec/templates/usersec/modules/request_grid_user_change.html deleted file mode 100644 index 01ab006..0000000 --- a/usersec/templates/usersec/modules/request_grid_user_change.html +++ /dev/null @@ -1,36 +0,0 @@ -{% load common %} - -
    -
    -
    - {% if admin %} - - Change Requests - {% else %} -
    - - {{ form_user_select.members }} -
    - {% endif %} -
    -
    -
      - {% for obj in hpcuserchangerequests %} -
    • - {{ obj.user.user.name }} | - {{ obj.user.username }} - - {{ obj.display_status }} - -
      - {{ obj.requester.username }} - {{ obj.date_created|date:"Y-d-m H:i" }} -
    • - {% empty %} -
    • No requests.
    • - {% endfor %} -
    -
    diff --git a/usersec/templates/usersec/modules/request_grid_user_create.html b/usersec/templates/usersec/modules/request_grid_user_create.html deleted file mode 100644 index b5b4ba3..0000000 --- a/usersec/templates/usersec/modules/request_grid_user_create.html +++ /dev/null @@ -1,33 +0,0 @@ -{% load common %} - -
    -
    -
    - {% if admin %} - - Create Requests - {% else %} - - - Add User To Group - - {% endif %} -
    -
    -
      - {% for obj in hpcusercreaterequests %} -
    • - {{ obj.email }} - - {{ obj.display_status }} - -
      - {{ obj.requester.username }} - {{ obj.date_created|date:"Y-d-m H:i" }} -
      -
    • - {% empty %} -
    • No requests.
    • - {% endfor %} -
    -
    diff --git a/usersec/templates/usersec/modules/request_grid_user_delete.html b/usersec/templates/usersec/modules/request_grid_user_delete.html deleted file mode 100644 index 7782531..0000000 --- a/usersec/templates/usersec/modules/request_grid_user_delete.html +++ /dev/null @@ -1,29 +0,0 @@ -{% load common %} - -
    -
    -
    - {% if admin %} - - Delete Requests - {% else %} - - - Delete User - - {% endif %} -
    -
    -
      - {% for obj in hpcuserdeleterequests %} -
    • - {{ obj.requester.username }} - - {{ obj.display_status }} - -
    • - {% empty %} -
    • No requests.
    • - {% endfor %} -
    -
    diff --git a/usersec/templates/usersec/modules/request_status_card.html b/usersec/templates/usersec/modules/request_status_card.html new file mode 100644 index 0000000..544b8f4 --- /dev/null +++ b/usersec/templates/usersec/modules/request_status_card.html @@ -0,0 +1,27 @@ +{% load common %} + +
    +
    + {% if object.status == "ACTIVE" or object.status == "REVISED" %} + We are working on your request and you will receive an email once we approve it. + {% elif object.status == "RETRACTED" %} + You have retracted your request. Click Re-activate to activate the request. + {% elif object.status == "REVISION" %} + We have asked you to revise your request with the following comment: +

    + {% with object.get_comment_history|last as comment %} + "{{ comment.2 }}" + {% endwith %} +

    + {% elif object.status == "APPROVED" %} + We have approved your request. + {% elif object.status == "DENIED" %} + We have denied your request with the following comment: +

    + {% with object.get_comment_history|last as comment %} + "{{ comment.2 }}" + {% endwith %} +

    + {% endif %} +
    +
    \ No newline at end of file diff --git a/usersec/templates/usersec/modules/resources_active.html b/usersec/templates/usersec/modules/resources_active.html index b7e8dc7..b7263b3 100644 --- a/usersec/templates/usersec/modules/resources_active.html +++ b/usersec/templates/usersec/modules/resources_active.html @@ -16,7 +16,7 @@
    Fast Active Storage (Tier 1)
    -
    +
    {% with percentage=object.generate_quota_report.percentage.tier1_work status=object.generate_quota_report.status.tier1_work %}
    {{ percentage }}% @@ -34,7 +34,7 @@
    Fast Active Storage (Tier 1)
    {{ object.folders.tier1_scratch|highlight_folder:"scratch" }}
    -
    +
    {% with percentage=object.generate_quota_report.percentage.tier1_scratch status=object.generate_quota_report.status.tier1_scratch %}
    {{ percentage }}% @@ -56,7 +56,7 @@
    Long-Term Storage (Tier 2)
    {{ object.folders.tier2_unmirrored|highlight_folder:"unmirrored" }}
    -
    +
    {% with percentage=object.generate_quota_report.percentage.tier2_unmirrored status=object.generate_quota_report.status.tier2_unmirrored %}
    {{ percentage }}% @@ -74,7 +74,7 @@
    Long-Term Storage (Tier 2)
    {{ object.folders.tier2_mirrored|highlight_folder:"mirrored" }}
    -
    +
    {% with percentage=object.generate_quota_report.percentage.tier2_mirrored status=object.generate_quota_report.status.tier2_mirrored %}
    {{ percentage }}% diff --git a/usersec/templates/usersec/overview.html b/usersec/templates/usersec/overview.html index 804e37b..1639b65 100644 --- a/usersec/templates/usersec/overview.html +++ b/usersec/templates/usersec/overview.html @@ -19,10 +19,32 @@

    {% if group_manager or project_manager %}
    @@ -32,7 +54,7 @@

    {{ object.home_directory|default:"None"|highlight_folder:"home" }}
    -
    +
    {% with percentage=object.generate_quota_report.percentage.tier1_home status=object.generate_quota_report.status.tier1_home %}
    {% if not view_mode %} {% if group_manager or project_manager %}
    -
    -
    - {% include "usersec/modules/request_grid.html" %} +
    + {% include "usersec/modules/manage.html" %} +
    {% endif %} {% endif %} @@ -101,7 +123,16 @@

    $(`.project${i}MemberInactive`).toggle(); } }).trigger("change"); - }); + + // Store last selected tab + $('button.nav-link').on('show.bs.tab', function(e) { + localStorage.setItem('activeTab', $(e.target).attr('id')); + }); + var activeTab = localStorage.getItem('activeTab'); + if (activeTab) { + $(`#pills-tab button#${activeTab}`).tab('show'); + } + }); {% endblock %} diff --git a/usersec/templatetags/common.py b/usersec/templatetags/common.py index 65f7f5b..1eac8cc 100644 --- a/usersec/templatetags/common.py +++ b/usersec/templatetags/common.py @@ -49,13 +49,13 @@ def site_version(): REQUEST_STATUS_COLOR_MAPPING = { # Request statuses - REQUEST_STATUS_INITIAL: "secondary", - REQUEST_STATUS_ACTIVE: "secondary", + REQUEST_STATUS_INITIAL: "info", + REQUEST_STATUS_ACTIVE: "info", REQUEST_STATUS_REVISION: "warning", - REQUEST_STATUS_REVISED: "secondary", + REQUEST_STATUS_REVISED: "info", REQUEST_STATUS_APPROVED: "success", REQUEST_STATUS_DENIED: "danger", - REQUEST_STATUS_RETRACTED: "danger", + REQUEST_STATUS_RETRACTED: "secondary", } @@ -65,6 +65,16 @@ def colorize_request_status(status): return REQUEST_STATUS_COLOR_MAPPING.get(status, "dark") +@register.filter +def colorize_text(status): + """Return the color for a given status.""" + color = REQUEST_STATUS_COLOR_MAPPING.get(status, "dark") + if color in ("warning", "info"): + return "dark" + else: + return "light" + + @register.filter def colorize_object_status(status): """Return the color for a given status.""" diff --git a/usersec/tests/factories.py b/usersec/tests/factories.py index 89f4044..2be74d2 100644 --- a/usersec/tests/factories.py +++ b/usersec/tests/factories.py @@ -380,7 +380,7 @@ class Meta: model = HpcGroupInvitation hpcusercreaterequest = factory.SubFactory(HpcUserCreateRequestFactory) - username = factory.Sequence(lambda n: f"user{n}_" + settings.INSTITUTE_USERNAME_SUFFIX) + username = factory.Sequence(lambda n: f"user{n}@" + settings.AUTH_LDAP_USERNAME_DOMAIN) class TermsAndConditionsFactory(factory.django.DjangoModelFactory): diff --git a/usersec/tests/test_forms.py b/usersec/tests/test_forms.py index fe25abc..58f8cda 100644 --- a/usersec/tests/test_forms.py +++ b/usersec/tests/test_forms.py @@ -1,6 +1,7 @@ +from datetime import datetime + from django.urls import reverse from django.utils import timezone -from django.utils.datetime_safe import datetime from test_plus.test import TestCase from usersec.forms import ( @@ -84,9 +85,6 @@ def test_form_initials(self): expiration_expected = datetime(year=timezone.now().year + 1, month=1, day=31) self.assertEqual(form.fields["expiration"].initial, expiration_expected) self.assertEqual(form.fields["delegate"].initial, self.hpc_group.delegate) - self.assertEqual( - form.fields["resources_requested"].initial, self.hpc_group.resources_requested - ) self.assertEqual( form.fields["tier1_scratch"].initial, self.hpc_group.resources_requested.get("tier1_scratch"), diff --git a/usersec/tests/test_rules.py b/usersec/tests/test_rules.py index 42918c2..d094712 100644 --- a/usersec/tests/test_rules.py +++ b/usersec/tests/test_rules.py @@ -1,15 +1,13 @@ import rules from django.conf import settings +from django.contrib.messages import get_messages from django.test import override_settings from django.urls import reverse from test_plus.test import TestCase from usersec.models import ( + REQUEST_STATUS_ACTIVE, HpcGroupCreateRequest, - HpcProjectChangeRequest, - HpcProjectCreateRequest, - HpcUserChangeRequest, - HpcUserCreateRequest, ) from usersec.tests.factories import ( HPCGROUPCHANGEREQUEST_FORM_DATA_VALID, @@ -115,7 +113,9 @@ def setUp(self): self.hpc_project.save() # Create HPC group create request - self.hpc_group_create_request = HpcGroupCreateRequestFactory(requester=self.user_pending) + self.hpc_group_create_request = HpcGroupCreateRequestFactory( + requester=self.user_pending, status=REQUEST_STATUS_ACTIVE + ) # Create HPC group change request self.hpc_group_change_request = HpcGroupChangeRequestFactory( @@ -189,6 +189,8 @@ def assert_permissions_on_url( lazy_url_callback=None, lazy_arg=None, rollback_callback=None, + messages_exp=None, + not_authorized=False, ): if req_kwargs is None: req_kwargs = {} @@ -196,6 +198,12 @@ def assert_permissions_on_url( else: req_kwargs = {"data": req_kwargs} + if messages_exp is None: + messages_exp = [] + + if not_authorized: + messages_exp.append("User not authorized for requested action") + for user in users: with self.login(user): response = self._send_request(url, method, req_kwargs) @@ -215,6 +223,11 @@ def assert_permissions_on_url( self.assertEqual(response.url, redirect_url, msg=f"user={user.username}") + messages = list(get_messages(response.wsgi_request)) + self.assertEqual(len(messages), len(messages_exp)) + for i, msg_exp in enumerate(messages_exp): + self.assertEqual(str(messages[i]), msg_exp) + if rollback_callback: rollback_callback() @@ -277,6 +290,79 @@ def test_has_group_invitation_true(self): def test_has_group_invitation_false(self): self.assertFalse(rules.test_rule("usersec.has_group_invitation", self.user)) + def test__view_mode_enabled_default(self): + self.assertFalse(rules.test_rule("usersec_tests._view_mode_enabled")) + + @override_settings(VIEW_MODE=True) + def test__view_mode_enabled_true(self): + self.assertTrue(rules.test_rule("usersec_tests._view_mode_enabled")) + + def test__has_group_invitation_false(self): + self.assertFalse(rules.test_rule("usersec_tests._has_group_invitation", self.user)) + + def test__has_group_invitation_true(self): + self.assertTrue(rules.test_rule("usersec_tests._has_group_invitation", self.user_invited)) + + def test__has_pending_group_request_false(self): + self.assertFalse(rules.test_rule("usersec_tests._has_pending_group_request", self.user)) + + def test__has_pending_group_request_true(self): + self.assertTrue( + rules.test_rule("usersec_tests._has_pending_group_request", self.user_pending) + ) + + def test__is_hpcuser_exception(self): + with self.assertRaisesRegex(ValueError, "HpcUser is None"): + rules.test_rule("usersec_tests._is_hpcuser", self.user) + + def test__is_hpcuser_false(self): + self.assertFalse( + rules.test_rule("usersec_tests._is_hpcuser", self.user_member, self.hpc_owner) + ) + + def test__is_hpcuser_true(self): + self.assertTrue( + rules.test_rule("usersec_tests._is_hpcuser", self.user_member, self.hpc_member) + ) + + def test__is_pi_of_hpcuser_exception(self): + with self.assertRaisesRegex(ValueError, "HpcUser is None"): + rules.test_rule("usersec_tests._is_pi_of_hpcuser", self.user) + + def test__is_pi_of_hpcuser_false(self): + self.assertFalse( + rules.test_rule("usersec_tests._is_pi_of_hpcuser", self.user_member, self.hpc_owner) + ) + + def test__is_pi_of_hpcuser_true(self): + self.assertTrue( + rules.test_rule("usersec_tests._is_pi_of_hpcuser", self.user_owner, self.hpc_owner) + ) + + def test__is_delegate_of_hpcuser_exception(self): + with self.assertRaisesRegex(ValueError, "HpcUser is None"): + rules.test_rule("usersec_tests._is_delegate_of_hpcuser", self.user) + + def test__is_delegate_of_hpcuser_false(self): + self.assertFalse( + rules.test_rule( + "usersec_tests._is_delegate_of_hpcuser", self.user_member, self.hpc_delegate + ) + ) + + def test__is_delegate_of_hpcuser_true(self): + self.assertTrue( + rules.test_rule( + "usersec_tests._is_delegate_of_hpcuser", self.user_delegate, self.hpc_delegate + ) + ) + + def test_is_orphan_false(self): + self.assertFalse(rules.test_rule("usersec_tests.is_orphan", self.user_member)) + + def test_is_orphan_true(self): + self.assertTrue(rules.test_rule("usersec_tests.is_orphan", self.user)) + class TestPermissions(TestRulesBase): """Tests for permissions without views.""" @@ -832,6 +918,7 @@ def _test_view_mode_denied(self, url, method="GET"): method, 302, redirect_url=reverse("home"), + not_authorized=True, ) def _test_view_mode_granted(self, url, method="GET"): @@ -962,7 +1049,9 @@ def test_orphan_user_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_orphan_user_view_get_view_mode(self): @@ -1001,6 +1090,7 @@ def test_orphan_user_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -1025,7 +1115,9 @@ def test_hpc_group_create_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_group_create_request_detail_view_view_mode(self): @@ -1052,7 +1144,9 @@ def test_hpc_group_create_request_update_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_group_create_request_update_view_get_view_mode(self): @@ -1097,6 +1191,7 @@ def test_hpc_group_create_request_update_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -1107,7 +1202,7 @@ def test_hpc_group_create_request_update_view_post_view_mode(self): ) self._test_view_mode_denied(url, "POST") - def test_hpc_group_create_request_retract_view_get(self): + def test_hpc_group_create_request_retract_view(self): url = reverse( "usersec:hpcgroupcreaterequest-retract", kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, @@ -1123,20 +1218,36 @@ def test_hpc_group_create_request_retract_view_get(self): self.user, ] - self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + good_users, + url, + "GET", + 302, + redirect_url=reverse( + "usersec:hpcgroupcreaterequest-detail", + kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, + ), + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) @override_settings(VIEW_MODE=True) - def test_hpc_group_create_request_retract_view_get_view_mode(self): + def test_hpc_group_create_request_retract_view_view_mode(self): url = reverse( "usersec:hpcgroupcreaterequest-retract", kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, ) self._test_view_mode_denied(url) - def test_hpc_group_create_request_retract_view_post(self): + def test_hpc_group_create_request_reactivate_view(self): url = reverse( - "usersec:hpcgroupcreaterequest-retract", + "usersec:hpcgroupcreaterequest-reactivate", kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, ) good_users = [self.superuser, self.user_pending] @@ -1153,26 +1264,28 @@ def test_hpc_group_create_request_retract_view_post(self): self.assert_permissions_on_url( good_users, url, - "POST", + "GET", 302, redirect_url=reverse( "usersec:hpcgroupcreaterequest-detail", kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, ), ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) - def test_hpc_group_create_request_retract_view_post_view_mode(self): + def test_hpc_group_create_request_reactivate_view_view_mode(self): url = reverse( - "usersec:hpcgroupcreaterequest-retract", + "usersec:hpcgroupcreaterequest-reactivate", kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, ) - self._test_view_mode_denied(url, "POST") + self._test_view_mode_denied(url) - def test_hpc_group_create_request_reactivate_view(self): + def test_hpc_group_create_request_delete_view_get(self): url = reverse( - "usersec:hpcgroupcreaterequest-reactivate", + "usersec:hpcgroupcreaterequest-delete", kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, ) good_users = [self.superuser, self.user_pending] @@ -1190,23 +1303,99 @@ def test_hpc_group_create_request_reactivate_view(self): good_users, url, "GET", + 200, + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", 302, - redirect_url=reverse( - "usersec:hpcgroupcreaterequest-detail", - kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, - ), + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_group_create_request_reactivate_view_view_mode(self): + def test_hpc_group_create_request_delete_view_get_view_mode(self): url = reverse( - "usersec:hpcgroupcreaterequest-reactivate", + "usersec:hpcgroupcreaterequest-delete", + kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_group_create_request_delete_view_post(self): + url = reverse( + "usersec:hpcgroupcreaterequest-delete", + kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, + ) + good_users = [self.superuser, self.user_pending] + bad_users = [ + self.user_hpcadmin, + self.user_owner, + self.user_delegate, + self.user_member, + self.user_member2, + self.user_member_other_group, + self.user, + ] + + def rollback_callback(): + self.hpc_group_create_request.save() + + self.assert_permissions_on_url( + good_users, + url, + "POST", + 302, + redirect_url=reverse("home"), + rollback_callback=rollback_callback, + ) + self.assert_permissions_on_url( + bad_users, + url, + "POST", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_group_create_request_delete_view_post_view_mode(self): + url = reverse( + "usersec:hpcgroupcreaterequest-delete", + kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, + ) + self._test_view_mode_denied(url, "POST") + + def test_hpc_group_create_request_archive_view(self): + url = reverse( + "usersec:hpcgroupcreaterequest-archive", + kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, + ) + good_users = [self.superuser, self.user_pending] + bad_users = [ + self.user_hpcadmin, + self.user_owner, + self.user_delegate, + self.user_member, + self.user_member2, + self.user_member_other_group, + self.user, + ] + + self.assert_permissions_on_url(good_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_group_create_request_archive_view_view_mode(self): + url = reverse( + "usersec:hpcgroupcreaterequest-archive", kwargs={"hpcgroupcreaterequest": self.hpc_group_create_request.uuid}, ) self._test_view_mode_denied(url) - def test_hpc_group_change_request_create_view(self): + def test_hpc_group_change_request_create_view_get(self): url = reverse( "usersec:hpcgroupchangerequest-create", kwargs={"hpcgroup": self.hpc_group.uuid}, @@ -1226,16 +1415,59 @@ def test_hpc_group_change_request_create_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) - def test_hpc_group_change_request_create_view_view_mode(self): + def test_hpc_group_change_request_create_view_get_view_mode(self): url = reverse( "usersec:hpcgroupchangerequest-create", kwargs={"hpcgroup": self.hpc_group.uuid}, ) self._test_view_mode_denied(url) + def test_hpc_group_change_request_create_view_post(self): + url = reverse( + "usersec:hpcgroupchangerequest-create", + kwargs={"hpcgroup": self.hpc_group.uuid}, + ) + good_users = [ + self.user_owner, + self.user_delegate, + self.superuser, + ] + bad_users = [ + self.user_pending, + self.user_hpcadmin, + self.user_member, + self.user_member2, + self.user_member_other_group, + self.user, + ] + data = dict(HPCGROUPCHANGEREQUEST_FORM_DATA_VALID) + + self.assert_permissions_on_url( + good_users, url, "POST", 302, req_kwargs=data, redirect_url=reverse("home") + ) + self.assert_permissions_on_url( + bad_users, + url, + "POST", + 302, + req_kwargs=data, + redirect_url=reverse("home"), + not_authorized=True, + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_group_change_request_create_view_post_view_mode(self): + url = reverse( + "usersec:hpcgroupchangerequest-create", + kwargs={"hpcgroup": self.hpc_group.uuid}, + ) + self._test_view_mode_denied(url, "POST") + def test_hpc_group_change_request_detail_view(self): url = reverse( "usersec:hpcgroupchangerequest-detail", @@ -1256,7 +1488,9 @@ def test_hpc_group_change_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_group_change_request_detail_view_view_mode(self): @@ -1286,7 +1520,9 @@ def test_hpc_group_change_request_update_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_group_change_request_update_view_get_view_mode(self): @@ -1334,6 +1570,7 @@ def test_hpc_group_change_request_update_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -1344,7 +1581,7 @@ def test_hpc_group_change_request_update_view_post_view_mode(self): ) self._test_view_mode_denied(url, "POST") - def test_hpc_group_change_request_retract_view_get(self): + def test_hpc_group_change_request_retract_view(self): url = reverse( "usersec:hpcgroupchangerequest-retract", kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, @@ -1363,20 +1600,36 @@ def test_hpc_group_change_request_retract_view_get(self): self.user, ] - self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + good_users, + url, + "GET", + 302, + redirect_url=reverse( + "usersec:hpcgroupchangerequest-detail", + kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, + ), + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) @override_settings(VIEW_MODE=True) - def test_hpc_group_change_request_retract_view_get_view_mode(self): + def test_hpc_group_change_request_retract_view_view_mode(self): url = reverse( "usersec:hpcgroupchangerequest-retract", kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, ) self._test_view_mode_denied(url) - def test_hpc_group_change_request_retract_view_post(self): + def test_hpc_group_change_request_reactivate_view(self): url = reverse( - "usersec:hpcgroupchangerequest-retract", + "usersec:hpcgroupchangerequest-reactivate", kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, ) good_users = [ @@ -1393,35 +1646,33 @@ def test_hpc_group_change_request_retract_view_post(self): self.user, ] + self.assert_permissions_on_url(good_users, url, "GET", 302, redirect_url=reverse("home")) self.assert_permissions_on_url( - good_users, + bad_users, url, - "POST", + "GET", 302, - redirect_url=reverse( - "usersec:hpcgroupchangerequest-detail", - kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, - ), + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_group_change_request_retract_view_post_view_mode(self): + def test_hpc_group_change_request_reactivate_view_view_mode(self): url = reverse( - "usersec:hpcgroupchangerequest-retract", + "usersec:hpcgroupchangerequest-reactivate", kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, ) - self._test_view_mode_denied(url, "POST") + self._test_view_mode_denied(url) - def test_hpc_group_change_request_reactivate_view(self): + def test_hpc_group_change_request_delete_view_get(self): url = reverse( - "usersec:hpcgroupchangerequest-reactivate", + "usersec:hpcgroupchangerequest-delete", kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, ) good_users = [ + self.superuser, self.user_owner, self.user_delegate, - self.superuser, ] bad_users = [ self.user_pending, @@ -1436,24 +1687,117 @@ def test_hpc_group_change_request_reactivate_view(self): good_users, url, "GET", + 200, + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", 302, - redirect_url=reverse( - "usersec:hpcgroupchangerequest-detail", - kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, - ), + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_group_change_request_reactivate_view_view_mode(self): + def test_hpc_group_change_request_delete_view_get_view_mode(self): url = reverse( - "usersec:hpcgroupchangerequest-reactivate", + "usersec:hpcgroupchangerequest-delete", kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, ) self._test_view_mode_denied(url) - def test_hpc_user_view(self): - url = reverse("usersec:hpcuser-overview") + def test_hpc_group_change_request_delete_view_post(self): + url = reverse( + "usersec:hpcgroupchangerequest-delete", + kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + ] + bad_users = [ + self.user_pending, + self.user_hpcadmin, + self.user_member, + self.user_member2, + self.user_member_other_group, + self.user, + ] + + def rollback_callback(): + self.hpc_group_change_request.save() + + self.assert_permissions_on_url( + good_users, + url, + "POST", + 302, + redirect_url=reverse("home"), + rollback_callback=rollback_callback, + ) + self.assert_permissions_on_url( + bad_users, + url, + "POST", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_group_change_request_delete_view_post_view_mode(self): + url = reverse( + "usersec:hpcgroupchangerequest-delete", + kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, + ) + self._test_view_mode_denied(url, "POST") + + def test_hpc_group_change_request_archive_view(self): + url = reverse( + "usersec:hpcgroupchangerequest-archive", + kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + ] + bad_users = [ + self.user_pending, + self.user_hpcadmin, + self.user_member, + self.user_member2, + self.user_member_other_group, + self.user, + ] + + self.assert_permissions_on_url( + good_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_group_change_request_archive_view_view_mode(self): + url = reverse( + "usersec:hpcgroupchangerequest-archive", + kwargs={"hpcgroupchangerequest": self.hpc_group_change_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_user_view(self): + url = reverse("usersec:hpcuser-overview") good_users = [ self.user_owner, self.user_delegate, @@ -1520,7 +1864,9 @@ def test_hpc_user_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_user_detail_view_view_mode(self): @@ -1550,7 +1896,9 @@ def test_hpc_group_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_group_detail_view_view_mode(self): @@ -1580,7 +1928,9 @@ def test_hpc_project_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_project_detail_view_view_mode(self): @@ -1610,7 +1960,9 @@ def test_hpc_user_create_request_create_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_user_create_request_create_view_mode(self): @@ -1641,15 +1993,7 @@ def test_hpc_user_create_request_create_view_post(self): data = dict(HPCUSERCREATEREQUEST_FORM_DATA_VALID) self.assert_permissions_on_url( - good_users, - url, - "POST", - 302, - req_kwargs=data, - lazy_url_callback=lambda: reverse( - "usersec:hpcusercreaterequest-detail", - kwargs={"hpcusercreaterequest": HpcUserCreateRequest.objects.last().uuid}, - ), + good_users, url, "POST", 302, req_kwargs=data, lazy_url_callback=lambda: reverse("home") ) self.assert_permissions_on_url( bad_users, @@ -1658,6 +2002,7 @@ def test_hpc_user_create_request_create_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -1688,7 +2033,9 @@ def test_hpc_user_create_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_user_create_request_detail_view_view_mode(self): @@ -1718,7 +2065,9 @@ def test_hpc_user_create_request_update_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_user_create_request_update_view_get_view_mode(self): @@ -1766,6 +2115,7 @@ def test_hpc_user_create_request_update_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -1776,7 +2126,7 @@ def test_hpc_user_create_request_update_view_post_view_mode(self): ) self._test_view_mode_denied(url, "POST") - def test_hpc_user_create_request_retract_view_get(self): + def test_hpc_user_create_request_retract_view(self): url = reverse( "usersec:hpcusercreaterequest-retract", kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, @@ -1795,20 +2145,36 @@ def test_hpc_user_create_request_retract_view_get(self): self.user, ] - self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + good_users, + url, + "GET", + 302, + redirect_url=reverse( + "usersec:hpcusercreaterequest-detail", + kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, + ), + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) @override_settings(VIEW_MODE=True) - def test_hpc_user_create_request_retract_view_get_view_mode(self): + def test_hpc_user_create_request_retract_view_view_mode(self): url = reverse( "usersec:hpcusercreaterequest-retract", kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, ) self._test_view_mode_denied(url) - def test_hpc_user_create_request_retract_view_post(self): + def test_hpc_user_create_request_reactivate_view(self): url = reverse( - "usersec:hpcusercreaterequest-retract", + "usersec:hpcusercreaterequest-reactivate", kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, ) good_users = [ @@ -1825,29 +2191,117 @@ def test_hpc_user_create_request_retract_view_post(self): self.user, ] + self.assert_permissions_on_url( + good_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + ) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_user_create_request_reactivate_view_view_mode(self): + url = reverse( + "usersec:hpcusercreaterequest-reactivate", + kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_user_create_request_delete_view_get(self): + url = reverse( + "usersec:hpcusercreaterequest-delete", + kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + ] + bad_users = [ + self.user_member, + self.user_member2, + self.user_pending, + self.user_hpcadmin, + self.user_member_other_group, + self.user, + ] + + self.assert_permissions_on_url( + good_users, + url, + "GET", + 200, + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_user_create_request_delete_view_get_view_mode(self): + url = reverse( + "usersec:hpcusercreaterequest-delete", + kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_user_create_request_delete_view_post(self): + url = reverse( + "usersec:hpcusercreaterequest-delete", + kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + ] + bad_users = [ + self.user_member, + self.user_member2, + self.user_pending, + self.user_hpcadmin, + self.user_member_other_group, + self.user, + ] + + def rollback_callback(): + self.hpc_user_create_request.save() + self.assert_permissions_on_url( good_users, url, "POST", 302, - redirect_url=reverse( - "usersec:hpcusercreaterequest-detail", - kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, - ), + redirect_url=reverse("home"), + rollback_callback=rollback_callback, + ) + self.assert_permissions_on_url( + bad_users, + url, + "POST", + 302, + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_user_create_request_retract_view_post_view_mode(self): + def test_hpc_user_create_request_delete_view_post_view_mode(self): url = reverse( - "usersec:hpcusercreaterequest-retract", + "usersec:hpcusercreaterequest-delete", kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, ) self._test_view_mode_denied(url, "POST") - def test_hpc_user_create_request_reactivate_view(self): + def test_hpc_user_create_request_archive_view(self): url = reverse( - "usersec:hpcusercreaterequest-reactivate", + "usersec:hpcusercreaterequest-archive", kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, ) good_users = [ @@ -1864,22 +2318,20 @@ def test_hpc_user_create_request_reactivate_view(self): self.user, ] + self.assert_permissions_on_url(good_users, url, "GET", 302, redirect_url=reverse("home")) self.assert_permissions_on_url( - good_users, + bad_users, url, "GET", 302, - redirect_url=reverse( - "usersec:hpcusercreaterequest-detail", - kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, - ), + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_user_create_request_reactivate_view_view_mode(self): + def test_hpc_user_create_request_archive_view_view_mode(self): url = reverse( - "usersec:hpcusercreaterequest-reactivate", + "usersec:hpcusercreaterequest-archive", kwargs={"hpcusercreaterequest": self.hpc_user_create_request.uuid}, ) self._test_view_mode_denied(url) @@ -1904,7 +2356,9 @@ def test_hpc_user_change_request_create_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_user_change_request_create_view_get_view_mode(self): @@ -1940,10 +2394,7 @@ def test_hpc_user_change_request_create_view_post(self): "POST", 302, req_kwargs=data, - lazy_url_callback=lambda: reverse( - "usersec:hpcuserchangerequest-detail", - kwargs={"hpcuserchangerequest": HpcUserChangeRequest.objects.last().uuid}, - ), + redirect_url=reverse("home"), ) self.assert_permissions_on_url( bad_users, @@ -1952,6 +2403,7 @@ def test_hpc_user_change_request_create_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -1982,7 +2434,9 @@ def test_hpc_user_change_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_user_change_request_detail_view_view_mode(self): @@ -2012,7 +2466,9 @@ def test_hpc_user_change_request_update_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_user_change_request_update_view_get_view_mode(self): @@ -2060,6 +2516,7 @@ def test_hpc_user_change_request_update_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -2070,7 +2527,7 @@ def test_hpc_user_change_request_update_view_post_view_mode(self): ) self._test_view_mode_denied(url, "POST") - def test_hpc_user_change_request_retract_view_get(self): + def test_hpc_user_change_request_retract_view(self): url = reverse( "usersec:hpcuserchangerequest-retract", kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, @@ -2089,20 +2546,36 @@ def test_hpc_user_change_request_retract_view_get(self): self.user, ] - self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + good_users, + url, + "GET", + 302, + redirect_url=reverse( + "usersec:hpcuserchangerequest-detail", + kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, + ), + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) @override_settings(VIEW_MODE=True) - def test_hpc_user_change_request_retract_view_get_view_mode(self): + def test_hpc_user_change_request_retract_view_view_mode(self): url = reverse( "usersec:hpcuserchangerequest-retract", kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, ) self._test_view_mode_denied(url) - def test_hpc_user_change_request_retract_view_post(self): + def test_hpc_user_change_request_reactivate_view(self): url = reverse( - "usersec:hpcuserchangerequest-retract", + "usersec:hpcuserchangerequest-reactivate", kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, ) good_users = [ @@ -2119,29 +2592,111 @@ def test_hpc_user_change_request_retract_view_post(self): self.user, ] + self.assert_permissions_on_url(good_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_user_change_request_reactivate_view_view_mode(self): + url = reverse( + "usersec:hpcuserchangerequest-reactivate", + kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_user_change_request_delete_view_get(self): + url = reverse( + "usersec:hpcuserchangerequest-delete", + kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + ] + bad_users = [ + self.user_member, + self.user_member2, + self.user_pending, + self.user_hpcadmin, + self.user_member_other_group, + self.user, + ] + + self.assert_permissions_on_url( + good_users, + url, + "GET", + 200, + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_user_change_request_delete_view_get_view_mode(self): + url = reverse( + "usersec:hpcuserchangerequest-delete", + kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_user_change_request_delete_view_post(self): + url = reverse( + "usersec:hpcuserchangerequest-delete", + kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + ] + bad_users = [ + self.user_member, + self.user_member2, + self.user_pending, + self.user_hpcadmin, + self.user_member_other_group, + self.user, + ] + + def rollback_callback(): + self.hpc_user_change_request.save() + self.assert_permissions_on_url( good_users, url, "POST", 302, - redirect_url=reverse( - "usersec:hpcuserchangerequest-detail", - kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, - ), + redirect_url=reverse("home"), + rollback_callback=rollback_callback, + ) + self.assert_permissions_on_url( + bad_users, + url, + "POST", + 302, + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_user_change_request_retract_view_post_view_mode(self): + def test_hpc_user_change_request_delete_view_post_view_mode(self): url = reverse( - "usersec:hpcuserchangerequest-retract", + "usersec:hpcuserchangerequest-delete", kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, ) self._test_view_mode_denied(url, "POST") - def test_hpc_user_change_request_reactivate_view(self): + def test_hpc_user_change_request_archive_view(self): url = reverse( - "usersec:hpcuserchangerequest-reactivate", + "usersec:hpcuserchangerequest-archive", kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, ) good_users = [ @@ -2158,22 +2713,20 @@ def test_hpc_user_change_request_reactivate_view(self): self.user, ] + self.assert_permissions_on_url(good_users, url, "GET", 302, redirect_url=reverse("home")) self.assert_permissions_on_url( - good_users, + bad_users, url, "GET", 302, - redirect_url=reverse( - "usersec:hpcuserchangerequest-detail", - kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, - ), + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_user_change_request_reactivate_view_view_mode(self): + def test_hpc_user_change_request_archive_view_view_mode(self): url = reverse( - "usersec:hpcuserchangerequest-reactivate", + "usersec:hpcuserchangerequest-archive", kwargs={"hpcuserchangerequest": self.hpc_user_change_request.uuid}, ) self._test_view_mode_denied(url) @@ -2198,7 +2751,9 @@ def test_hpc_project_create_request_create_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_project_create_request_create_view_get_view_mode(self): @@ -2235,10 +2790,7 @@ def test_hpc_project_create_request_create_view_post(self): "POST", 302, req_kwargs=data, - lazy_url_callback=lambda: reverse( - "usersec:hpcprojectcreaterequest-detail", - kwargs={"hpcprojectcreaterequest": HpcProjectCreateRequest.objects.last().uuid}, - ), + redirect_url=reverse("home"), ) self.assert_permissions_on_url( bad_users, @@ -2247,6 +2799,7 @@ def test_hpc_project_create_request_create_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -2277,7 +2830,9 @@ def test_hpc_project_create_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_project_create_request_detail_view_view_mode(self): @@ -2307,7 +2862,9 @@ def test_hpc_project_create_request_update_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_project_create_request_update_view_get_view_mode(self): @@ -2356,6 +2913,7 @@ def test_hpc_project_create_request_update_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -2366,7 +2924,7 @@ def test_hpc_project_create_request_update_view_post_view_mode(self): ) self._test_view_mode_denied(url, "POST") - def test_hpc_project_create_request_retract_view_get(self): + def test_hpc_project_create_request_retract_view(self): url = reverse( "usersec:hpcprojectcreaterequest-retract", kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, @@ -2385,20 +2943,110 @@ def test_hpc_project_create_request_retract_view_get(self): self.user, ] - self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + good_users, + url, + "GET", + 302, + redirect_url=reverse( + "usersec:hpcprojectcreaterequest-detail", + kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, + ), + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) @override_settings(VIEW_MODE=True) - def test_hpc_project_create_request_retract_view_get_view_mode(self): + def test_hpc_project_create_request_retract_view_view_mode(self): url = reverse( "usersec:hpcprojectcreaterequest-retract", kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, ) self._test_view_mode_denied(url) - def test_hpc_project_create_request_retract_view_post(self): + def test_hpc_project_create_request_reactivate_view(self): url = reverse( - "usersec:hpcprojectcreaterequest-retract", + "usersec:hpcprojectcreaterequest-reactivate", + kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + ] + bad_users = [ + self.user_member, + self.user_member2, + self.user_pending, + self.user_hpcadmin, + self.user_member_other_group, + self.user, + ] + + self.assert_permissions_on_url(good_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_project_create_request_reactivate_view_view_mode(self): + url = reverse( + "usersec:hpcprojectcreaterequest-reactivate", + kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_project_create_request_delete_view_get(self): + url = reverse( + "usersec:hpcprojectcreaterequest-delete", + kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + ] + bad_users = [ + self.user_member, + self.user_member2, + self.user_pending, + self.user_hpcadmin, + self.user_member_other_group, + self.user, + ] + + self.assert_permissions_on_url( + good_users, + url, + "GET", + 200, + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_project_create_request_delete_view_get_view_mode(self): + url = reverse( + "usersec:hpcprojectcreaterequest-delete", + kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_project_create_request_delete_view_post(self): + url = reverse( + "usersec:hpcprojectcreaterequest-delete", kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, ) good_users = [ @@ -2415,29 +3063,37 @@ def test_hpc_project_create_request_retract_view_post(self): self.user, ] + def rollback_callback(): + self.hpc_project_create_request.save() + self.assert_permissions_on_url( good_users, url, "POST", 302, - redirect_url=reverse( - "usersec:hpcprojectcreaterequest-detail", - kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, - ), + redirect_url=reverse("home"), + rollback_callback=rollback_callback, + ) + self.assert_permissions_on_url( + bad_users, + url, + "POST", + 302, + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_project_create_request_retract_view_post_view_mode(self): + def test_hpc_project_create_request_delete_view_post_view_mode(self): url = reverse( - "usersec:hpcprojectcreaterequest-retract", + "usersec:hpcprojectcreaterequest-delete", kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, ) self._test_view_mode_denied(url, "POST") - def test_hpc_project_create_request_reactivate_view(self): + def test_hpc_project_create_request_archive_view(self): url = reverse( - "usersec:hpcprojectcreaterequest-reactivate", + "usersec:hpcprojectcreaterequest-archive", kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, ) good_users = [ @@ -2454,22 +3110,20 @@ def test_hpc_project_create_request_reactivate_view(self): self.user, ] + self.assert_permissions_on_url(good_users, url, "GET", 302, redirect_url=reverse("home")) self.assert_permissions_on_url( - good_users, + bad_users, url, "GET", 302, - redirect_url=reverse( - "usersec:hpcprojectcreaterequest-detail", - kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, - ), + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_project_create_request_reactivate_view_view_mode(self): + def test_hpc_project_create_request_archive_view_view_mode(self): url = reverse( - "usersec:hpcprojectcreaterequest-reactivate", + "usersec:hpcprojectcreaterequest-archive", kwargs={"hpcprojectcreaterequest": self.hpc_project_create_request.uuid}, ) self._test_view_mode_denied(url) @@ -2494,7 +3148,9 @@ def test_hpc_project_change_request_create_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_project_change_request_create_view_get_view_mode(self): @@ -2531,10 +3187,7 @@ def test_hpc_project_change_request_create_view_post(self): "POST", 302, req_kwargs=data, - lazy_url_callback=lambda: reverse( - "usersec:hpcprojectchangerequest-detail", - kwargs={"hpcprojectchangerequest": HpcProjectChangeRequest.objects.last().uuid}, - ), + redirect_url=reverse("home"), ) self.assert_permissions_on_url( bad_users, @@ -2543,6 +3196,7 @@ def test_hpc_project_change_request_create_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -2573,7 +3227,9 @@ def test_hpc_project_change_request_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_project_change_request_detail_view_view_mode(self): @@ -2603,7 +3259,9 @@ def test_hpc_project_change_request_update_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_project_change_request_update_view_get_view_mode(self): @@ -2652,6 +3310,7 @@ def test_hpc_project_changee_request_update_view_post(self): 302, req_kwargs=data, redirect_url=reverse("home"), + not_authorized=True, ) @override_settings(VIEW_MODE=True) @@ -2662,7 +3321,7 @@ def test_hpc_project_change_request_update_view_post_view_mode(self): ) self._test_view_mode_denied(url, "POST") - def test_hpc_project_change_request_retract_view_get(self): + def test_hpc_project_change_request_retract_view(self): url = reverse( "usersec:hpcprojectchangerequest-retract", kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, @@ -2681,20 +3340,110 @@ def test_hpc_project_change_request_retract_view_get(self): self.user, ] - self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + good_users, + url, + "GET", + 302, + redirect_url=reverse( + "usersec:hpcprojectchangerequest-detail", + kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, + ), + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) @override_settings(VIEW_MODE=True) - def test_hpc_project_change_request_retract_view_get_view_mode(self): + def test_hpc_project_change_request_retract_view_view_mode(self): url = reverse( "usersec:hpcprojectchangerequest-retract", kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, ) self._test_view_mode_denied(url) - def test_hpc_project_change_request_retract_view_post(self): + def test_hpc_project_change_request_reactivate_view(self): url = reverse( - "usersec:hpcprojectchangerequest-retract", + "usersec:hpcprojectchangerequest-reactivate", + kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + self.user_member_other_group, + ] + bad_users = [ + self.user_member, + self.user_member2, + self.user_pending, + self.user_hpcadmin, + self.user, + ] + + self.assert_permissions_on_url(good_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_project_change_request_reactivate_view_view_mode(self): + url = reverse( + "usersec:hpcprojectchangerequest-reactivate", + kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_project_change_request_delete_view_get(self): + url = reverse( + "usersec:hpcprojectchangerequest-delete", + kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, + ) + good_users = [ + self.superuser, + self.user_owner, + self.user_delegate, + self.user_member_other_group, + ] + bad_users = [ + self.user_member, + self.user_member2, + self.user_pending, + self.user_hpcadmin, + self.user, + ] + + self.assert_permissions_on_url( + good_users, + url, + "GET", + 200, + ) + self.assert_permissions_on_url( + bad_users, + url, + "GET", + 302, + redirect_url=reverse("home"), + not_authorized=True, + ) + + @override_settings(VIEW_MODE=True) + def test_hpc_project_change_request_delete_view_get_view_mode(self): + url = reverse( + "usersec:hpcprojectchangerequest-delete", + kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, + ) + self._test_view_mode_denied(url) + + def test_hpc_project_change_request_delete_view_post(self): + url = reverse( + "usersec:hpcprojectchangerequest-delete", kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, ) good_users = [ @@ -2711,29 +3460,37 @@ def test_hpc_project_change_request_retract_view_post(self): self.user, ] + def rollback_callback(): + self.hpc_project_change_request.save() + self.assert_permissions_on_url( good_users, url, "POST", 302, - redirect_url=reverse( - "usersec:hpcprojectchangerequest-detail", - kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, - ), + redirect_url=reverse("home"), + rollback_callback=rollback_callback, + ) + self.assert_permissions_on_url( + bad_users, + url, + "POST", + 302, + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_project_change_request_retract_view_post_view_mode(self): + def test_hpc_project_change_request_delete_view_post_view_mode(self): url = reverse( - "usersec:hpcprojectchangerequest-retract", + "usersec:hpcprojectchangerequest-delete", kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, ) self._test_view_mode_denied(url, "POST") - def test_hpc_project_change_request_reactivate_view(self): + def test_hpc_project_change_request_archive_view(self): url = reverse( - "usersec:hpcprojectchangerequest-reactivate", + "usersec:hpcprojectchangerequest-archive", kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, ) good_users = [ @@ -2750,22 +3507,20 @@ def test_hpc_project_change_request_reactivate_view(self): self.user, ] + self.assert_permissions_on_url(good_users, url, "GET", 302, redirect_url=reverse("home")) self.assert_permissions_on_url( - good_users, + bad_users, url, "GET", 302, - redirect_url=reverse( - "usersec:hpcprojectchangerequest-detail", - kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, - ), + redirect_url=reverse("home"), + not_authorized=True, ) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) @override_settings(VIEW_MODE=True) - def test_hpc_project_change_request_reactivate_view_view_mode(self): + def test_hpc_project_change_request_archive_view_view_mode(self): url = reverse( - "usersec:hpcprojectchangerequest-reactivate", + "usersec:hpcprojectchangerequest-archive", kwargs={"hpcprojectchangerequest": self.hpc_project_change_request.uuid}, ) self._test_view_mode_denied(url) @@ -2791,7 +3546,9 @@ def test_hpc_group_invitation_detail_view(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) @override_settings(VIEW_MODE=True) def test_hpc_group_invitation_detail_view_view_mode(self): @@ -2841,8 +3598,16 @@ def test_hpc_group_invitation_accept_view(self): "usersec:hpcgroupinvitation-detail", kwargs={"hpcgroupinvitation": self.hpc_group_invitation.uuid}, ), + messages_exp=[ + ( + "Superuser is not allowed to accept invitations. " + "This would lead to inconsistencies." + ) + ], + ) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) def test_hpc_group_invitation_reject_view_get(self): url = reverse( @@ -2865,7 +3630,9 @@ def test_hpc_group_invitation_reject_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_group_invitation_reject_view_post(self): url = reverse( @@ -2897,7 +3664,9 @@ def test_hpc_group_invitation_reject_view_post(self): kwargs={"hpcgroupinvitation": self.hpc_group_invitation.uuid}, ), ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_project_invitation_accept_view(self): url = reverse( @@ -2936,8 +3705,16 @@ def test_hpc_project_invitation_accept_view(self): "GET", 302, redirect_url=reverse("home"), + messages_exp=[ + ( + "Superuser is not allowed to accept invitations. " + "This would lead to inconsistencies." + ) + ], + ) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True ) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) def test_hpc_project_invitation_reject_view_get(self): url = reverse( @@ -2960,7 +3737,9 @@ def test_hpc_project_invitation_reject_view_get(self): ] self.assert_permissions_on_url(good_users, url, "GET", 200) - self.assert_permissions_on_url(bad_users, url, "GET", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "GET", 302, redirect_url=reverse("home"), not_authorized=True + ) def test_hpc_project_invitation_reject_view_post(self): url = reverse( @@ -2991,4 +3770,6 @@ def test_hpc_project_invitation_reject_view_post(self): "usersec:hpcuser-overview", ), ) - self.assert_permissions_on_url(bad_users, url, "POST", 302, redirect_url=reverse("home")) + self.assert_permissions_on_url( + bad_users, url, "POST", 302, redirect_url=reverse("home"), not_authorized=True + ) diff --git a/usersec/tests/test_templatetags.py b/usersec/tests/test_templatetags.py index c546ae8..15a6399 100644 --- a/usersec/tests/test_templatetags.py +++ b/usersec/tests/test_templatetags.py @@ -42,13 +42,13 @@ def test_site_version(self): def test_colorize_request_status(self): data = { - REQUEST_STATUS_INITIAL: "secondary", - REQUEST_STATUS_ACTIVE: "secondary", + REQUEST_STATUS_INITIAL: "info", + REQUEST_STATUS_ACTIVE: "info", REQUEST_STATUS_REVISION: "warning", - REQUEST_STATUS_REVISED: "secondary", + REQUEST_STATUS_REVISED: "info", REQUEST_STATUS_APPROVED: "success", REQUEST_STATUS_DENIED: "danger", - REQUEST_STATUS_RETRACTED: "danger", + REQUEST_STATUS_RETRACTED: "secondary", "UNKNOWN": "dark", } diff --git a/usersec/tests/test_views.py b/usersec/tests/test_views.py index 8afe975..8a9490e 100644 --- a/usersec/tests/test_views.py +++ b/usersec/tests/test_views.py @@ -13,11 +13,13 @@ INVITATION_STATUS_REJECTED, REQUEST_STATUS_ACTIVE, REQUEST_STATUS_APPROVED, + REQUEST_STATUS_ARCHIVED, REQUEST_STATUS_DENIED, REQUEST_STATUS_INITIAL, REQUEST_STATUS_RETRACTED, TERMS_AUDIENCE_PI, TERMS_AUDIENCE_USER, + HpcGroupChangeRequest, HpcGroupCreateRequest, HpcProjectChangeRequest, HpcProjectCreateRequest, @@ -94,6 +96,9 @@ def setUp(self): self.hpc_project.members.add(self.hpc_owner) self.hpc_project.get_latest_version().members.add(self.hpc_owner) + def assertNoMessages(self, response): + self.assertEqual(list(get_messages(response.wsgi_request)), []) + class TestHomeView(TestViewBase): """Tests for HomeView.""" @@ -107,12 +112,14 @@ def setUp(self): def test_get_no_cluster_user(self): with self.login(self.user): response = self.client.get(reverse("home")) + self.assertNoMessages(response) self.assertRedirects(response, reverse("usersec:orphan-user")) def test_get_cluster_user(self): HpcUserFactory(user=self.user, primary_group=self.hpc_group) with self.login(self.user): response = self.client.get(reverse("home")) + self.assertNoMessages(response) self.assertEqual(response.status_code, 200) self.assertIsInstance(response.context_data["view"], HpcUserView) self.assertEqual(response.context_data["object"], self.user.hpcuser_user.first()) @@ -120,11 +127,13 @@ def test_get_cluster_user(self): def test_get_admin_user(self): with self.login(self.user_hpcadmin): response = self.client.get(reverse("home")) + self.assertNoMessages(response) self.assertRedirects(response, reverse("adminsec:overview")) def test_get_superuser(self): with self.login(self.superuser): response = self.client.get(reverse("home")) + self.assertNoMessages(response) self.assertRedirects(response, reverse("admin-landing")) def test_get_not_consented_empty_terms(self): @@ -133,6 +142,7 @@ def test_get_not_consented_empty_terms(self): with self.login(self.user): response = self.client.get(reverse("home")) + self.assertNoMessages(response) self.assertRedirects(response, reverse("usersec:orphan-user")) def test_get_not_consented(self): @@ -142,8 +152,40 @@ def test_get_not_consented(self): with self.login(self.user): response = self.client.get(reverse("home")) + self.assertNoMessages(response) self.assertRedirects(response, reverse("usersec:terms")) + def test_has_invitation(self): + create_request = HpcUserCreateRequestFactory( + requester=self.user_owner, group=self.hpc_group + ) + invitation = HpcGroupInvitationFactory( + hpcusercreaterequest=create_request, username="user@CHARITE" + ) + with self.login(self.user): + response = self.client.get(reverse("home")) + self.assertNoMessages(response) + self.assertRedirects( + response, + reverse( + "usersec:hpcgroupinvitation-detail", + kwargs={"hpcgroupinvitation": invitation.uuid}, + ), + ) + + def test_has_pending_group_request(self): + request = HpcGroupCreateRequestFactory(requester=self.user, status=REQUEST_STATUS_ACTIVE) + with self.login(self.user): + response = self.client.get(reverse("home")) + self.assertNoMessages(response) + self.assertRedirects( + response, + reverse( + "usersec:hpcgroupcreaterequest-detail", + kwargs={"hpcgroupcreaterequest": request.uuid}, + ), + ) + class TestOrphanUserView(TestViewBase): """Tests for OrphanUserView.""" @@ -178,9 +220,6 @@ def test_post_form_valid(self): kwargs={"hpcgroupcreaterequest": request.uuid}, ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully submitted request for group creation.") self.assertEqual(len(mail.outbox), 2) @@ -351,10 +390,6 @@ def test_post(self): # TODO Sort out timezone issue # self.assertEqual(self.obj.expiration, update["expiration"]) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully updated request for group creation.") - self.assertEqual(len(mail.outbox), 0) def test_post_fail(self): @@ -400,18 +435,6 @@ def test_get(self): kwargs={"hpcgroupcreaterequest": self.obj.uuid}, ) ) - self.assertEqual(response.status_code, 200) - self.assertIsNotNone(response.context["form"]) - - def test_post(self): - with self.login(self.user): - response = self.client.post( - reverse( - "usersec:hpcgroupcreaterequest-retract", - kwargs={"hpcgroupcreaterequest": self.obj.uuid}, - ), - ) - self.assertRedirects( response, reverse( @@ -420,10 +443,6 @@ def test_post(self): ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully retracted request for group creation.") - self.assertEqual(self.obj.status, REQUEST_STATUS_INITIAL) self.obj.refresh_from_db() self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) @@ -456,16 +475,106 @@ def test_get(self): kwargs={"hpcgroupcreaterequest": self.obj.uuid}, ), ) + self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + self.obj.refresh_from_db() + self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual( - str(messages[0]), "Successfully re-activated request for group creation." + +class TestHpcGroupCreateRequestDeleteView(TestViewBase): + """Tests for HpcGroupCreateRequestDeleteView.""" + + def setUp(self): + super().setUp() + self.obj = HpcGroupCreateRequestFactory(requester=self.user) + + def test_get(self): + with self.login(self.user): + response = self.client.get( + reverse( + "usersec:hpcgroupcreaterequest-delete", + kwargs={"hpcgroupcreaterequest": self.obj.uuid}, + ) ) + self.assertEqual(response.status_code, 200) + self.assertNoMessages(response) - self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + def test_post(self): + with self.login(self.user): + response = self.client.post( + reverse( + "usersec:hpcgroupcreaterequest-delete", + kwargs={"hpcgroupcreaterequest": self.obj.uuid}, + ), + follow=True, + ) + self.assertRedirects(response, reverse("usersec:orphan-user")) + self.assertNoMessages(response) + self.assertEqual(HpcGroupCreateRequest.objects.count(), 0) + + +class TestHpcGroupCreateRequestArchiveView(TestViewBase): + """Tests for HpcGroupCreateRequestArchiveView.""" + + def setUp(self): + super().setUp() + self.obj = HpcGroupCreateRequestFactory( + requester=self.user_owner, status=REQUEST_STATUS_APPROVED + ) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( + reverse( + "usersec:hpcgroupcreaterequest-archive", + kwargs={"hpcgroupcreaterequest": self.obj.uuid}, + ) + ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) self.obj.refresh_from_db() - self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + self.assertEqual(self.obj.status, REQUEST_STATUS_ARCHIVED) + + +class TestHpcGroupChangeRequestCreateView(TestViewBase): + """Tests for HpcGroupChangeRequestCreateView.""" + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( + reverse( + "usersec:hpcgroupchangerequest-create", kwargs={"hpcgroup": self.hpc_group.uuid} + ) + ) + self.assertEqual(response.status_code, 200) + + def test_post_form_valid(self): + with self.login(self.user_owner): + data = dict(HPCGROUPCREATEREQUEST_FORM_DATA_VALID) + response = self.client.post( + reverse( + "usersec:hpcgroupchangerequest-create", kwargs={"hpcgroup": self.hpc_group.uuid} + ), + data=data, + ) + self.assertEqual(HpcGroupChangeRequest.objects.count(), 1) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(len(mail.outbox), 1) + + def test_post_form_invalid(self): + with self.login(self.user_owner): + data = dict(HPCGROUPCREATEREQUEST_FORM_DATA_VALID) + data["resources_requested"] = "" + response = self.client.post( + reverse( + "usersec:hpcgroupchangerequest-create", kwargs={"hpcgroup": self.hpc_group.uuid} + ), + data=data, + ) + self.assertEqual( + response.context["form"].errors["resources_requested"][0], + "This field is required.", + ) class TestHpcGroupChangeRequestDetailView(TestViewBase): @@ -632,10 +741,6 @@ def test_post(self): # TODO Sort out timezone issue # self.assertEqual(self.obj.expiration, update["expiration"]) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully updated request for group update.") - self.assertEqual(len(mail.outbox), 0) def test_post_fail(self): @@ -681,18 +786,6 @@ def test_get(self): kwargs={"hpcgroupchangerequest": self.obj.uuid}, ) ) - self.assertEqual(response.status_code, 200) - self.assertIsNotNone(response.context["form"]) - - def test_post(self): - with self.login(self.user_owner): - response = self.client.post( - reverse( - "usersec:hpcgroupchangerequest-retract", - kwargs={"hpcgroupchangerequest": self.obj.uuid}, - ), - ) - self.assertRedirects( response, reverse( @@ -701,10 +794,6 @@ def test_post(self): ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully retracted request for group update.") - self.assertEqual(self.obj.status, REQUEST_STATUS_INITIAL) self.obj.refresh_from_db() self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) @@ -730,23 +819,64 @@ def test_get(self): ) ) - self.assertRedirects( - response, + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + self.obj.refresh_from_db() + self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + + +class TestHpcGroupChangeRequestDeleteView(TestViewBase): + """Tests for HpcGroupChangeRequestDeleteView.""" + + def setUp(self): + super().setUp() + self.obj = HpcGroupChangeRequestFactory(requester=self.user_owner, group=self.hpc_group) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( reverse( - "usersec:hpcgroupchangerequest-detail", + "usersec:hpcgroupchangerequest-delete", kwargs={"hpcgroupchangerequest": self.obj.uuid}, - ), + ) ) + self.assertEqual(response.status_code, 200) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual( - str(messages[0]), "Successfully re-activated request for group update." + def test_post(self): + with self.login(self.user_owner): + response = self.client.post( + reverse( + "usersec:hpcgroupchangerequest-delete", + kwargs={"hpcgroupchangerequest": self.obj.uuid}, + ) ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(HpcGroupChangeRequest.objects.count(), 0) - self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + +class TestHpcGroupChangeRequestArchiveView(TestViewBase): + """Tests for HpcGroupChangeRequestArchiveView.""" + + def setUp(self): + super().setUp() + self.obj = HpcGroupChangeRequestFactory( + requester=self.user_owner, group=self.hpc_group, status=REQUEST_STATUS_ACTIVE + ) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( + reverse( + "usersec:hpcgroupchangerequest-archive", + kwargs={"hpcgroupchangerequest": self.obj.uuid}, + ) + ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) self.obj.refresh_from_db() - self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + self.assertEqual(self.obj.status, REQUEST_STATUS_ARCHIVED) class TestHpcUserView(TestViewBase): @@ -763,6 +893,30 @@ def test_get(self): self.assertEqual(response.status_code, 200) self.assertEqual(response.context["object"], self.hpc_owner) + def test_get_no_cluster_user(self): + with self.login(self.user): + response = self.client.get( + reverse( + "usersec:hpcuser-overview", + ) + ) + self.assertRedirects(response, reverse("usersec:orphan-user")) + + def test_get_retracted_group_change_request(self): + change_request = HpcGroupChangeRequestFactory( + requester=self.user_owner, status=REQUEST_STATUS_RETRACTED, group=self.hpc_group + ) + with self.login(self.user_owner): + response = self.client.get( + reverse( + "usersec:hpcuser-overview", + ) + ) + self.assertEqual(response.status_code, 200) + self.assertEqual( + response.context["retracted_group_change_request"], str(change_request.uuid) + ) + class TestHpcUserDetailView(TestViewBase): """Tests for HpcUserDetailView.""" @@ -827,18 +981,9 @@ def test_post_form_valid(self): ), data=data, ) - request = HpcUserCreateRequest.objects.first() - self.assertRedirects( - response, - reverse( - "usersec:hpcusercreaterequest-detail", - kwargs={"hpcusercreaterequest": request.uuid}, - ), - ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Couldn't submitted request for user creation.") - + self.assertEqual(HpcUserCreateRequest.objects.count(), 1) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) self.assertEqual(len(mail.outbox), 1) def test_post_form_invalid(self): @@ -1020,10 +1165,6 @@ def test_post(self): # TODO Sort out timezone issue # self.assertEqual(self.obj.expiration, update["expiration"]) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully updated request for user creation.") - self.assertEqual(len(mail.outbox), 1) def test_post_fail(self): @@ -1069,18 +1210,6 @@ def test_get(self): kwargs={"hpcusercreaterequest": self.obj.uuid}, ) ) - self.assertEqual(response.status_code, 200) - self.assertIsNotNone(response.context["form"]) - - def test_post(self): - with self.login(self.user_owner): - response = self.client.post( - reverse( - "usersec:hpcusercreaterequest-retract", - kwargs={"hpcusercreaterequest": self.obj.uuid}, - ), - ) - self.assertRedirects( response, reverse( @@ -1089,10 +1218,6 @@ def test_post(self): ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully retracted request for user creation.") - self.assertEqual(self.obj.status, REQUEST_STATUS_INITIAL) self.obj.refresh_from_db() self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) @@ -1100,7 +1225,7 @@ def test_post(self): self.assertEqual(len(mail.outbox), 0) -class TestHpcUserCreateRequestRectivateView(TestViewBase): +class TestHpcUserCreateRequestReactivateView(TestViewBase): """Tests for HpcUserCreateRequestReactivateView.""" def setUp(self): @@ -1118,23 +1243,62 @@ def test_get(self): ) ) - self.assertRedirects( - response, + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + self.obj.refresh_from_db() + self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + + +class TestHpcUserCreateRequestDeleteView(TestViewBase): + """Tests for HpcUserCreateRequestDeleteView.""" + + def setUp(self): + super().setUp() + self.obj = HpcUserCreateRequestFactory(requester=self.user_owner, group=self.hpc_group) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( reverse( - "usersec:hpcusercreaterequest-detail", + "usersec:hpcusercreaterequest-delete", kwargs={"hpcusercreaterequest": self.obj.uuid}, - ), + ) ) + self.assertEqual(response.status_code, 200) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual( - str(messages[0]), "Successfully re-activated request for user creation." + def test_post(self): + with self.login(self.user_owner): + response = self.client.post( + reverse( + "usersec:hpcusercreaterequest-delete", + kwargs={"hpcusercreaterequest": self.obj.uuid}, + ) ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(HpcUserCreateRequest.objects.count(), 0) - self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + +class TestHpcUserCreateRequestArchiveView(TestViewBase): + """Tests for HpcUserCreateRequestArchiveView.""" + + def setUp(self): + super().setUp() + self.obj = HpcUserCreateRequestFactory(requester=self.user_owner, group=self.hpc_group) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( + reverse( + "usersec:hpcusercreaterequest-archive", + kwargs={"hpcusercreaterequest": self.obj.uuid}, + ) + ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) self.obj.refresh_from_db() - self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + self.assertEqual(self.obj.status, REQUEST_STATUS_ARCHIVED) class TestHpcUserChangeRequestCreateView(TestViewBase): @@ -1158,18 +1322,9 @@ def test_post_form_valid(self): ), data=data, ) - request = HpcUserChangeRequest.objects.first() - self.assertRedirects( - response, - reverse( - "usersec:hpcuserchangerequest-detail", - kwargs={"hpcuserchangerequest": request.uuid}, - ), - ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully submitted request for user update.") - + self.assertEqual(HpcUserChangeRequest.objects.count(), 1) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) self.assertEqual(len(mail.outbox), 1) def test_post_form_invalid(self): @@ -1335,10 +1490,6 @@ def test_post(self): # TODO Sort out timezone issue # self.assertEqual(self.obj.expiration, update["expiration"]) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully updated request for user update.") - self.assertEqual(len(mail.outbox), 0) def test_post_fail(self): @@ -1379,18 +1530,6 @@ def test_get(self): kwargs={"hpcuserchangerequest": self.obj.uuid}, ) ) - self.assertEqual(response.status_code, 200) - self.assertIsNotNone(response.context["form"]) - - def test_post(self): - with self.login(self.user_owner): - response = self.client.post( - reverse( - "usersec:hpcuserchangerequest-retract", - kwargs={"hpcuserchangerequest": self.obj.uuid}, - ), - ) - self.assertRedirects( response, reverse( @@ -1399,10 +1538,6 @@ def test_post(self): ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully retracted request for user update.") - self.assertEqual(self.obj.status, REQUEST_STATUS_INITIAL) self.obj.refresh_from_db() self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) @@ -1410,7 +1545,7 @@ def test_post(self): self.assertEqual(len(mail.outbox), 0) -class TestHpcUserChangeRequestRectivateView(TestViewBase): +class TestHpcUserChangeRequestReactivateView(TestViewBase): """Tests for HpcUserChangeRequestReactivateView.""" def setUp(self): @@ -1428,21 +1563,62 @@ def test_get(self): ) ) - self.assertRedirects( - response, + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + self.obj.refresh_from_db() + self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + + +class TestHpcUserChangeRequestDeleteView(TestViewBase): + """Tests for HpcUserChangeRequestDeleteView.""" + + def setUp(self): + super().setUp() + self.obj = HpcUserChangeRequestFactory(requester=self.user_owner, user=self.hpc_member) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( reverse( - "usersec:hpcuserchangerequest-detail", + "usersec:hpcuserchangerequest-delete", kwargs={"hpcuserchangerequest": self.obj.uuid}, - ), + ) ) + self.assertEqual(response.status_code, 200) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully re-activated request for user update.") + def test_post(self): + with self.login(self.user_owner): + response = self.client.post( + reverse( + "usersec:hpcuserchangerequest-delete", + kwargs={"hpcuserchangerequest": self.obj.uuid}, + ) + ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(HpcUserChangeRequest.objects.count(), 0) - self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + +class TestHpcUserChangeRequestArchiveView(TestViewBase): + """Tests for HpcUserChangeRequestArchiveView.""" + + def setUp(self): + super().setUp() + self.obj = HpcUserChangeRequestFactory(requester=self.user_owner, user=self.hpc_member) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( + reverse( + "usersec:hpcuserchangerequest-archive", + kwargs={"hpcuserchangerequest": self.obj.uuid}, + ) + ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) self.obj.refresh_from_db() - self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + self.assertEqual(self.obj.status, REQUEST_STATUS_ARCHIVED) class TestHpcProjectCreateRequestCreateView(TestViewBase): @@ -1470,20 +1646,8 @@ def test_post_form_valid(self): data=data, ) self.assertEqual(HpcProjectCreateRequest.objects.count(), 1) - request = HpcProjectCreateRequest.objects.first() - self.assertRedirects( - response, - reverse( - "usersec:hpcprojectcreaterequest-detail", - kwargs={"hpcprojectcreaterequest": request.uuid}, - ), - ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual( - str(messages[0]), "Successfully submitted request for project creation." - ) - + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) self.assertEqual(len(mail.outbox), 2) def test_post_form_invalid(self): @@ -1693,10 +1857,6 @@ def test_post(self): # TODO Sort out timezone issue # self.assertEqual(self.obj.expiration, update["expiration"]) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully updated request for project creation.") - self.assertEqual(len(mail.outbox), 0) def test_post_fail(self): @@ -1741,18 +1901,6 @@ def test_get(self): kwargs={"hpcprojectcreaterequest": self.obj.uuid}, ) ) - self.assertEqual(response.status_code, 200) - self.assertIsNotNone(response.context["form"]) - - def test_post(self): - with self.login(self.user_owner): - response = self.client.post( - reverse( - "usersec:hpcprojectcreaterequest-retract", - kwargs={"hpcprojectcreaterequest": self.obj.uuid}, - ), - ) - self.assertRedirects( response, reverse( @@ -1761,12 +1909,6 @@ def test_post(self): ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual( - str(messages[0]), "Successfully retracted request for project creation." - ) - self.assertEqual(self.obj.status, REQUEST_STATUS_INITIAL) self.obj.refresh_from_db() self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) @@ -1792,23 +1934,62 @@ def test_get(self): ) ) - self.assertRedirects( - response, + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + self.obj.refresh_from_db() + self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + + +class TestHpcProjectCreateRequestDeleteView(TestViewBase): + """Tests for HpcProjectCreateRequestDeleteView.""" + + def setUp(self): + super().setUp() + self.obj = HpcProjectCreateRequestFactory(requester=self.user_owner, group=self.hpc_group) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( reverse( - "usersec:hpcprojectcreaterequest-detail", + "usersec:hpcprojectcreaterequest-delete", kwargs={"hpcprojectcreaterequest": self.obj.uuid}, - ), + ) ) + self.assertEqual(response.status_code, 200) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual( - str(messages[0]), "Successfully re-activated request for project creation." + def test_post(self): + with self.login(self.user_owner): + response = self.client.post( + reverse( + "usersec:hpcprojectcreaterequest-delete", + kwargs={"hpcprojectcreaterequest": self.obj.uuid}, + ) ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(HpcProjectCreateRequest.objects.count(), 0) - self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + +class TestHpcProjectCreateRequestArchiveView(TestViewBase): + """Tests for HpcProjectCreateRequestArchiveView.""" + + def setUp(self): + super().setUp() + self.obj = HpcProjectCreateRequestFactory(requester=self.user_owner, group=self.hpc_group) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( + reverse( + "usersec:hpcprojectcreaterequest-archive", + kwargs={"hpcprojectcreaterequest": self.obj.uuid}, + ) + ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) self.obj.refresh_from_db() - self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + self.assertEqual(self.obj.status, REQUEST_STATUS_ARCHIVED) class TestHpcProjectChangeRequestCreateView(TestViewBase): @@ -1836,18 +2017,7 @@ def test_post_form_valid(self): data=data, ) self.assertEqual(HpcProjectChangeRequest.objects.count(), 1) - request = HpcProjectChangeRequest.objects.first() - self.assertRedirects( - response, - reverse( - "usersec:hpcprojectchangerequest-detail", - kwargs={"hpcprojectchangerequest": request.uuid}, - ), - ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully submitted request for project update.") - + self.assertRedirects(response, reverse("home")) self.assertEqual(len(mail.outbox), 1) def test_post_form_invalid(self): @@ -2052,10 +2222,6 @@ def test_post(self): # TODO Sort out timezone issue # self.assertEqual(self.obj.expiration, update["expiration"]) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully updated request for project update.") - self.assertEqual(len(mail.outbox), 0) def test_post_fail(self): @@ -2100,18 +2266,6 @@ def test_get(self): kwargs={"hpcprojectchangerequest": self.obj.uuid}, ) ) - self.assertEqual(response.status_code, 200) - self.assertIsNotNone(response.context["form"]) - - def test_post(self): - with self.login(self.user_owner): - response = self.client.post( - reverse( - "usersec:hpcprojectchangerequest-retract", - kwargs={"hpcprojectchangerequest": self.obj.uuid}, - ), - ) - self.assertRedirects( response, reverse( @@ -2120,10 +2274,6 @@ def test_post(self): ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully retracted request for project update.") - self.assertEqual(self.obj.status, REQUEST_STATUS_INITIAL) self.obj.refresh_from_db() self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) @@ -2131,7 +2281,7 @@ def test_post(self): self.assertEqual(len(mail.outbox), 0) -class TestHpcProjectChangeRequestRectivateView(TestViewBase): +class TestHpcProjectChangeRequestReactivateView(TestViewBase): """Tests for HpcProjectChangeRequestReactivateView.""" def setUp(self): @@ -2149,23 +2299,66 @@ def test_get(self): ) ) - self.assertRedirects( - response, + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + self.obj.refresh_from_db() + self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + + +class TestHpcProjectChangeRequestDeleteView(TestViewBase): + """Tests for HpcProjectChangeRequestDeleteView.""" + + def setUp(self): + super().setUp() + self.obj = HpcProjectChangeRequestFactory( + requester=self.user_owner, project=self.hpc_project + ) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( reverse( - "usersec:hpcprojectchangerequest-detail", + "usersec:hpcprojectchangerequest-delete", kwargs={"hpcprojectchangerequest": self.obj.uuid}, - ), + ) ) + self.assertEqual(response.status_code, 200) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual( - str(messages[0]), "Successfully re-activated request for project update." + def test_post(self): + with self.login(self.user_owner): + response = self.client.post( + reverse( + "usersec:hpcprojectchangerequest-delete", + kwargs={"hpcprojectchangerequest": self.obj.uuid}, + ) ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + self.assertEqual(HpcProjectChangeRequest.objects.count(), 0) - self.assertEqual(self.obj.status, REQUEST_STATUS_RETRACTED) + +class TestHpcProjectChangeRequestArchiveView(TestViewBase): + """Tests for HpcProjectChangeRequestArchiveView.""" + + def setUp(self): + super().setUp() + self.obj = HpcProjectChangeRequestFactory( + requester=self.user_owner, project=self.hpc_project + ) + + def test_get(self): + with self.login(self.user_owner): + response = self.client.get( + reverse( + "usersec:hpcprojectchangerequest-archive", + kwargs={"hpcprojectchangerequest": self.obj.uuid}, + ) + ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) self.obj.refresh_from_db() - self.assertEqual(self.obj.status, REQUEST_STATUS_ACTIVE) + self.assertEqual(self.obj.status, REQUEST_STATUS_ARCHIVED) class TestHpcGroupInvitationDetailView(TestViewBase): @@ -2240,10 +2433,6 @@ def test_get(self): ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Invitation successfully accepted and user created.") - self.assertEqual(self.obj.status, INVITATION_STATUS_PENDING) self.obj.refresh_from_db() self.assertEqual(self.obj.status, INVITATION_STATUS_ACCEPTED) @@ -2295,10 +2484,6 @@ def test_post(self): ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Invitation successfully rejected.") - self.assertEqual(self.obj.status, INVITATION_STATUS_PENDING) self.obj.refresh_from_db() self.assertEqual(self.obj.status, INVITATION_STATUS_REJECTED) @@ -2339,10 +2524,6 @@ def test_get(self): list(self.hpc_project.members.all()), [self.hpc_owner, self.hpc_member] ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Successfully joined the project.") - self.assertEqual(self.obj.status, INVITATION_STATUS_PENDING) self.obj.refresh_from_db() self.assertEqual(self.obj.status, INVITATION_STATUS_ACCEPTED) @@ -2391,10 +2572,6 @@ def test_post(self): ), ) - messages = list(get_messages(response.wsgi_request)) - self.assertEqual(len(messages), 1) - self.assertEqual(str(messages[0]), "Invitation successfully rejected.") - self.assertEqual(self.obj.status, INVITATION_STATUS_PENDING) self.obj.refresh_from_db() self.assertEqual(self.obj.status, INVITATION_STATUS_REJECTED) @@ -2458,3 +2635,19 @@ def test_get_as_pi_published(self): self.assertListEqual( list(response.context["object_list"]), [self.terms_all, self.terms_pi] ) + + def test_post(self): + self.user_owner.consented_to_terms = False + with self.login(self.user_owner): + response = self.client.post( + reverse("usersec:terms"), + { + "terms": [self.terms_all.id, self.terms_users.id], + }, + follow=True, + ) + self.assertRedirects(response, reverse("home")) + self.assertNoMessages(response) + + self.user_owner.refresh_from_db() + self.assertTrue(self.user_owner.consented_to_terms) diff --git a/usersec/tests/test_views_api.py b/usersec/tests/test_views_api.py new file mode 100644 index 0000000..f6bb226 --- /dev/null +++ b/usersec/tests/test_views_api.py @@ -0,0 +1,63 @@ +from django.urls import reverse +from rest_framework import status +from rest_framework.test import APITestCase + +from usersec.models import HpcUser +from usersec.tests.factories import HpcUserFactory + + +class TestHpcUserLookupApiView(APITestCase): + """Tests for HpcUserLookupApiView.""" + + def test_list_empty(self): + url = reverse("usersec:api-hpcuser-lookup") + expected = [] + response = self.client.get(url + "?q=user") + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.json(), expected) + + def test_list_all(self): + HpcUserFactory.create_batch(3) + url = reverse("usersec:api-hpcuser-lookup") + response = self.client.get(url + "?q=user") + self.assertEqual(response.status_code, status.HTTP_200_OK) + users = HpcUser.objects.all() + expected = [ + { + "full_name": users[0].user.name, + "id": users[0].id, + "primary_group": users[0].primary_group.name, + "username": users[0].username, + }, + { + "full_name": users[1].user.name, + "id": users[1].id, + "primary_group": users[1].primary_group.name, + "username": users[1].username, + }, + { + "full_name": users[2].user.name, + "id": users[2].id, + "primary_group": users[2].primary_group.name, + "username": users[2].username, + }, + ] + + self.assertEqual(response.json(), expected) + + def test_list_single(self): + HpcUserFactory.create_batch(3) + url = reverse("usersec:api-hpcuser-lookup") + response = self.client.get(url + f"?q={HpcUser.objects.first().username}") + self.assertEqual(response.status_code, status.HTTP_200_OK) + users = HpcUser.objects.all() + expected = [ + { + "full_name": users[0].user.name, + "id": users[0].id, + "primary_group": users[0].primary_group.name, + "username": users[0].username, + }, + ] + + self.assertEqual(response.json(), expected) diff --git a/usersec/urls.py b/usersec/urls.py index 8e20f99..3326ead 100644 --- a/usersec/urls.py +++ b/usersec/urls.py @@ -1,7 +1,7 @@ from django.urls import path from django.views.generic import TemplateView -from usersec import views +from usersec import views, views_api app_name = "usersec" @@ -45,6 +45,16 @@ view=views.HpcGroupCreateRequestReactivateView.as_view(), name="hpcgroupcreaterequest-reactivate", ), + path( + "hpcgroupcreaterequest//delete/", + view=views.HpcGroupCreateRequestDeleteView.as_view(), + name="hpcgroupcreaterequest-delete", + ), + path( + "hpcgroupcreaterequest//archive/", + view=views.HpcGroupCreateRequestArchiveView.as_view(), + name="hpcgroupcreaterequest-archive", + ), # ------------------------------------------------------------------------------ # HpcGroupChangeRequest related # ------------------------------------------------------------------------------ @@ -73,6 +83,16 @@ view=views.HpcGroupChangeRequestReactivateView.as_view(), name="hpcgroupchangerequest-reactivate", ), + path( + "hpcgroupchangerequest//delete/", + view=views.HpcGroupChangeRequestDeleteView.as_view(), + name="hpcgroupchangerequest-delete", + ), + path( + "hpcgroupchangerequest//archive/", + view=views.HpcGroupChangeRequestArchiveView.as_view(), + name="hpcgroupchangerequest-archive", + ), # ------------------------------------------------------------------------------ # HpcGroupDeleteRequest related # ------------------------------------------------------------------------------ @@ -101,6 +121,16 @@ view=views.HpcGroupDeleteRequestReactivateView.as_view(), name="hpcgroupdeleterequest-reactivate", ), + path( + "hpcgroupdeleterequest//delete/", + view=views.HpcGroupDeleteRequestDeleteView.as_view(), + name="hpcgroupdeleterequest-delete", + ), + path( + "hpcgroupdeleterequest//archive/", + view=views.HpcGroupDeleteRequestArchiveView.as_view(), + name="hpcgroupdeleterequest-archive", + ), # ------------------------------------------------------------------------------ # HpcUser related # ------------------------------------------------------------------------------ @@ -109,7 +139,7 @@ view=views.HpcUserView.as_view(), name="hpcuser-overview", ), - path( + path( # TODO OBSOLETE "hpcuser//detail/", view=views.HpcUserDetailView.as_view(), name="hpcuser-detail", @@ -142,6 +172,16 @@ view=views.HpcUserCreateRequestReactivateView.as_view(), name="hpcusercreaterequest-reactivate", ), + path( + "hpcusercreaterequest//delete/", + view=views.HpcUserCreateRequestDeleteView.as_view(), + name="hpcusercreaterequest-delete", + ), + path( + "hpcusercreaterequest//archive/", + view=views.HpcUserCreateRequestArchiveView.as_view(), + name="hpcusercreaterequest-archive", + ), # ------------------------------------------------------------------------------ # HpcUserChangeRequest related # ------------------------------------------------------------------------------ @@ -170,6 +210,16 @@ view=views.HpcUserChangeRequestReactivateView.as_view(), name="hpcuserchangerequest-reactivate", ), + path( + "hpcuserchangerequest//delete/", + view=views.HpcUserChangeRequestDeleteView.as_view(), + name="hpcuserchangerequest-delete", + ), + path( + "hpcuserchangerequest//archive/", + view=views.HpcUserChangeRequestArchiveView.as_view(), + name="hpcuserchangerequest-archive", + ), # ------------------------------------------------------------------------------ # HpcUserDeleteRequest related # ------------------------------------------------------------------------------ @@ -198,6 +248,16 @@ view=views.HpcUserDeleteRequestReactivateView.as_view(), name="hpcuserdeleterequest-reactivate", ), + path( + "hpcuserdeleterequest//delete/", + view=views.HpcUserDeleteRequestDeleteView.as_view(), + name="hpcuserdeleterequest-delete", + ), + path( + "hpcuserdeleterequest//archive/", + view=views.HpcUserDeleteRequestArchiveView.as_view(), + name="hpcuserdeleterequest-archive", + ), # ------------------------------------------------------------------------------ # HpcProject related # ------------------------------------------------------------------------------ @@ -234,6 +294,16 @@ view=views.HpcProjectCreateRequestReactivateView.as_view(), name="hpcprojectcreaterequest-reactivate", ), + path( + "hpcprojectcreaterequest//delete/", + view=views.HpcProjectCreateRequestDeleteView.as_view(), + name="hpcprojectcreaterequest-delete", + ), + path( + "hpcprojectcreaterequest//archive/", + view=views.HpcProjectCreateRequestArchiveView.as_view(), + name="hpcprojectcreaterequest-archive", + ), # ------------------------------------------------------------------------------ # HpcProjectChangeRequest related # ------------------------------------------------------------------------------ @@ -262,6 +332,16 @@ view=views.HpcProjectChangeRequestReactivateView.as_view(), name="hpcprojectchangerequest-reactivate", ), + path( + "hpcprojectchangerequest//delete/", + view=views.HpcProjectChangeRequestDeleteView.as_view(), + name="hpcprojectchangerequest-delete", + ), + path( + "hpcprojectchangerequest//archive/", + view=views.HpcProjectChangeRequestArchiveView.as_view(), + name="hpcprojectchangerequest-archive", + ), # ------------------------------------------------------------------------------ # HpcProjectDeleteRequest related # ------------------------------------------------------------------------------ @@ -290,6 +370,16 @@ view=views.HpcProjectDeleteRequestReactivateView.as_view(), name="hpcprojectdeleterequest-reactivate", ), + path( + "hpcprojectdeleterequest//delete/", + view=views.HpcProjectDeleteRequestDeleteView.as_view(), + name="hpcprojectdeleterequest-delete", + ), + path( + "hpcprojectdeleterequest//archive/", + view=views.HpcProjectDeleteRequestArchiveView.as_view(), + name="hpcprojectdeleterequest-archive", + ), # ------------------------------------------------------------------------------ # HpcGroupInvitation related # ------------------------------------------------------------------------------ @@ -321,4 +411,12 @@ view=views.HpcProjectInvitationRejectView.as_view(), name="hpcprojectinvitation-reject", ), + # ------------------------------------------------------------------------------ + # API + # ------------------------------------------------------------------------------ + path( + "api/hpcuser/lookup/", + view=views_api.HpcUserLookupApiView.as_view(), + name="api-hpcuser-lookup", + ), ] diff --git a/usersec/views.py b/usersec/views.py index 978f5a3..4823815 100644 --- a/usersec/views.py +++ b/usersec/views.py @@ -1,3 +1,5 @@ +from itertools import chain + import rules from django.conf import settings from django.contrib import messages @@ -42,6 +44,11 @@ INVITATION_STATUS_REJECTED, OBJECT_STATUS_ACTIVE, REQUEST_STATUS_ACTIVE, + REQUEST_STATUS_APPROVED, + REQUEST_STATUS_ARCHIVED, + REQUEST_STATUS_DENIED, + REQUEST_STATUS_RETRACTED, + REQUEST_STATUS_REVISED, REQUEST_STATUS_REVISION, TERMS_AUDIENCE_ALL, TERMS_AUDIENCE_PI, @@ -71,10 +78,8 @@ MSG_PART_SUBMITTED = "submitted" MSG_PART_UPDATE = "update" MSG_PART_UPDATED = "updated" -MSG_PART_RETRACT = "retract" -MSG_PART_RETRACTED = "retracted" -MSG_PART_REACTIVATE = "re-activate" -MSG_PART_REACTIVATED = "re-activated" +MSG_PART_DELETED = "deleted" +MSG_PART_ARCHIVED = "archived" MSG_PART_GROUP_CREATION = "group creation" MSG_PART_GROUP_UPDATE = "group update" MSG_PART_GROUP_DELETION = "group deletion" @@ -100,14 +105,6 @@ MSG_TERMS_CONSENT = "Consented successfully to terms and conditions." -# ----------------------------------------------------------------------------- -# Object comments -# ----------------------------------------------------------------------------- - -COMMENT_REACTIVATED = "Request re-activated" -COMMENT_RETRACTED = "Request retracted" - - class HpcPermissionMixin(LoginRequiredMixin, PermissionRequiredMixin): """Customized required login and permission mixin.""" @@ -132,9 +129,6 @@ def get(self, request, *args, **kwargs): if request.user.is_hpcadmin: return redirect(reverse("adminsec:overview")) - if not request.user.is_active: - return redirect(reverse("logout")) - if not request.user.consented_to_terms and get_terms_and_conditions(self.request).exists(): return redirect(reverse("usersec:terms")) @@ -145,7 +139,9 @@ def get(self, request, *args, **kwargs): return redirect(reverse("usersec:view-mode-enabled")) if rules.test_rule("usersec.has_pending_group_request", request.user): - request_uuid = request.user.hpcgroupcreaterequest_requester.first().uuid + request_uuid = request.user.hpcgroupcreaterequest_requester.get( + status__in=[REQUEST_STATUS_ACTIVE, REQUEST_STATUS_REVISED] + ).uuid return redirect( reverse( "usersec:hpcgroupcreaterequest-detail", @@ -207,9 +203,6 @@ def form_valid(self, form): send_notification_manager_group_request(obj) send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_SUBMITTED, MSG_PART_GROUP_CREATION) - ) return HttpResponseRedirect(self.get_success_url(obj.uuid)) @@ -232,6 +225,8 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() + context["is_hpc_group_create_request"] = True return context @@ -284,33 +279,23 @@ def form_valid(self, form): ) return HttpResponseRedirect(reverse("usersec:orphan-user")) - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_UPDATED, MSG_PART_GROUP_CREATION) - ) return HttpResponseRedirect(self.get_success_url()) -class HpcGroupCreateRequestRetractView(HpcPermissionMixin, DeleteView): +class HpcGroupCreateRequestRetractView(HpcPermissionMixin, SingleObjectMixin, View): """HPC group create request update view.""" - template_name_suffix = "_retract_confirm" model = HpcGroupCreateRequest slug_field = "uuid" slug_url_kwarg = "hpcgroupcreaterequest" permission_required = "usersec.manage_hpcgroupcreaterequest" - def post(self, request, *args, **kwargs): + def get(self, request, *args, **kwargs): obj = self.get_object() - obj.comment = COMMENT_RETRACTED obj.editor = self.request.user + obj.comment = "" obj.retract_with_version() - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_RETRACTED, MSG_PART_GROUP_CREATION) - ) - return HttpResponseRedirect( reverse( "usersec:hpcgroupcreaterequest-detail", @@ -320,7 +305,7 @@ def post(self, request, *args, **kwargs): class HpcGroupCreateRequestReactivateView(HpcPermissionMixin, SingleObjectMixin, View): - """HPC group create request update view.""" + """HPC group create request reactivate view.""" model = HpcGroupCreateRequest slug_field = "uuid" @@ -330,16 +315,13 @@ class HpcGroupCreateRequestReactivateView(HpcPermissionMixin, SingleObjectMixin, def get(self, request, *args, **kwargs): obj = self.get_object() obj.status = REQUEST_STATUS_ACTIVE - obj.comment = COMMENT_REACTIVATED obj.editor = self.request.user + obj.comment = "" obj.save_with_version() if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_REACTIVATED, MSG_PART_GROUP_CREATION) - ) return HttpResponseRedirect( reverse( "usersec:hpcgroupcreaterequest-detail", @@ -348,6 +330,36 @@ def get(self, request, *args, **kwargs): ) +class HpcGroupCreateRequestDeleteView(HpcPermissionMixin, DeleteView): + """HPC group create request delete view.""" + + template_name_suffix = "_delete_confirm" + model = HpcGroupCreateRequest + slug_field = "uuid" + slug_url_kwarg = "hpcgroupcreaterequest" + permission_required = "usersec.manage_hpcgroupcreaterequest" + + def get_success_url(self): + return reverse("home") + + +class HpcGroupCreateRequestArchiveView(HpcPermissionMixin, SingleObjectMixin, View): + """HPC user change request archive view.""" + + model = HpcGroupCreateRequest + slug_field = "uuid" + slug_url_kwarg = "hpcgroupcreaterequest" + permission_required = "usersec.manage_hpcgroupcreaterequest" + + def get(self, request, *args, **kwargs): + obj = self.get_object() + obj.status = REQUEST_STATUS_ARCHIVED + obj.editor = self.request.user + obj.save_with_version() + + return HttpResponseRedirect(reverse("home")) + + class HpcUserView(HpcPermissionMixin, DetailView): """HPC user overview.""" @@ -356,9 +368,6 @@ class HpcUserView(HpcPermissionMixin, DetailView): permission_required = "usersec.view_hpcuser" def get(self, request, *args, **kwargs): - if not request.user.is_active: - return redirect(reverse("logout")) - if not rules.test_rule("usersec.is_cluster_user", request.user): return redirect(reverse("home")) @@ -382,6 +391,25 @@ def get_context_data(self, **kwargs): context["project_manager"] = is_project_manager context["view_mode"] = settings.VIEW_MODE projects_available = False + context["pending_requests"] = [] + context["revision_requests"] = [] + context["retracted_requests"] = [] + context["has_pending_group_change_request"] = False + context["retracted_group_change_request"] = "" + + def get_requests_by_status(status): + return list( + chain( + HpcUserCreateRequest.objects.filter(group=group, status=status), + HpcProjectCreateRequest.objects.filter(group=group, status=status), + HpcUserChangeRequest.objects.filter(user__primary_group=group, status=status), + HpcGroupChangeRequest.objects.filter(group=group, status=status), + HpcProjectChangeRequest.objects.filter( + Q(project__group=group) | Q(project__delegate=context["object"]), + status=status, + ), + ) + ) if is_group_manager: context["hpcusercreaterequests"] = HpcUserCreateRequest.objects.filter(group=group) @@ -398,6 +426,26 @@ def get_context_data(self, **kwargs): context["hpcgroupdeleterequests"] = None context["hpcuserdeleterequests"] = None context["hpcprojectdeleterequests"] = None + context["requests"] = list( + chain( + get_requests_by_status(REQUEST_STATUS_ACTIVE), + get_requests_by_status(REQUEST_STATUS_REVISED), + get_requests_by_status(REQUEST_STATUS_REVISION), + get_requests_by_status(REQUEST_STATUS_RETRACTED), + get_requests_by_status(REQUEST_STATUS_APPROVED), + get_requests_by_status(REQUEST_STATUS_DENIED), + ) + ) + context["has_pending_group_change_request"] = HpcGroupChangeRequest.objects.filter( + group=group, status=REQUEST_STATUS_ACTIVE + ).exists() + hpc_group_change_request = HpcGroupChangeRequest.objects.filter( + group=group, status=REQUEST_STATUS_RETRACTED + ) + if hpc_group_change_request.exists(): + context["retracted_group_change_request"] = str( + hpc_group_change_request.first().uuid + ) context["form_user_select"] = UserSelectForm(group=group) projects_available |= group.hpcprojects.exists() @@ -406,6 +454,19 @@ def get_context_data(self, **kwargs): "project__delegate" ).filter(project__delegate=context["object"]) context["hpcprojectdeleterequests"] = None + context["pending_requests"] += list( + HpcProjectChangeRequest.objects.filter( + Q(project__group=group) | Q(project__delegate=context["object"]), + status__in=( + REQUEST_STATUS_ACTIVE, + REQUEST_STATUS_REVISION, + REQUEST_STATUS_REVISED, + REQUEST_STATUS_RETRACTED, + REQUEST_STATUS_APPROVED, + REQUEST_STATUS_DENIED, + ), + ) + ) projects_available |= context["object"].hpcproject_delegate.exists() if is_project_manager or is_group_manager: @@ -484,15 +545,7 @@ def form_valid(self, form): if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_FAILURE.format(MSG_PART_SUBMITTED, MSG_PART_USER_CREATION) - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcusercreaterequest-detail", - kwargs={"hpcusercreaterequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) class HpcUserCreateRequestDetailView(HpcPermissionMixin, DetailView): @@ -514,6 +567,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() return context @@ -568,31 +622,23 @@ def form_valid(self, form): if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_UPDATED, MSG_PART_USER_CREATION) - ) return HttpResponseRedirect(self.get_success_url()) -class HpcUserCreateRequestRetractView(HpcPermissionMixin, DeleteView): +class HpcUserCreateRequestRetractView(HpcPermissionMixin, SingleObjectMixin, View): """HPC user create request update view.""" - template_name_suffix = "_retract_confirm" model = HpcUserCreateRequest slug_field = "uuid" slug_url_kwarg = "hpcusercreaterequest" permission_required = "usersec.manage_hpcusercreaterequest" - def post(self, request, *args, **kwargs): + def get(self, request, *args, **kwargs): obj = self.get_object() - obj.comment = COMMENT_RETRACTED obj.editor = self.request.user + obj.comment = "" obj.retract_with_version() - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_RETRACTED, MSG_PART_USER_CREATION) - ) return HttpResponseRedirect( reverse( "usersec:hpcusercreaterequest-detail", @@ -602,7 +648,7 @@ def post(self, request, *args, **kwargs): class HpcUserCreateRequestReactivateView(HpcPermissionMixin, SingleObjectMixin, View): - """HPC user create request update view.""" + """HPC user create request reactivate view.""" model = HpcUserCreateRequest slug_field = "uuid" @@ -612,22 +658,44 @@ class HpcUserCreateRequestReactivateView(HpcPermissionMixin, SingleObjectMixin, def get(self, request, *args, **kwargs): obj = self.get_object() obj.status = REQUEST_STATUS_ACTIVE - obj.comment = COMMENT_REACTIVATED obj.editor = self.request.user + obj.comment = "" obj.save_with_version() if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_REACTIVATED, MSG_PART_USER_CREATION) - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcusercreaterequest-detail", - kwargs={"hpcusercreaterequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) + + +class HpcUserCreateRequestDeleteView(HpcPermissionMixin, DeleteView): + """HPC user create request delete view.""" + + template_name_suffix = "_delete_confirm" + model = HpcUserCreateRequest + slug_field = "uuid" + slug_url_kwarg = "hpcusercreaterequest" + permission_required = "usersec.manage_hpcusercreaterequest" + + def get_success_url(self): + return reverse("home") + + +class HpcUserCreateRequestArchiveView(HpcPermissionMixin, SingleObjectMixin, View): + """HPC user create request archive view.""" + + model = HpcUserCreateRequest + slug_field = "uuid" + slug_url_kwarg = "hpcusercreaterequest" + permission_required = "usersec.manage_hpcusercreaterequest" + + def get(self, request, *args, **kwargs): + obj = self.get_object() + obj.status = REQUEST_STATUS_ARCHIVED + obj.editor = self.request.user + obj.save_with_version() + + return HttpResponseRedirect(reverse("home")) class HpcGroupDeleteRequestCreateView(View): @@ -650,6 +718,14 @@ class HpcGroupDeleteRequestReactivateView(View): pass +class HpcGroupDeleteRequestDeleteView(View): + pass + + +class HpcGroupDeleteRequestArchiveView(View): + pass + + class HpcGroupChangeRequestCreateView(HpcPermissionMixin, CreateView): """HPC group change request create view. @@ -685,6 +761,21 @@ def get_context_data(self, **kwargs): context.update({"group": self.get_object()}) return context + def get(self, request, *args, **kwargs): + if HpcGroupChangeRequest.objects.filter( + group=self.get_object(), + status__in=( + REQUEST_STATUS_ACTIVE, + REQUEST_STATUS_REVISION, + REQUEST_STATUS_RETRACTED, + REQUEST_STATUS_REVISED, + ), + ).exists(): + messages.error(request, "There already exists an ongoing request to create the group.") + return HttpResponseRedirect(reverse("home")) + + return super().get(request, *args, **kwargs) + def form_valid(self, form): obj = form.save(commit=False) obj.requester = self.request.user @@ -704,15 +795,7 @@ def form_valid(self, form): if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_SUBMITTED, MSG_PART_GROUP_UPDATE) - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcgroupchangerequest-detail", - kwargs={"hpcgroupchangerequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) class HpcGroupChangeRequestDetailView(HpcPermissionMixin, DetailView): @@ -734,6 +817,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() return context @@ -785,32 +869,23 @@ def form_valid(self, form): ) return HttpResponseRedirect(reverse("home")) - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_UPDATED, MSG_PART_GROUP_UPDATE) - ) return HttpResponseRedirect(self.get_success_url()) -class HpcGroupChangeRequestRetractView(HpcPermissionMixin, DeleteView): +class HpcGroupChangeRequestRetractView(HpcPermissionMixin, SingleObjectMixin, View): """HPC group change request retract view.""" - template_name_suffix = "_retract_confirm" model = HpcGroupChangeRequest slug_field = "uuid" slug_url_kwarg = "hpcgroupchangerequest" permission_required = "usersec.manage_hpcgroupchangerequest" - def post(self, request, *args, **kwargs): + def get(self, request, *args, **kwargs): obj = self.get_object() - obj.comment = COMMENT_RETRACTED obj.editor = self.request.user + obj.comment = "" obj.retract_with_version() - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_RETRACTED, MSG_PART_GROUP_UPDATE) - ) return HttpResponseRedirect( reverse( "usersec:hpcgroupchangerequest-detail", @@ -820,7 +895,7 @@ def post(self, request, *args, **kwargs): class HpcGroupChangeRequestReactivateView(HpcPermissionMixin, SingleObjectMixin, View): - """HPC group change request update view.""" + """HPC group change request reactivate view.""" model = HpcGroupChangeRequest slug_field = "uuid" @@ -830,22 +905,44 @@ class HpcGroupChangeRequestReactivateView(HpcPermissionMixin, SingleObjectMixin, def get(self, request, *args, **kwargs): obj = self.get_object() obj.status = REQUEST_STATUS_ACTIVE - obj.comment = COMMENT_REACTIVATED obj.editor = self.request.user + obj.comment = "" obj.save_with_version() if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_REACTIVATED, MSG_PART_GROUP_UPDATE) - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcgroupchangerequest-detail", - kwargs={"hpcgroupchangerequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) + + +class HpcGroupChangeRequestDeleteView(HpcPermissionMixin, DeleteView): + """HPC group change request delete view.""" + + template_name_suffix = "_delete_confirm" + model = HpcGroupChangeRequest + slug_field = "uuid" + slug_url_kwarg = "hpcgroupchangerequest" + permission_required = "usersec.manage_hpcgroupchangerequest" + + def get_success_url(self): + return reverse("home") + + +class HpcGroupChangeRequestArchiveView(HpcPermissionMixin, SingleObjectMixin, View): + """HPC group change request archive view.""" + + model = HpcGroupChangeRequest + slug_field = "uuid" + slug_url_kwarg = "hpcgroupchangerequest" + permission_required = "usersec.manage_hpcgroupchangerequest" + + def get(self, request, *args, **kwargs): + obj = self.get_object() + obj.status = REQUEST_STATUS_ARCHIVED + obj.editor = self.request.user + obj.save_with_version() + + return HttpResponseRedirect(reverse("home")) class HpcUserDeleteRequestCreateView(View): @@ -868,6 +965,14 @@ class HpcUserDeleteRequestReactivateView(View): pass +class HpcUserDeleteRequestDeleteView(View): + pass + + +class HpcUserDeleteRequestArchiveView(View): + pass + + class HpcUserChangeRequestCreateView(HpcPermissionMixin, CreateView): """HPC user change request create view. @@ -920,15 +1025,7 @@ def form_valid(self, form): if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_SUBMITTED, MSG_PART_USER_UPDATE) - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcuserchangerequest-detail", - kwargs={"hpcuserchangerequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) class HpcUserChangeRequestDetailView(HpcPermissionMixin, DetailView): @@ -950,6 +1047,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() return context @@ -1001,32 +1099,23 @@ def form_valid(self, form): ) return HttpResponseRedirect(reverse("home")) - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_UPDATED, MSG_PART_USER_UPDATE) - ) return HttpResponseRedirect(self.get_success_url()) -class HpcUserChangeRequestRetractView(HpcPermissionMixin, DeleteView): +class HpcUserChangeRequestRetractView(HpcPermissionMixin, SingleObjectMixin, View): """HPC user change request update view.""" - template_name_suffix = "_retract_confirm" model = HpcUserChangeRequest slug_field = "uuid" slug_url_kwarg = "hpcuserchangerequest" permission_required = "usersec.manage_hpcuserchangerequest" - def post(self, request, *args, **kwargs): + def get(self, request, *args, **kwargs): obj = self.get_object() - obj.comment = COMMENT_RETRACTED obj.editor = self.request.user + obj.comment = "" obj.retract_with_version() - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_RETRACTED, MSG_PART_USER_UPDATE) - ) return HttpResponseRedirect( reverse( "usersec:hpcuserchangerequest-detail", @@ -1046,22 +1135,44 @@ class HpcUserChangeRequestReactivateView(HpcPermissionMixin, SingleObjectMixin, def get(self, request, *args, **kwargs): obj = self.get_object() obj.status = REQUEST_STATUS_ACTIVE - obj.comment = COMMENT_REACTIVATED obj.editor = self.request.user + obj.comment = "" obj.save_with_version() if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_REACTIVATED, MSG_PART_USER_UPDATE) - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcuserchangerequest-detail", - kwargs={"hpcuserchangerequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) + + +class HpcUserChangeRequestDeleteView(HpcPermissionMixin, DeleteView): + """HPC user change request delete view.""" + + template_name_suffix = "_delete_confirm" + model = HpcUserChangeRequest + slug_field = "uuid" + slug_url_kwarg = "hpcuserchangerequest" + permission_required = "usersec.manage_hpcuserchangerequest" + + def get_success_url(self): + return reverse("home") + + +class HpcUserChangeRequestArchiveView(HpcPermissionMixin, SingleObjectMixin, View): + """HPC user change request archive view.""" + + model = HpcUserChangeRequest + slug_field = "uuid" + slug_url_kwarg = "hpcuserchangerequest" + permission_required = "usersec.manage_hpcuserchangerequest" + + def get(self, request, *args, **kwargs): + obj = self.get_object() + obj.status = REQUEST_STATUS_ARCHIVED + obj.editor = self.request.user + obj.save_with_version() + + return HttpResponseRedirect(reverse("home")) class HpcProjectDetailView(HpcPermissionMixin, DetailView): @@ -1106,7 +1217,7 @@ def get_form_kwargs(self): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context.update({"group": self.get_object()}) + context.update({"owner_id": self.get_object().owner.id}) return context def form_valid(self, form): @@ -1133,15 +1244,7 @@ def form_valid(self, form): send_notification_admin_request(obj) send_notification_manager_project_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_SUBMITTED, MSG_PART_PROJECT_CREATION) - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcprojectcreaterequest-detail", - kwargs={"hpcprojectcreaterequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) class HpcProjectCreateRequestDetailView(HpcPermissionMixin, DetailView): @@ -1163,6 +1266,7 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() return context @@ -1179,6 +1283,7 @@ class HpcProjectCreateRequestUpdateView(HpcPermissionMixin, UpdateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["update"] = True + context["owner_id"] = self.get_object().group.owner.id return context def get_form_kwargs(self): @@ -1217,33 +1322,23 @@ def form_valid(self, form): obj.members.set(form.cleaned_data["members"]) obj.version_history.last().members.set(form.cleaned_data["members"]) - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_UPDATED, MSG_PART_PROJECT_CREATION) - ) return HttpResponseRedirect(self.get_success_url()) -class HpcProjectCreateRequestRetractView(HpcPermissionMixin, DeleteView): +class HpcProjectCreateRequestRetractView(HpcPermissionMixin, SingleObjectMixin, View): """HPC project create request update view.""" - template_name_suffix = "_retract_confirm" model = HpcProjectCreateRequest slug_field = "uuid" slug_url_kwarg = "hpcprojectcreaterequest" permission_required = "usersec.manage_hpcprojectcreaterequest" - def post(self, request, *args, **kwargs): + def get(self, request, *args, **kwargs): obj = self.get_object() - obj.comment = COMMENT_RETRACTED obj.editor = self.request.user + obj.comment = "" obj.retract_with_version() - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_RETRACTED, MSG_PART_PROJECT_CREATION) - ) - return HttpResponseRedirect( reverse( "usersec:hpcprojectcreaterequest-detail", @@ -1263,23 +1358,44 @@ class HpcProjectCreateRequestReactivateView(HpcPermissionMixin, SingleObjectMixi def get(self, request, *args, **kwargs): obj = self.get_object() obj.status = REQUEST_STATUS_ACTIVE - obj.comment = COMMENT_REACTIVATED obj.editor = self.request.user + obj.comment = "" obj.save_with_version() if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, - MSG_REQUEST_SUCCESS.format(MSG_PART_REACTIVATED, MSG_PART_PROJECT_CREATION), - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcprojectcreaterequest-detail", - kwargs={"hpcprojectcreaterequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) + + +class HpcProjectCreateRequestDeleteView(HpcPermissionMixin, DeleteView): + """HPC project create request delete view.""" + + template_name_suffix = "_delete_confirm" + model = HpcProjectCreateRequest + slug_field = "uuid" + slug_url_kwarg = "hpcprojectcreaterequest" + permission_required = "usersec.manage_hpcprojectcreaterequest" + + def get_success_url(self): + return reverse("home") + + +class HpcProjectCreateRequestArchiveView(HpcPermissionMixin, SingleObjectMixin, View): + """HPC project create request archive view.""" + + model = HpcProjectCreateRequest + slug_field = "uuid" + slug_url_kwarg = "hpcprojectcreaterequest" + permission_required = "usersec.manage_hpcprojectcreaterequest" + + def get(self, request, *args, **kwargs): + obj = self.get_object() + obj.status = REQUEST_STATUS_ARCHIVED + obj.editor = self.request.user + obj.save_with_version() + + return HttpResponseRedirect(reverse("home")) class HpcProjectDeleteRequestCreateView(View): @@ -1302,6 +1418,14 @@ class HpcProjectDeleteRequestReactivateView(View): pass +class HpcProjectDeleteRequestDeleteView(View): + pass + + +class HpcProjectDeleteRequestArchiveView(View): + pass + + class HpcProjectChangeRequestCreateView(HpcPermissionMixin, CreateView): """HPC project create request create view. @@ -1312,7 +1436,7 @@ class HpcProjectChangeRequestCreateView(HpcPermissionMixin, CreateView): # Required for permission checks, usually the CreateView doesn't have the current object # available model = HpcProject - template_name = "usersec/hpcprojectchangerequest_form.html" + template_name = "usersec/hpcprojectcreaterequest_form.html" slug_field = "uuid" slug_url_kwarg = "hpcproject" # Check permission based on HpcProject object @@ -1334,7 +1458,7 @@ def get_form_kwargs(self): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context.update({"project": self.get_object()}) + context["owner_id"] = self.get_object().group.owner.id return context def form_valid(self, form): @@ -1360,15 +1484,7 @@ def form_valid(self, form): if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_SUBMITTED, MSG_PART_PROJECT_UPDATE) - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcprojectchangerequest-detail", - kwargs={"hpcprojectchangerequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) class HpcProjectChangeRequestDetailView(HpcPermissionMixin, DetailView): @@ -1390,13 +1506,14 @@ def get_context_data(self, **kwargs): context["is_active"] = obj.is_active() context["is_revision"] = obj.is_revision() context["is_revised"] = obj.is_revised() + context["is_archived"] = obj.is_archived() return context class HpcProjectChangeRequestUpdateView(HpcPermissionMixin, UpdateView): """HPC project change request update view.""" - template_name = "usersec/hpcprojectchangerequest_form.html" + template_name = "usersec/hpcprojectcreaterequest_form.html" form_class = HpcProjectChangeRequestForm model = HpcProjectChangeRequest slug_field = "uuid" @@ -1406,7 +1523,7 @@ class HpcProjectChangeRequestUpdateView(HpcPermissionMixin, UpdateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["update"] = True - context["project"] = self.get_object().project + context["owner_id"] = self.get_object().project.group.owner.id return context def get_form_kwargs(self): @@ -1441,32 +1558,23 @@ def form_valid(self, form): ) return HttpResponseRedirect(reverse("home")) - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_UPDATED, MSG_PART_PROJECT_UPDATE) - ) return HttpResponseRedirect(self.get_success_url()) -class HpcProjectChangeRequestRetractView(HpcPermissionMixin, DeleteView): +class HpcProjectChangeRequestRetractView(HpcPermissionMixin, SingleObjectMixin, View): """HPC project change request retract view.""" - template_name_suffix = "_retract_confirm" model = HpcProjectChangeRequest slug_field = "uuid" slug_url_kwarg = "hpcprojectchangerequest" permission_required = "usersec.manage_hpcprojectchangerequest" - def post(self, request, *args, **kwargs): + def get(self, request, *args, **kwargs): obj = self.get_object() - obj.comment = COMMENT_RETRACTED obj.editor = self.request.user + obj.comment = "" obj.retract_with_version() - # No email notification required - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_RETRACTED, MSG_PART_PROJECT_UPDATE) - ) return HttpResponseRedirect( reverse( "usersec:hpcprojectchangerequest-detail", @@ -1486,22 +1594,44 @@ class HpcProjectChangeRequestReactivateView(HpcPermissionMixin, SingleObjectMixi def get(self, request, *args, **kwargs): obj = self.get_object() obj.status = REQUEST_STATUS_ACTIVE - obj.comment = COMMENT_REACTIVATED obj.editor = self.request.user + obj.comment = "" obj.save_with_version() if settings.SEND_EMAIL: send_notification_admin_request(obj) - messages.success( - self.request, MSG_REQUEST_SUCCESS.format(MSG_PART_REACTIVATED, MSG_PART_PROJECT_UPDATE) - ) - return HttpResponseRedirect( - reverse( - "usersec:hpcprojectchangerequest-detail", - kwargs={"hpcprojectchangerequest": obj.uuid}, - ) - ) + return HttpResponseRedirect(reverse("home")) + + +class HpcProjectChangeRequestDeleteView(HpcPermissionMixin, DeleteView): + """HPC project change request delete view.""" + + template_name_suffix = "_delete_confirm" + model = HpcProjectChangeRequest + slug_field = "uuid" + slug_url_kwarg = "hpcprojectchangerequest" + permission_required = "usersec.manage_hpcprojectchangerequest" + + def get_success_url(self): + return reverse("home") + + +class HpcProjectChangeRequestArchiveView(HpcPermissionMixin, SingleObjectMixin, View): + """HPC project change request archive view.""" + + model = HpcProjectChangeRequest + slug_field = "uuid" + slug_url_kwarg = "hpcprojectchangerequest" + permission_required = "usersec.manage_hpcprojectchangerequest" + + def get(self, request, *args, **kwargs): + obj = self.get_object() + obj.status = REQUEST_STATUS_ARCHIVED + obj.editor = self.request.user + obj.save_with_version() + + return HttpResponseRedirect(reverse("home")) class HpcGroupInvitationDetailView(HpcPermissionMixin, DetailView): @@ -1574,7 +1704,6 @@ def get(self, request, *args, **kwargs): send_notification_manager_user_decided_invitation(obj) send_notification_user_welcome_mail(hpcuser) - messages.success(request, MSG_INVITATION_GROUP_USER_CREATE_SUCCESS) return HttpResponseRedirect( reverse( "usersec:hpcuser-overview", @@ -1599,7 +1728,6 @@ def post(self, request, *args, **kwargs): if settings.SEND_EMAIL: send_notification_manager_user_decided_invitation(obj) - messages.success(request, MSG_INVITATION_REJECTED_SUCCESS) return HttpResponseRedirect( reverse( "usersec:hpcgroupinvitation-detail", @@ -1647,7 +1775,6 @@ def get(self, request, *args, **kwargs): if settings.SEND_EMAIL: send_notification_manager_user_decided_invitation(obj) - messages.success(request, MSG_INVITATION_PROJECT_USER_ADD_SUCCESS) return HttpResponseRedirect( reverse( "usersec:hpcuser-overview", @@ -1672,7 +1799,6 @@ def post(self, request, *args, **kwargs): if settings.SEND_EMAIL: send_notification_manager_user_decided_invitation(obj) - messages.success(self.request, MSG_INVITATION_REJECTED_SUCCESS) return HttpResponseRedirect( reverse( "usersec:hpcuser-overview", @@ -1703,5 +1829,4 @@ def post(self, request, *args, **kwargs): request.user.consented_to_terms = True request.user.save() - messages.success(self.request, MSG_TERMS_CONSENT) return HttpResponseRedirect(reverse("home")) diff --git a/usersec/views_api.py b/usersec/views_api.py new file mode 100644 index 0000000..67f77ab --- /dev/null +++ b/usersec/views_api.py @@ -0,0 +1,24 @@ +from django.db.models import Q +from rest_framework.generics import ListAPIView + +from usersec.models import HpcUser +from usersec.serializers import HpcUserLookupSerializer + + +class HpcUserLookupApiView(ListAPIView): + """API view for retrieving, updating and deleting a user.""" + + queryset = HpcUser.objects.all() + serializer_class = HpcUserLookupSerializer + # permission_classes = [] + + def paginate_queryset(self, _queryset): + # Don't paginate the results + return None + + def filter_queryset(self, queryset=None): + queryset = super().filter_queryset(queryset) + return queryset.filter( + Q(username__icontains=self.request.query_params.get("q", "")) + | Q(user__name__icontains=self.request.query_params.get("q", "")) + )