Skip to content

Commit

Permalink
Add visibility template to admin set form. See samvera/hyku#419
Browse files Browse the repository at this point in the history
  • Loading branch information
tdonohue committed Nov 7, 2016
1 parent 66dec00 commit 43660c1
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class PermissionTemplatesController < ApplicationController
def update
authorize! :update, @permission_template
@permission_template.update(update_params)
redirect_to sufia.edit_admin_admin_set_path(params[:admin_set_id], anchor: 'participants'),
# Ensure we redirect to active tab
current_tab = params[:sufia_permission_template][:access_grants_attributes].present? ? 'participants' : 'visibility'
redirect_to sufia.edit_admin_admin_set_path(params[:admin_set_id], anchor: current_tab),
notice: 'Permissions updated'
end

Expand All @@ -19,7 +21,7 @@ def load_template_for_admin_set

def update_params
params.require(:sufia_permission_template)
.permit(access_grants_attributes: [:access, :agent_id, :agent_type, :id])
.permit(:visibility, access_grants_attributes: [:access, :agent_id, :agent_type, :id])
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion app/forms/sufia/forms/permission_template_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ class PermissionTemplateForm
include HydraEditor::Form
self.model_class = PermissionTemplate
self.terms = []
delegate :access_grants, :access_grants_attributes=, to: :model
delegate :access_grants, :access_grants_attributes=, :visibility, to: :model

# Visibility options for permission templates
def visibility_options
i18n_prefix = "sufia.admin.admin_sets.form_visibility"
# Note: Visibility 'varies' = '' as it implies no constraints
[[Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC, I18n.t(i18n_prefix + '.visibility.everyone')],
['', I18n.t(i18n_prefix + '.visibility.varies')],
[Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED, I18n.t(i18n_prefix + '.visibility.institution')],
[Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, I18n.t(i18n_prefix + '.visibility.restricted')]]
end
end
end
end
4 changes: 4 additions & 0 deletions app/views/sufia/admin/admin_sets/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<li>
<a href="#participants"><%= t('.tabs.participants') %></a>
</li>
<li>
<a href="#visibility"><%= t('.tabs.visibility') %></a>
</li>
<% end %>
</ul>
<div class="tab-content">
Expand All @@ -31,6 +34,7 @@
</div>
<% if @form.persisted? %>
<%= render 'form_participants' %>
<%= render 'form_visibility' %>
<% end %>
</div>
</div>
20 changes: 20 additions & 0 deletions app/views/sufia/admin/admin_sets/_form_visibility.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div id="visibility" class="tab-pane">
<div class="panel panel-default labels">
<%= simple_form_for @form.permission_template,
url: [sufia, :admin, @form, :permission_template] do |f| %>
<div class="panel-body">
<p><%= t('.page_description') %></p>
<h3><%= t('.visibility.title') %></h3>
<p><%= t('.visibility.description') %></p>
<ul class="visibility">
<%# List each option as a radio button in a <li class='radio'> tag %>
<%= f.collection_radio_buttons :visibility, f.object.visibility_options, :first, :last, item_wrapper_tag: :li, item_wrapper_class: 'radio' %>
</ul>
</div>
<div class="panel-footer">
<%= link_to 'Cancel', sufia.admin_admin_sets_path, class: 'btn btn-default pull-right'%>
<%= f.button :submit, class: 'btn btn-primary pull-right'%>
</div>
<% end %>
</div>
</div>
10 changes: 10 additions & 0 deletions config/locales/sufia.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ en:
tabs:
description: "Description"
participants: "Participants"
visibility: "Release and Visibility"
form_participants:
add_group: "Add group:"
add_user: "Add user:"
Expand Down Expand Up @@ -339,6 +340,15 @@ en:
type: "Type"
action: "Action"
remove: "Remove"
form_visibility:
page_description: "Release and visibility settings control when works added to this set are made available for discovery and download and who can discover and download them."
visibility:
title: "Visibility"
description: "After its release date, works in this set can be discovered and downloaded by:"
everyone: "Everyone -- all works in this set will be public"
varies: "Varies -- default is public, but depositors can restrict the visibility of individual works"
institution: "Institution -- all works will be visible only to authenticated users of this institution"
restricted: "Restricted -- all works will be visible only to repository managers and managers and reviewers of this administrative set"
show:
header: "Administrative Set"
item_list_header: "Works in This Set"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
end

context "when signed in as an admin" do
describe "update" do
describe "update participants" do
let(:admin_set) { create(:admin_set) }
let!(:permission_template) { Sufia::PermissionTemplate.create!(admin_set_id: admin_set.id) }
let(:input_params) do
Expand All @@ -40,5 +40,24 @@
expect(flash[:notice]).to eq 'Permissions updated'
end
end
describe "update visibility" do
let(:admin_set) { create(:admin_set) }
let!(:permission_template) { Sufia::PermissionTemplate.create!(admin_set_id: admin_set.id) }
let(:input_params) do
{ admin_set_id: admin_set.id,
sufia_permission_template: {
visibility: 'open'
} }
end

it "is successful" do
expect(controller).to receive(:authorize!).with(:update, permission_template)
expect do
put :update, params: input_params
end.to change { permission_template.visibility }.from(nil).to('open')
expect(response).to redirect_to(sufia.edit_admin_admin_set_path(admin_set, anchor: 'visibility'))
expect(flash[:notice]).to eq 'Permissions updated'
end
end
end
end
7 changes: 4 additions & 3 deletions spec/features/admin_admin_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
expect(page).to have_content "Works in This Set"

click_link "Edit"

fill_in "Title", with: 'A better unique name'
click_button 'Save'
within('#description') do
fill_in "Title", with: 'A better unique name'
click_button 'Save'
end
expect(page).to have_content "A better unique name"
end
end

0 comments on commit 43660c1

Please sign in to comment.