From 333d629c2fd7fff867631d76568e95556322318e Mon Sep 17 00:00:00 2001
From: ViolanteCodes
Date: Tue, 19 Jan 2021 15:18:36 -0500
Subject: [PATCH 1/9] added test_moderator_view_GET_account_approver
---
anonticket/tests.py | 40 ++++++++++++++++++++++++++++++++++++++--
db.sqlite3 | Bin 208896 -> 208896 bytes
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/anonticket/tests.py b/anonticket/tests.py
index b9595ef..cdf0875 100644
--- a/anonticket/tests.py
+++ b/anonticket/tests.py
@@ -11,6 +11,8 @@ from anonticket.forms import (
Anonymous_Ticket_Base_Search_Form,
Anonymous_Ticket_Project_Search_Form,
CreateIssueForm)
+import pprint
+pp = pprint.PrettyPrinter(indent=4)
# Create your tests here.
@@ -655,8 +657,11 @@ class TestModeratorViews(TestCase):
# will allow test group permissions to exactly match those from file.
from anonticket.management.commands.create_groups import GROUPS
from anonticket.management.commands.create_groups import Command as create_groups
+ # Add a bad permission call so that you can test this part of the code.
+ GROUPS["Account Approvers"]["user identifier"].append("smash")
create_groups.handle(create_groups)
self.Moderators = Group.objects.get(name="Moderators")
+ self.AccountApprovers = Group.objects.get(name="Account Approvers")
# Set up users to test the staff decorator and is_mod decorator.
UserStaffNoGroup = User.objects.create(
@@ -682,6 +687,14 @@ class TestModeratorViews(TestCase):
self.UserGroupAndStaff = UserGroupAndStaff
self.Moderators.user_set.add(UserGroupAndStaff)
+ UserAccountApprover = User.objects.create(
+ username='UserAccountApprover',
+ password='IAmATestPassword',
+ is_staff=True,
+ )
+ self.UserAccountApprover = UserAccountApprover
+ self.AccountApprovers.user_set.add(UserAccountApprover)
+
# set the login redirect url for views testing
from anonticket.views import login_redirect_url as login_redirect_url
self.login_redirect_url = login_redirect_url
@@ -711,7 +724,15 @@ class TestModeratorViews(TestCase):
self.assertEqual(self.UserGroupAndStaff.username, "UserGroupAndStaff")
self.assertTrue(self.UserGroupAndStaff.is_staff)
self.assertTrue(self.UserGroupAndStaff.groups.filter(name="Moderators").exists())
-
+
+ def test_user_account_approver_created_successfully(self):
+ """Tese that the username exists, that the user is staff, and that
+ the user is part of the Account Approvers group."""
+ self.assertEqual(self.UserAccountApprover.username, "UserAccountApprover")
+ self.assertTrue(self.UserAccountApprover.is_staff)
+ self.assertTrue(
+ self.UserAccountApprover.groups.filter(name="Account Approvers").exists())
+
def test_moderator_view_GET_not_logged_in(self):
"""Test that the moderator view redirects to a login form
if there is no logged in user."""
@@ -741,7 +762,22 @@ class TestModeratorViews(TestCase):
url = reverse('moderator')
response = self.client.get(url)
self.assertTemplateNotUsed(response, 'anonticket/moderator.html')
- # print(response)
+
+ def test_moderator_view_GET_account_approver(self):
+ """Test that the moderator view loads if a user is an account
+ approver."""
+ current_user = self.UserAccountApprover
+ self.client.force_login(current_user)
+ url = reverse('moderator')
+ response = self.client.get(url)
+ self.assertEqual(response.status_code, 200)
+ # Assert that the correct template loaded
+ self.assertTemplateUsed(response, 'anonticket/moderator.html')
+ # But that users in Account Approvers Group and not in Moderators
+ # Group do not have access to pending issues.
+ self.assertInHTML(
+ "You do not have permission to view pending issues at this time.",
+ 'You do not have permission to view pending issues at this time.
')
def test_moderator_view_GET_valid_moderator(self):
"""Test that the moderator view displays correctly if
diff --git a/db.sqlite3 b/db.sqlite3
index 3a4bcceeb353f87fe2eeea03a857b4f39f27b50b..5cce61e0fcd58564b7fb4596e446873147ffbb7a 100644
GIT binary patch
delta 473
zcmaiwy-wRu07hdYBnDE8xd<|V)K*G#uYGNbzlJG!D9zrphGt@AfALQjEGO)dUT|7`Mi4hyn6GQkbkc45%R;2zup>OfqWf-
zIzlymF_y`J|G%An#Yd`~KnK$t~
zFiEC0y`3D{66nSgL9yhj7^ThVaEP!z#hKGO8VAR|+0mJHwad{xh3C$2#$>07nCuS%
zO$RtZUh_~DdI679b;zcS;_#7t!JTFuFvV=&38P74Y&$eMH=uTayL+=y8up>Oi`fvx
zC!NF=)syZl6J67_oTezkmWeG7_s6cJ%c_>P15;`5_s~odxhY_bxDH(yhv)Uoa(5fP
z5(%Ic3#o8`4W=3n{DG-y-yyV*Ymq#en))yy?`G})C={vfD3AKV@V+1*OA4`cXH$3D=;^i
ANB{r;
delta 120
zcmV-;0Ehp8;0%D^43HZEOOYHy0ZXx9zitsYATlvJGc-ChGA=kbI5IIXvoLSeAP4~t
z+W-#R4YRW`AgK)k0VuO^5F`P!+ny-_1OX4+0Jjhz0
Date: Tue, 19 Jan 2021 15:24:12 -0500
Subject: [PATCH 2/9] added get_linked_notes function to views.py and added it
to user_landing_view
---
anonticket/views.py | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/anonticket/views.py b/anonticket/views.py
index ca801cb..a20a6e2 100644
--- a/anonticket/views.py
+++ b/anonticket/views.py
@@ -58,6 +58,11 @@ def get_linked_issues(UserIdentifier):
linked_issues = Issue.objects.filter(linked_user=UserIdentifier)
return linked_issues
+def get_linked_notes(UserIdentifier):
+ """Gets a list of the notes assigned to a User Identifier."""
+ linked_notes = Note.objects.filter(linked_user=UserIdentifier)
+ return linked_notes
+
# --------------------DECORATORS AND MIXINS-----------------------------
# Django decorators wrap functions (such as views) in other functions.
# Mixins perform a similar function for class based views.
@@ -209,8 +214,10 @@ def user_landing_view(request, user_identifier):
# results dictionary.
working_user = get_user_as_object(user_identifier)
linked_issues = get_linked_issues(working_user)
- results['linked_issues'] = linked_issues
- # if found or not found, pass 'user_identifier' to context dictionary
+ linked_notes = get_linked_notes(working_user)
+ results['linked_issues'] = linked_issues
+ results['linked_notes'] = linked_notes
+ # whether user found or not found, pass 'user_identifier' to context dictionary
results['user_identifier'] = user_identifier
return render(request, 'anonticket/user_landing.html', {'results': results})
--
GitLab
From 91d596d3d9b022095edc6425ff1f8372e42af4e6 Mon Sep 17 00:00:00 2001
From: ViolanteCodes
Date: Tue, 19 Jan 2021 15:33:32 -0500
Subject: [PATCH 3/9] created a pending_note.html template for
PendingNoteDetailView
---
.../templates/anonticket/note_pending.html | 48 +++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100644 anonticket/templates/anonticket/note_pending.html
diff --git a/anonticket/templates/anonticket/note_pending.html b/anonticket/templates/anonticket/note_pending.html
new file mode 100644
index 0000000..f1eae68
--- /dev/null
+++ b/anonticket/templates/anonticket/note_pending.html
@@ -0,0 +1,48 @@
+{% extends 'shared/layout.html' %}
+{% load static %}
+
+{% load custom_filters %}
+
+{% load markdownify %}
+
+{% block extra_links %}
+ {% include 'shared/extend_sidebar.html' %}
+{% endblock %}
+
+{% block h3 %}
+
+
+
{note.linked_project}}
+
Created by {{note.linked_user.user_identifier}}
+
+
+
+
Milestone: NA, Issue Pending Mod Approval.
+
+
+ Labels: NA, Issue Pending Mod Approval
+
+
+
+
+
Pending{{issue.body|capfirst}}
+
+
+
+
+{% endblock %}
+{% block subheader %}
+ {{note.body|capfirst|markdownify}}
+{% endblock %}
+
+{% block content %}
+
+{% endblock %}
\ No newline at end of file
--
GitLab
From dc9552851739534616f137cef5d1a0e400c97f46 Mon Sep 17 00:00:00 2001
From: ViolanteCodes
Date: Tue, 19 Jan 2021 15:33:47 -0500
Subject: [PATCH 4/9] added a new view PendingNoteDetailView
---
anonticket/views.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/anonticket/views.py b/anonticket/views.py
index a20a6e2..3879a7e 100644
--- a/anonticket/views.py
+++ b/anonticket/views.py
@@ -381,6 +381,11 @@ class NoteCreateView(PassUserIdentifierMixin, CreateView):
working_url = reverse('issue-created', args=[user_identifier_to_pass])
return working_url
+class PendingNoteDetailView(PassUserIdentifierMixin, DetailView):
+ """View For Pending Notes that have not been mod approved."""
+ model = Note
+ template_name = 'anonticket/note_pending.html'
+
# ----------------------MODERATOR_VIEWS---------------------------------
# Views related to moderators. Should all have decorator
# @staff_member_required, which forces staff status and allows access
--
GitLab
From deef998201355a24214b9718c1f40f968f1ee212 Mon Sep 17 00:00:00 2001
From: ViolanteCodes
Date: Tue, 19 Jan 2021 15:33:59 -0500
Subject: [PATCH 5/9] added notes to user_landing page
---
.../templates/anonticket/user_landing.html | 28 +++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/anonticket/templates/anonticket/user_landing.html b/anonticket/templates/anonticket/user_landing.html
index b15e8d9..52eab52 100644
--- a/anonticket/templates/anonticket/user_landing.html
+++ b/anonticket/templates/anonticket/user_landing.html
@@ -83,4 +83,32 @@
{% endif %}
+
+
+
+
+
You have created the following notes:
+
+ {% if results.linked_notes %}
+
(Notes marked with *** have not been approved by moderators and therefore have not been posted to GitLab.)
+
+ {% for note in results.linked_notes %}
+
+ {% if note.gitlab_id %}
+ {% url 'issue-detail-view' results.user_identifier note.linked_project.slug note.issue_iid as issue_url %}
+ - Note: {{note.body}} on {{note.gitlab_issue_title}}
+
+ {% else %}
+ {% url 'pending-issue-detail-view' results.user_identifier issue.linked_project.slug issue.pk as issue_url %}
+ - {{issue.title|capfirst}} ***
+ {% endif %}
+ {% endfor %}
+
+
+ {% else %}
+
+
You have not created any issues.
+ {% endif %}
+
+
{% endblock %}
\ No newline at end of file
--
GitLab
From 898c9d8e3b6059224350abce06b4a09d2b23b7f1 Mon Sep 17 00:00:00 2001
From: ViolanteCodes
Date: Tue, 19 Jan 2021 16:14:41 -0500
Subject: [PATCH 6/9] updated some of the language on the user_landing.html
template
---
.../templates/anonticket/user_landing.html | 48 ++++++++++++-------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/anonticket/templates/anonticket/user_landing.html b/anonticket/templates/anonticket/user_landing.html
index 52eab52..92dd4f3 100644
--- a/anonticket/templates/anonticket/user_landing.html
+++ b/anonticket/templates/anonticket/user_landing.html
@@ -46,11 +46,15 @@
- {% url 'project-list' results.user_identifier as project_list_url %}
- See a list of all projects using this portal.
+ See a list all projects using this portal. Each project links
+ to a detail page with a list of issues.
- {% url 'issue-search' results.user_identifier as search_url %}
- Search for an issue inside of a given project.
+ Search for an issue inside of a given project.
- {% url 'create-issue' results.user_identifier as create_url %}
- Create an issue inside of a given project.
+ Create an issue inside of a given project.
+ - You can also create a note on an issue by searching for the issue first or
+ selecting it from the project page using one of the above methods.
+
@@ -89,25 +93,33 @@
You have created the following notes:
+ {% url 'issue-search' results.user_identifier as search_url %}
+ {% url 'project-list' results.user_identifier as project_list_url%}
+
(To create a new note,
+ search for the issue you want to comment on, or look at the
+ project's detail view to find an issue.
+ Notes marked with *** have not been approved by moderators
+ and therefore have not been posted to GitLab.)
{% if results.linked_notes %}
-
(Notes marked with *** have not been approved by moderators and therefore have not been posted to GitLab.)
-
- {% for note in results.linked_notes %}
-
- {% if note.gitlab_id %}
- {% url 'issue-detail-view' results.user_identifier note.linked_project.slug note.issue_iid as issue_url %}
- - Note: {{note.body}} on {{note.gitlab_issue_title}}
-
- {% else %}
- {% url 'pending-issue-detail-view' results.user_identifier issue.linked_project.slug issue.pk as issue_url %}
- - {{issue.title|capfirst}} ***
- {% endif %}
- {% endfor %}
-
+
+ {% for note in results.linked_notes %}
+
+ {% if note.gitlab_id %}
+ {% url 'issue-detail-view' results.user_identifier note.linked_project.slug note.issue_iid as issue_url %}
+ - Posted on {{note.linked_project.name_with_namespace}} > {{note.gitlab_issue_title}}:
+ "{{note.body|truncatewords:20}}"
+
+ {% else %}
+ {% url 'pending-note' results.user_identifier note.linked_project.slug note.issue_iid note.pk as note_url %}
+ - (Pending) on {{note.linked_project.name_with_namespace}} > {{note.gitlab_issue_title}}:
+ "{{note.body|capfirst|truncatewords:20}}" ***
+ {% endif %}
+ {% endfor %}
+
{% else %}
-
You have not created any issues.
+
You have not created any Notes.
{% endif %}
--
GitLab
From 981da3b2f982d42f93edda1afac0b910595563e5 Mon Sep 17 00:00:00 2001
From: ViolanteCodes
Date: Tue, 19 Jan 2021 16:14:59 -0500
Subject: [PATCH 7/9] Added a url path for the NoteDetailView
---
anonticket/urls.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/anonticket/urls.py b/anonticket/urls.py
index b6b6b1f..4153958 100644
--- a/anonticket/urls.py
+++ b/anonticket/urls.py
@@ -22,6 +22,7 @@ urlpatterns = [
path('user/login/', views.login_view, name='login'),
path('user//login_error/', views.UserLoginErrorView.as_view(), name='user-login-error'),
path('user//projects//issues//notes/create/', views.NoteCreateView.as_view(), name='create-note'),
+ path('user//projects//issues//notes//', views.PendingNoteDetailView.as_view(), name='pending-note'),
path('user//projects//issues//details/', views.issue_detail_view, name='issue-detail-view'),
path('user//projects//issues/pending//', views.PendingIssueDetailView.as_view(), name='pending-issue-detail-view'),
path('user//projects/all/issues/search/', views.issue_search_view, name="issue-search"),
--
GitLab
From 2791c19f6053976c5cacd172aa61acf7cd363371 Mon Sep 17 00:00:00 2001
From: ViolanteCodes
Date: Tue, 19 Jan 2021 16:15:19 -0500
Subject: [PATCH 8/9] updated the note_pending.html template
---
anonticket/templates/anonticket/note_pending.html | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/anonticket/templates/anonticket/note_pending.html b/anonticket/templates/anonticket/note_pending.html
index f1eae68..6531a14 100644
--- a/anonticket/templates/anonticket/note_pending.html
+++ b/anonticket/templates/anonticket/note_pending.html
@@ -12,27 +12,28 @@
{% block h3 %}
-
{note.linked_project}}
+
{{note.linked_project}}
Created by {{note.linked_user.user_identifier}}
-
Milestone: NA, Issue Pending Mod Approval.
+
Milestone: NA, Note Pending Mod Approval.
- Labels: NA, Issue Pending Mod Approval
+ Labels: NA, Note Pending Mod Approval
-
Pending{{issue.body|capfirst}}
+ Pending Noteon Issue: "{{note.gitlab_issue_title|capfirst|truncatewords:20}}"
{% endblock %}
{% block subheader %}
- {{note.body|capfirst|markdownify}}
+ "{{note.body|capfirst|markdownify}}"
+ (***This note is pending moderator approval.)
{% endblock %}
{% block content %}
--
GitLab
From 0c1b2e15bdedde68227a1c362e58b34dc666c1ca Mon Sep 17 00:00:00 2001
From: ViolanteCodes
Date: Tue, 19 Jan 2021 16:15:27 -0500
Subject: [PATCH 9/9] Logged in and out of sqllite
---
db.sqlite3 | Bin 208896 -> 208896 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
diff --git a/db.sqlite3 b/db.sqlite3
index 5cce61e0fcd58564b7fb4596e446873147ffbb7a..75bfc937216c2e59b40d744481ec30d8498ab6a7 100644
GIT binary patch
delta 475
zcmZp8z|-)6XM!|i$V3@u#*mE(ReFrNn{Vsga}cmpFfy<*F|aZ;(=)R)v@qR#GT&B#
zZ5spMZQgC04HZ`MYBDw{F|qnK2Rj;97GxKvMA1^+w#FZ{pwAA!v{!Oz40j)9GVft8t&kx6&^3w@?n`uuS3LoA*CFrG=7
zhn4>h16bb+{x91F5||$Hb3*m;=x+a&&&1Urz{)$1fxn&4ieH3pEAKr1C}3c9@uoFO
z>T)wQnlkfqGBR?OI+m2A<`$G>=A|o?&6QL4PoSeQ!uB1@BNV!OFNVR<&|Ua{Zip&}6YP#DS4N?AlK(wWy>E
zsY-^aRr$;_9HfI|PxAH}c1MBOV+XkdS*+PS_T?t$r>h3s;L<{NkVxQYXe;GnkA(ycl?5_RttMI
zc2trwLzwQ31!SVJb0P$qxs$c3t_bsE(HHk|FP(B4RzvM{?&l2Cl1JLZqS|zADT^7%
zpcG`5P9k1lm+NsfL>O^=IDJEtD>D#