Skip to content

Commit

Permalink
feat: moved add comment page into modal on analysis page
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke committed Dec 13, 2024
1 parent 058e49f commit 6ebd1e3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 88 deletions.
9 changes: 0 additions & 9 deletions src/test/unit/web_interface/test_app_add_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ def add_comment_to_object(_, comment, author, time):

@pytest.mark.WebInterfaceUnitTestConfig(database_mock_class=DbMock)
class TestAppAddComment:
def test_app_add_comment_get_not_in_db(self, test_client):
rv = test_client.get('/comment/abc_123')
assert b'Error: UID not found in database' in rv.data

def test_app_add_comment_get_valid_uid(self, test_client):
rv = test_client.get(f'/comment/{TEST_FW.uid}')
assert b'Error: UID not found in database' not in rv.data
assert b'Add Comment' in rv.data

def test_app_add_comment_put(self, test_client):
data = {'comment': 'this is the test comment', 'author': 'test author'}
rv = test_client.post(
Expand Down
6 changes: 0 additions & 6 deletions src/web_interface/components/miscellaneous_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ def post_comment(self, uid):
self.db.editing.add_comment_to_object(uid, comment, author, round(time()))
return redirect(url_for('show_analysis', uid=uid))

@roles_accepted(*PRIVILEGES['comment'])
@AppRoute('/comment/<uid>', GET)
def show_add_comment(self, uid):
error = not self.db.frontend.exists(uid)
return render_template('add_comment.html', uid=uid, error=error)

@roles_accepted(*PRIVILEGES['delete'])
@AppRoute('/admin/delete_comment/<uid>/<timestamp>', GET)
def delete_comment(self, uid, timestamp):
Expand Down
68 changes: 0 additions & 68 deletions src/web_interface/templates/add_comment.html

This file was deleted.

59 changes: 54 additions & 5 deletions src/web_interface/templates/show_analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,10 @@ <h5 class="modal-title">Add analysis to file</h5>
<th>
Comments
{# Add Comment Button #}
<form action="/comment/{{ firmware.uid }}" style="float: right; margin-right: 5px;">
<button class="btn btn-primary btn-sm" type="submit">
<i class="far fa-edit"></i> add comment
</button>
</form>
<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#addCommentModal"
style="float: right;">
<i class="far fa-edit"></i> add comment
</button>

{# Show Comments Button #}
<form onsubmit="return false;" style="float: right; margin-right: 5px;">
Expand Down Expand Up @@ -437,6 +436,56 @@ <h5 class="modal-title">Add analysis to file</h5>

</div>

<!-- Add Comment Modal -->
<div class="modal fade" id="addCommentModal" data-backdrop="static" data-keyboard="false" tabindex="-1"
aria-labelledby="addCommentLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addCommentLabel">Add a Comment</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form class="form-horizontal" id="addCommentForm" action="/comment/{{ uid }}" method=post enctype=multipart/form-data>

<div class="form-group row">
<label class="control-label col-sm-2" for="comment" style="margin-top: 6px;">
Comment:
</label>
<div class="col-xs-12 col-sm-10">
<textarea name="comment" rows="5" style="resize: vertical; position: relative; z-index: 1;" required autofocus class="form-control" id="comment"></textarea>
</div>
</div>

<div class="form-group row">
<label class="control-label col-sm-2" for="author" style="margin-top: 6px;">
Author:
</label>
<div class="col-xs-12 col-sm-10">
<input type="text" name="author" class="form-control" id="author" required
style="position: relative; z-index: 1;" value="anonymous">
</div>
</div>

{% if current_user.is_authenticated %}
<script type="text/javascript">
document.getElementById('author').value = '{{ current_user.email }}';
document.getElementById('author').setAttribute("readonly", true);
</script>
{% endif %}
</form>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" form="addCommentForm">Add Comment</button>
</div>
</div>
</div>
</div>

<script>
function radare_view() {
let radare_form = document.createElement('form');
Expand Down

0 comments on commit 6ebd1e3

Please sign in to comment.