-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates basic read-only validation UI
** Why are these changes being introduced: As part of allowing users to validate the actions taken by TACOS, we need to first create an interface showing what those actions have been. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/tco-8 ** How does this address that need: This commit creates a very basic interface to present what actions have been taken with regard to a single term. There is an index page, which shows all terms that have prompted any activity (not all terms in the system). From this index, the user can click into a display for any given term, which will list all the detectors and categories in the system, with an indication of which detectors activated for that term. The final score for each category is also displayed. There is not yet a form on this page, and the details of the UI need to be more closely considered. This is a starting point, not the end. ** Document any side effects to this change: This may be a side effect, or it may not, but: I've added the manage role for Validations to the basic user, rather than creating a specific role for this work. This is in line with what we've done so far, but I am nervous about relying on basic roles for too much.
- Loading branch information
1 parent
0467d40
commit 3f5811d
Showing
7 changed files
with
198 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class ValidationController < ApplicationController | ||
def index | ||
@terms = Term.joins(:detections).uniq | ||
end | ||
|
||
def term | ||
@term = Term.find(params[:id]) | ||
@detectors = Detector.all | ||
@categories = Category.all | ||
end | ||
end |
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<%= content_for(:title, "TACOS Validation") %> | ||
|
||
<h3>Validation index</h3> | ||
|
||
<p>This would be the page which lists terms - which have tripped a detector and have been categorized - which have not | ||
yet been validated by a user.</p> | ||
|
||
<table class="table table-simplified table-cozy"> | ||
<thead> | ||
<tr> | ||
<th scope="col">ID</th> | ||
<th scope="col">Phrase</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @terms.each do |t| %> | ||
<tr> | ||
<td><%= t.id %></td> | ||
<td><%= link_to(t.phrase, validate_term_path(t) ) %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<%= content_for(:title, "TACOS Validation") %> | ||
|
||
<p><%= link_to('Back to validation index', validate_path) %></p> | ||
|
||
<h3>Validation form</h3> | ||
|
||
<div class="well"> | ||
<p><%= @term.phrase %></p> | ||
</div> | ||
|
||
<p><strong>Please note:</strong> The information below is not currently filtered | ||
for only current detections; all detections across the history of the application | ||
are represented. This will need to be adjusted in the future.</p> | ||
|
||
<h4>Detection result</h4> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Detector</th> | ||
<th scope="col">Result</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @detectors.each do |d| %> | ||
<tr class="detector-result"> | ||
<td><%= d.name %></td> | ||
<td> | ||
<% if @term.detections.pluck(:detector_id).include?(d.id) %> | ||
Detection | ||
<% else %> | ||
| ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<h4>Categorization result</h4> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Category</th> | ||
<th scope="col">Score</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @categories.each do |c| %> | ||
<tr class="category-result"> | ||
<td><%= c.name %></td> | ||
<td> | ||
<% if @term.categorizations.pluck(:category_id).include?(c.id) %> | ||
<%= @term.categorizations.find_by(category_id: c.id).confidence %> | ||
<% else %> | ||
| ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class ValidationControllerTest < ActionDispatch::IntegrationTest | ||
# Access to validation index | ||
test 'validation index is not accessible without authentication' do | ||
get validate_path | ||
|
||
assert_redirected_to '/' | ||
follow_redirect! | ||
|
||
assert_select 'div.alert', text: 'Please sign in to continue', count: 1 | ||
end | ||
|
||
test 'validation index is accessible to users with no special access' do | ||
sign_in users(:basic) | ||
get validate_path | ||
|
||
assert_response :success | ||
end | ||
|
||
test 'validation index is accessible to users with the admin flag set' do | ||
sign_in users(:admin) | ||
get validate_path | ||
|
||
assert_response :success | ||
end | ||
|
||
test 'unauthenticated users do not see a nav link to validation' do | ||
get root_path | ||
|
||
assert_select 'a.nav-item', text: 'Validate', count: 0 | ||
end | ||
|
||
test 'Users with no special access do see a nav link to validation' do | ||
sign_in users(:basic) | ||
get root_path | ||
|
||
assert_select 'a.nav-item', text: 'Validate', count: 1 | ||
end | ||
|
||
test 'Users with the admin flag set do see a nav link to validation' do | ||
sign_in users(:admin) | ||
get root_path | ||
|
||
assert_select 'a.nav-item', text: 'Validate', count: 1 | ||
end | ||
|
||
# Access to validation form | ||
test 'validation form is not accessible without authentication' do | ||
get validate_term_path(terms(:hi)) | ||
|
||
assert_redirected_to '/' | ||
follow_redirect! | ||
|
||
assert_select 'div.alert', text: 'Please sign in to continue', count: 1 | ||
end | ||
|
||
test 'validation form is accessible to users with no special access' do | ||
sign_in users(:basic) | ||
get validate_term_path(terms(:hi)) | ||
|
||
assert_response :success | ||
end | ||
|
||
test 'validation form is accessible to users with the admin flag set' do | ||
sign_in users(:admin) | ||
get validate_term_path(terms(:hi)) | ||
|
||
assert_response :success | ||
end | ||
|
||
# Validation form contents | ||
test 'validation form includes a table row for every detector' do | ||
sign_in users(:basic) | ||
get validate_term_path(terms(:hi)) | ||
|
||
assert_select 'tr.detector-result', count: Detector.count | ||
end | ||
|
||
test 'validation form includes a table row for every category' do | ||
sign_in users(:basic) | ||
get validate_term_path(terms(:hi)) | ||
|
||
assert_select 'tr.category-result', count: Category.count | ||
end | ||
end |