Skip to content

Commit 5083a2e

Browse files
Updates based on code review feedback
- The name of a variable in the Term model test suite has been updated to hopefully be clearer about its use. - The confirmation workflow is now restrictd to already-categorized terms for non-admin users. Admins will still have an ability to load all terms for this workflow, but as noted this is not the smoothest workflow yet. Side note: the restriction being enacted here is on the ability to load the _index_ in a specific state, but the actual confirmation form is not affected. A non-admin user who understands the URL structure will be able to guess the right URL for a given term (or pick one randomly), and submit a confirmation for a term that has not been categorized. I believe this is an acceptable risk, as the impact of such a user is that we'd have some extra confirmation records in the system - which are useful only for adjusting future operations, so I struggle to think of a downside to having some extras.
1 parent 9dc1a31 commit 5083a2e

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

app/controllers/term_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TermController < ApplicationController
88
# confirmed.
99
def unconfirmed
1010
terms = if params[:show] == 'all'
11+
authorize! :confirm_uncategorized, Term
1112
Term.user_unconfirmed
1213
else
1314
Term.categorized.user_unconfirmed

app/models/ability.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def initialize(user)
4040
# Rules for admins
4141
return unless user.admin?
4242

43+
can :confirm_uncategorized, Term
4344
can :manage, :all
4445
end
4546
end

app/views/term/unconfirmed.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
<p>The terms listed here have not yet been reviewed by a person and placed into a category. Clicking on any term will
44
take you to the form for submitting this information.</p>
55

6+
<% if can? :confirm_uncategorized, Term %>
67
<p class="wrap-filters">View:
78
<a class="btn button-small button-secondary" href="<%= terms_unconfirmed_path %>">Categorized terms</a>
89
<a class="btn button-small button-secondary" href="<%= terms_unconfirmed_path(show: 'all') %>">All terms</a>
910
</p>
11+
<% end %>
1012

1113
<p><%== pagy_info(@pagy) %></p>
1214

test/controllers/term_controller_test.rb

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,41 @@ class TermControllerTest < ActionDispatch::IntegrationTest
2626
assert_response :success
2727
end
2828

29-
test 'confirmation index can show two different sets of terms' do
29+
test 'basic users see only one confirmation option' do
3030
sign_in users(:basic)
3131
get terms_unconfirmed_path
3232

33+
assert_select 'p.wrap-filters', text: "View:\n Categorized terms\n All terms", count: 0
34+
end
35+
36+
test 'admin users see two confirmation options' do
37+
sign_in users(:admin)
38+
get terms_unconfirmed_path
39+
40+
assert_select 'p.wrap-filters', text: "View:\n Categorized terms\n All terms", count: 1
41+
end
42+
43+
test 'basic users cannot access the confirmation option for uncategorized terms' do
44+
sign_in users(:basic)
45+
get terms_unconfirmed_path(show: 'all')
46+
47+
assert_redirected_to '/'
48+
follow_redirect!
49+
50+
assert_select 'div.alert', text: 'Not authorized.', count: 1
51+
end
52+
53+
test 'admin users can access the confirmation option for uncategorized terms' do
54+
sign_in users(:admin)
55+
get terms_unconfirmed_path(show: 'all')
56+
57+
assert_response :success
58+
end
59+
60+
test 'confirmation index can show two different sets of terms for admin users' do
61+
sign_in users(:admin)
62+
get terms_unconfirmed_path
63+
3364
# default_pagy will be something like "Displaying 10 items"
3465
default_pagy = response.parsed_body.xpath('//main//span').first.text
3566
default_pagy_count = default_pagy.split.second.to_i

test/models/term_test.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,10 @@ class TermTest < ActiveSupport::TestCase
306306
test 'categorized scope accounts for terms with multiple categorizations' do
307307
categorized_count = Term.categorized.count
308308
t = terms('doi')
309-
310-
term_category_count = t.categorizations.count
309+
orig_categorization_count = t.categorizations.count
311310

312311
# term has been categorized already
313-
assert_operator 1, :<=, term_category_count
312+
assert_operator 1, :<=, orig_categorization_count
314313

315314
new_record = {
316315
term: t,
@@ -321,7 +320,7 @@ class TermTest < ActiveSupport::TestCase
321320
Categorization.create!(new_record)
322321

323322
# The term has gained a category, but the categorized scope has not changed size.
324-
assert_operator term_category_count, :<, t.categorizations.count
323+
assert_operator orig_categorization_count, :<, t.categorizations.count
325324
assert_equal categorized_count, Term.categorized.count
326325
end
327326

0 commit comments

Comments
 (0)