-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
@group_required
in workflow history view re #10658
- Loading branch information
1 parent
3e4a9c2
commit 4c7a463
Showing
2 changed files
with
23 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import uuid | ||
import datetime | ||
|
||
from django.contrib.auth.models import User | ||
from django.contrib.auth.models import Group, User | ||
from django.urls import reverse | ||
from django.test.client import Client | ||
|
||
|
@@ -15,6 +15,9 @@ def setUpClass(cls): | |
cls.client = Client() | ||
cls.admin = User.objects.get(username="admin") | ||
cls.anonymous = User.objects.get(username="anonymous") | ||
cls.editor = User.objects.create_user(username="sam", email="[email protected]", password="Test12345!") | ||
group = Group.objects.get(name="Resource Editor") | ||
group.user_set.add(cls.editor) | ||
super().setUpClass() | ||
|
||
def setUp(self): | ||
|
@@ -73,7 +76,7 @@ def test_get_workflow_history(self): | |
response = self.client.get(reverse("workflow_history", kwargs={"workflowid": str(self.history.workflowid)})) | ||
|
||
self.assertEqual(response.status_code, 403) | ||
self.assertIn(b"Permission Denied", response.content) | ||
self.assertIn(b"Forbidden", response.content) | ||
|
||
self.client.force_login(self.admin) | ||
response = self.client.get(reverse("workflow_history", kwargs={"workflowid": str(self.history.workflowid)})) | ||
|
@@ -83,13 +86,6 @@ def test_get_workflow_history(self): | |
|
||
def test_post_workflow_history(self): | ||
"""Partial updates of componentdata and stepdata are allowed.""" | ||
self.client.force_login(self.anonymous) | ||
response = self.client.post(reverse("workflow_history", kwargs={"workflowid": str(self.history.workflowid)})) | ||
|
||
self.assertEqual(response.status_code, 403) | ||
self.assertIn(b"Permission Denied", response.content) | ||
|
||
self.client.force_login(self.admin) | ||
post_data = { | ||
"workflowid": str(self.history.workflowid), # required | ||
"workflowname": 'test-name', | ||
|
@@ -128,6 +124,18 @@ def test_post_workflow_history(self): | |
}, | ||
} | ||
|
||
# Non-superuser cannot update someone else's workflow. | ||
self.client.force_login(self.editor) | ||
response = self.client.post( | ||
reverse("workflow_history", kwargs={"workflowid": str(self.history.workflowid)}), | ||
post_data, | ||
content_type="application/json", | ||
) | ||
|
||
self.assertEqual(response.status_code, 403) | ||
self.assertIn(b"Forbidden", response.content) | ||
|
||
self.client.force_login(self.admin) | ||
response = self.client.post( | ||
reverse("workflow_history", kwargs={"workflowid": str(self.history.workflowid)}), | ||
post_data, | ||
|