Skip to content

Commit 55ddb39

Browse files
Merge pull request #133 from MITLibraries/user-categorization
Simple confirmation workflow
2 parents f2d7558 + 5598293 commit 55ddb39

26 files changed

+695
-16
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ gem 'omniauth'
3737
gem 'omniauth_openid_connect'
3838
gem 'omniauth-rails_csrf_protection'
3939

40+
# Pagy used for pagination on long lists of records
41+
gem 'pagy', '~> 9.1'
42+
4043
# Parser added explicitly to allow for the namespace to be available for scout
4144
gem 'parser'
4245

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ GEM
277277
validate_url
278278
webfinger (~> 2.0)
279279
orm_adapter (0.5.0)
280+
pagy (9.1.1)
280281
parallel (1.26.2)
281282
parser (3.3.4.2)
282283
ast (~> 2.4.1)
@@ -490,6 +491,7 @@ DEPENDENCIES
490491
omniauth
491492
omniauth-rails_csrf_protection
492493
omniauth_openid_connect
494+
pagy (~> 9.1)
493495
parser
494496
pg
495497
puma (>= 5.0)

app/controllers/term_controller.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
class TermController < ApplicationController
4+
include Pagy::Backend
5+
6+
def confirm_index
7+
@pagy, @records = pagy(Term.user_unconfirmed)
8+
end
9+
10+
def confirm_term
11+
@term = Term.find(params[:id])
12+
@categories = Category.all
13+
end
14+
end

app/helpers/application_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
22

33
module ApplicationHelper
4+
include Pagy::Frontend
45
end

app/models/ability.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def initialize(user)
2222

2323
# Allow all authenticated users to view reports
2424
can :view, :report
25+
26+
# Create manual confirmation
27+
can :manage, :confirmations
28+
can :manage, Confirmation
2529
# End of Rules for all authenticated user with no additional roles required
2630

2731
# Rules for admins

app/models/category.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ class Category < ApplicationRecord
1414
has_many :detector_categories, dependent: :destroy
1515
has_many :detectors, through: :detector_categories
1616
has_many :categorizations, dependent: :destroy
17+
has_many :confirmations, dependent: :destroy
1718
end

app/models/confirmation.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
# A Confirmation is a "ground truth" record, provided by a person who has
4+
# reviewed a Term record and recommended how TACOS should classify the term
5+
# during the categorization workflow. Most of the time, we anticipate that the
6+
# user will place the term into one of the primary categories. If no category
7+
# seems appropriate, there is an "undefined" option available (which is not
8+
# used by TACOS normally).
9+
#
10+
# There is also a "flag" boolean field available, in case the user feels that
11+
# the term should be reviewed and removed from the dataset entirely. This flag
12+
# is why the category field is not a required value.
13+
#
14+
# == Schema Information
15+
#
16+
# Table name: confirmations
17+
#
18+
# id :integer not null, primary key
19+
# user_id :integer not null
20+
# term_id :integer not null
21+
# category_id :integer
22+
# flag :boolean
23+
# created_at :datetime not null
24+
# updated_at :datetime not null
25+
#
26+
class Confirmation < ApplicationRecord
27+
belongs_to :user
28+
belongs_to :term
29+
belongs_to :category, optional: true
30+
end

app/models/term.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class Term < ApplicationRecord
1616
has_many :search_events, dependent: :destroy
1717
has_many :detections, dependent: :destroy
1818
has_many :categorizations, dependent: :destroy
19+
has_many :confirmations, dependent: :destroy
20+
21+
scope :user_confirmed, -> { where.associated(:confirmations).distinct }
22+
scope :user_unconfirmed, -> { where.missing(:confirmations).distinct }
1923

2024
# The record_detections method is the one-stop method to call every Detector's record method that is defined within
2125
# the application.

app/models/user.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# admin :boolean default(FALSE)
1313
#
1414
class User < ApplicationRecord
15+
has_many :confirmations, dependent: :destroy
16+
1517
include FakeAuthConfig
1618

1719
if FakeAuthConfig.fake_auth_enabled?

app/views/layouts/_site_nav.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<nav class="local-nav" aria-label="Main menu">
1111
<%= nav_link_to("Home", root_path) %>
1212
<% if user_signed_in? %>
13+
<% if can? :manage, Confirmation %>
14+
<%= link_to('Confirm terms', confirm_index_path, class: 'nav-item') %>
15+
<% end %>
1316
<% if can? :index, Term %>
1417
<%= link_to('Admin', admin_root_path, class: 'nav-item') %>
1518
<% end %>

0 commit comments

Comments
 (0)