Skip to content

Commit 18a4f6e

Browse files
committed
Fix "Add source" button no longer showing
1 parent 1fb43f9 commit 18a4f6e

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

app/views/content_providers/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<% end %>
7272
<% if policy(@content_provider).update? && TeSS::Config.feature['sources'] %>
7373
<div id="sources" class="tab-pane fade<%= ' in active' if activator.check_pane('sources') %>">
74-
<% if policy(Source).new? %>
74+
<% if policy(@content_provider).create_source? %>
7575
<div class="my-3">
7676
<%= link_to new_content_provider_source_path(@content_provider), class: 'btn btn-primary' do %>
7777
<i class="fa fa-plus-square"></i> Add source

test/controllers/content_providers_controller_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,27 @@ class ContentProvidersControllerTest < ActionController::TestCase
608608
assert_select '.masonry-brick-heading h4', text: 'Learn about plants'
609609
end
610610
end
611+
612+
test 'user should see new source button for their content provider' do
613+
sign_in users(:regular_user)
614+
get :show, params: { id: @content_provider }
615+
assert_response :success
616+
assert_select 'a.btn[href=?]', new_content_provider_source_path(@content_provider), text: 'Add source'
617+
end
618+
619+
test 'user should not see new source button if user creation feature disabled' do
620+
with_settings(feature: { user_source_creation: false }) do
621+
sign_in users(:regular_user)
622+
get :show, params: { id: @content_provider }
623+
assert_response :success
624+
assert_select 'a.btn[href=?]', new_content_provider_source_path(@content_provider), text: 'Add source', count: 0
625+
end
626+
end
627+
628+
test 'unaffiliated user should not see new source button' do
629+
sign_in users(:another_regular_user)
630+
get :show, params: { id: @content_provider }
631+
assert_response :success
632+
assert_select 'a.btn[href=?]', new_content_provider_source_path(@content_provider), text: 'Add source', count: 0
633+
end
611634
end

0 commit comments

Comments
 (0)