diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-10-29 17:50:49 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-02-19 14:43:49 +0100 |
commit | 547a20789faf6bbc9979357c7f65cbe61e56ed07 (patch) | |
tree | 5ede13492f49434468607950769266d643333d11 /archaeological_operations | |
parent | fcc0bb255730d43ec2cff78fb8b948d6322a8b68 (diff) | |
download | Ishtar-547a20789faf6bbc9979357c7f65cbe61e56ed07.tar.bz2 Ishtar-547a20789faf6bbc9979357c7f65cbe61e56ed07.zip |
✨ permissions refactoring: link items to user QA forms
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/models.py | 20 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 24 | ||||
-rw-r--r-- | archaeological_operations/urls.py | 13 |
3 files changed, 55 insertions, 2 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 9e43f264b..debc26d8b 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -584,6 +584,13 @@ class ArchaeologicalSite( "archaeological_operations.change_own_archaeologicalsite" ], ) + QA_LINK = QuickAction( + url="site-qa-link", + icon_class="fa fa-link", + text=_("Link to account"), + target="many", + rights=["ishtaradmin"], + ) QA_EDIT = QuickAction( url="site-qa-bulk-update", icon_class="fa fa-pencil", @@ -596,7 +603,6 @@ class ArchaeologicalSite( ) QUICK_ACTIONS = [ QA_EDIT, - QA_LOCK, QuickAction( url="site-add-operation", icon_class="fa fa-plus", @@ -615,6 +621,8 @@ class ArchaeologicalSite( "archaeological_operations.change_own_archaeologicalsite" ], ), + QA_LOCK, + QA_LINK ] objects = SiteManager() @@ -1478,9 +1486,15 @@ class Operation( "archaeological_operations.change_own_operation" ], ) + QA_LINK = QuickAction( + url="operation-qa-link", + icon_class="fa fa-link", + text=_("Link to account"), + target="many", + rights=["ishtaradmin"], + ) QUICK_ACTIONS = [ QA_EDIT, - QA_LOCK, QuickAction( url="operation-qa-duplicate", icon_class="fa fa-clone", @@ -1491,6 +1505,8 @@ class Operation( "archaeological_operations.change_own_operation" ], ), + QA_LOCK, + QA_LINK, ] UP_MODEL_QUERY = { diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 18d927d06..41d4a8611 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -4784,6 +4784,30 @@ class OperationQATest(OperationInitTest, TestCase): Permission.objects.get(codename="change_operation") ) + def test_link(self): + c = Client() + op0, op1 = self.operations[0], self.operations[1] + pks = "{}-{}".format(op0.pk, op1.pk) + url = reverse("operation-qa-link", args=[pks]) + + response = c.get(url) + self.assertEqual(response.status_code, 404) + + c.login(username=self.username, password=self.password) + response = c.get(reverse("operation-qa-link", args=[pks])) + + self.assertEqual(response.status_code, 200) + q_link = models.Operation.objects.filter(ishtar_users__pk__isnull=False) + self.assertEqual(q_link.count(), 0) + + response = c.post(url, {"action": "link", "account": self.user.pk}) + self.assertRedirects(response, "/success/") + self.assertEqual(q_link.count(), 2) + + response = c.post(url, {"action": "unlink", "account": self.user.pk}) + self.assertRedirects(response, "/success/") + self.assertEqual(q_link.count(), 0) + def test_lock(self): c = Client() op0, op1 = self.operations[0], self.operations[1] diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py index ba96c64b2..29b68a349 100644 --- a/archaeological_operations/urls.py +++ b/archaeological_operations/urls.py @@ -21,6 +21,7 @@ from django.conf.urls import url from django.urls import path, register_converter from ishtar_common import urls_converters +from ishtar_common.views import QALinkView from ishtar_common.utils import check_permissions from archaeological_operations import views from archaeological_operations import views_api @@ -394,6 +395,12 @@ urlpatterns = [ kwargs={"model": models.Operation}, ), url( + r"^operation-qa-link/(?P<pks>[0-9-]+)?/$", + QALinkView.as_view(), + name="operation-qa-link", + kwargs={"model": models.Operation, "url": "operation-qa-link"}, + ), + url( r"^site-qa-duplicate/(?P<pks>[0-9-]+)?/$", check_permissions( ["archaeological_operations.change_archaeologicalsite", @@ -408,6 +415,12 @@ urlpatterns = [ kwargs={"model": models.ArchaeologicalSite}, ), url( + r"^site-qa-link/(?P<pks>[0-9-]+)?/$", + QALinkView.as_view(), + name="site-qa-link", + kwargs={"model": models.ArchaeologicalSite, "url": "site-qa-link"}, + ), + url( r"^site-qa-bulk-update/(?P<pks>[0-9-]+)?/$", check_permissions( ["archaeological_operations.change_archaeologicalsite", |