Skip to content

Commit 0780f12

Browse files
authored
creds-notes-fixes Some updates to creds/cred-related notes: Show "Add Note" button on cred notes page; show delete note button for note creator and fix note deletion; fix "Associated Products" header to have less spacing around it; fix credential deletion (#10644)
1 parent 522a192 commit 0780f12

3 files changed

Lines changed: 61 additions & 57 deletions

File tree

dojo/cred/views.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def view_cred_details(request, ttid):
112112
'cred': cred,
113113
'form': form,
114114
'notes': notes,
115-
'cred_products': cred_products
115+
'cred_products': cred_products,
116+
'person': request.user.username,
116117
})
117118

118119

@@ -650,7 +651,7 @@ def delete_cred_controller(request, destination_url, id, ttid):
650651
if id:
651652
product = None
652653
if destination_url == "all_cred_product":
653-
product = get_object_or_404(Product, id)
654+
product = get_object_or_404(Product, id=id)
654655
elif destination_url == "view_engagement":
655656
engagement = get_object_or_404(Engagement, id=id)
656657
product = engagement.product
@@ -669,7 +670,7 @@ def delete_cred_controller(request, destination_url, id, ttid):
669670

670671
@user_is_authorized(Cred_User, Permissions.Credential_Delete, 'ttid')
671672
def delete_cred(request, ttid):
672-
return delete_cred_controller(request, "cred", 0, ttid)
673+
return delete_cred_controller(request, "cred", 0, ttid=ttid)
673674

674675

675676
@user_is_authorized(Product, Permissions.Product_Edit, 'pid')

dojo/notes/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# Local application/library imports
1717
from dojo.forms import DeleteNoteForm, NoteForm, TypedNoteForm
18-
from dojo.models import Engagement, Finding, Note_Type, NoteHistory, Notes, Test
18+
from dojo.models import Cred_User, Engagement, Finding, Note_Type, NoteHistory, Notes, Test
1919

2020
logger = logging.getLogger(__name__)
2121

@@ -37,6 +37,11 @@ def delete_note(request, id, page, objid):
3737
object = get_object_or_404(Finding, id=objid)
3838
object_id = object.id
3939
reverse_url = "view_finding"
40+
elif page == "cred":
41+
object = get_object_or_404(Cred_User, id=objid)
42+
object_id = object.id
43+
reverse_url = "view_cred_details"
44+
4045
form = DeleteNoteForm(request.POST, instance=note)
4146

4247
if page is None:
@@ -53,7 +58,7 @@ def delete_note(request, id, page, objid):
5358
else:
5459
messages.add_message(request,
5560
messages.SUCCESS,
56-
_('Note was not succesfully deleted.'),
61+
_('Note was not successfully deleted.'),
5762
extra_tags='alert-danger')
5863

5964
return HttpResponseRedirect(reverse(reverse_url, args=(object_id, )))

dojo/templates/dojo/view_cred_details.html

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ <h4>Login Details</h4>
9999

100100
<div class="panel panel-default">
101101
<div class="panel-heading">
102-
<div class="clearfix">
103-
<div class="panel-heading">
104-
<h4>Associated Products</h4>
105-
</div>
106-
</div>
102+
<h4>Associated Products</h4>
107103
</div>
108104
<div class="table-responsive">
109105
{% if cred_products %}
@@ -142,56 +138,58 @@ <h4>Associated Products</h4>
142138
<div class="panel-heading">
143139
<h3>Notes</h3>
144140
</div>
145-
{% if notes %}
146-
<table id="notes" class="table-striped table table-condensed table-hover">
147-
<thead>
148-
<tr>
149-
<th>User</th>
150-
<th>Date</th>
151-
<th>Note</th>
152-
</tr>
153-
</thead>
154-
<tbody>
155-
{% for note in notes %}
141+
<div class="panel-body">
142+
{% if notes %}
143+
<table id="notes" class="table-striped table table-condensed table-hover">
144+
<thead>
156145
<tr>
157-
<td>
158-
{{ note.author.username }}
159-
</td>
160-
<td>
161-
{{ note.date }}
162-
</td>
163-
<td>
164-
{{ note }}
165-
{% if person == note.author.username %}
166-
<a href="{% url 'delete_test_note' test.id note.id %}" class="btn btn-danger btn-xs"
167-
title="Delete">
168-
<i class="fa-solid fa-trash" aria-hidden="true"></i>
169-
</a>
170-
{% endif %}
171-
</td>
146+
<th>User</th>
147+
<th>Date</th>
148+
<th>Note</th>
172149
</tr>
173-
{% endfor %}
174-
175-
</tbody>
176-
</table>
177-
{% else %}
178-
179-
<p class="text-center">No notes found.</p>
180-
{% endif %}
181-
<hr/>
182-
183-
<form class="form-horizontal" id="add_notes" action="{% url 'view_cred_details' cred.id %}"
184-
method="post">{% csrf_token %}
185-
{% include "dojo/form_fields.html" with form=form %}
186-
<div class="form-group">
187-
<div class="col-sm-offset-2 col-sm-10">
188-
<input class="btn btn-primary" type="submit" value="Add Note"/>
189-
150+
</thead>
151+
<tbody>
152+
{% for note in notes %}
153+
<tr>
154+
<td>
155+
{{ note.author.username }}
156+
</td>
157+
<td>
158+
{{ note.date }}
159+
</td>
160+
<td>
161+
{{ note }}
162+
{% if person == note.author.username %}
163+
<div class="pull-right">
164+
<form method="post" action="{% url 'delete_note' note.id 'cred' cred.id %}">
165+
{% csrf_token %}
166+
<input type="hidden" aria-label="id" name="id" value="{{note.id}}"
167+
id="id_id" />
168+
<button type="submit" aria-label="Delete Note" class="btn-delete">
169+
<i class="fa-solid fa-trash"></i>
170+
</button>
171+
</form>
172+
</div>
173+
{% endif %}
174+
</td>
175+
</tr>
176+
{% endfor %}
177+
</tbody>
178+
</table>
179+
{% else %}
180+
<p class="text-center">No notes found.</p>
181+
{% endif %}
182+
<hr/>
183+
<form class="form-horizontal" id="add_notes" action="{% url 'view_cred_details' cred.id %}"
184+
method="post">{% csrf_token %}
185+
{% include "dojo/form_fields.html" with form=form %}
186+
<div class="form-group">
187+
<div class="col-sm-offset-2 col-sm-10">
188+
<input class="btn btn-secondary" type="submit" value="Add Note"/>
189+
</div>
190190
</div>
191-
</div>
192-
</form>
193-
<br/>
194-
<br/>
191+
</form>
192+
</div>
195193
</div>
196194
{% endblock %}
197195

0 commit comments

Comments
 (0)