Skip to content

Commit

Permalink
Creates basic read-only validation UI
Browse files Browse the repository at this point in the history
** 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
matt-bernhardt committed Oct 23, 2024
1 parent 0467d40 commit 3f5811d
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/controllers/validation_controller.rb
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
4 changes: 4 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def initialize(user)

# Allow all authenticated users to view reports
can :view, :report

# Allow all authenticted users to perform validation work
can :manage, :validation
can :manage, Validation
# End of Rules for all authenticated user with no additional roles required

# Rules for admins
Expand Down
3 changes: 3 additions & 0 deletions app/views/layouts/_site_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<% if can? :index, Term %>
<%= link_to('Admin', admin_root_path, class: 'nav-item') %>
<% end %>
<% if can? :index, Validation %>
<%= link_to('Validate', validate_path, class: 'nav-item') %>
<% end %>
<% if can? :view, :playground %>
<%= link_to('Playground', '/playground', class: 'nav-item') %>
<% end %>
Expand Down
23 changes: 23 additions & 0 deletions app/views/validation/index.html.erb
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>
63 changes: 63 additions & 0 deletions app/views/validation/term.html.erb
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 %>
&nbsp;
<% 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 %>
&nbsp;
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
get '/report', to: 'report#index'
get '/report/algorithm_metrics', to: 'report#algorithm_metrics'

# Validation interface
get '/validate', to: 'validation#index'
get '/validate/:id', to: 'validation#term', as: 'validate_term'

# Defines the root path route ("/")
root to: 'static#index'
end
88 changes: 88 additions & 0 deletions test/controllers/validation_controller_test.rb
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

0 comments on commit 3f5811d

Please sign in to comment.