Skip to content

Commit

Permalink
Generate list of email addresses of current site administrators, exhi…
Browse files Browse the repository at this point in the history
…bit administrators, and exhibit curators. Fixes #1472
  • Loading branch information
mjgiarlo committed Aug 3, 2016
1 parent 617f9e9 commit 19294f2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/javascripts/spotlight/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
//= require bootstrap/carousel
//= require bootstrap-tagsinput
//= require jquery.serializejson
//= require clipboard

//= require_tree .
9 changes: 9 additions & 0 deletions app/assets/javascripts/spotlight/copy_email_addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(function($) {
$.fn.copyEmailAddresses = function( options ) {
var clip = new Clipboard('.copy-email-addresses');
};
})( jQuery );

Spotlight.onLoad(function() {
$('.copy-email-addresses').copyEmailAddresses();
});
2 changes: 2 additions & 0 deletions app/models/concerns/spotlight/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module User
has_many :roles, class_name: 'Spotlight::Role', dependent: :destroy
has_many :exhibits, class_name: 'Spotlight::Exhibit', through: :roles, source: 'resource', source_type: 'Spotlight::Exhibit'

scope :with_roles, -> { where(id: Spotlight::Role.uniq.pluck(:user_id)) }

before_create :add_default_roles
end

Expand Down
10 changes: 10 additions & 0 deletions app/views/spotlight/admin_users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
</div>
</div>
<% end %>

<p class="instructions"><%= t :'.all_users' %></p>
<div id="all_users" class="well well-sm">
<div class='btn-toolbar pull-right'>
<button class="btn btn-xs btn-default copy-email-addresses" data-clipboard-target="#all_users">
Copy
</button>
</div>
<%= Spotlight::Engine.user_class.with_roles.pluck(:email).sort.join(', ') %>
</div>
</div>

<aside class="col-md-3">
Expand Down
1 change: 1 addition & 0 deletions blacklight-spotlight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ these collections.)
s.add_dependency 'oauth2'
s.add_dependency 'paper_trail', '~> 5.0'
s.add_dependency 'openseadragon'
s.add_dependency 'clipboard-rails', '~> 1.5'

s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rspec-rails', '~> 3.1'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/spotlight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ en:
section: Manage exhibits
page_title: Manage administrators
instructions: Existing exhibits administrators
all_users: Administrators and curators of all exhibits
copy: Copy
add: Add new administrator
destroy: Remove from role
save: Add role
Expand Down
1 change: 1 addition & 0 deletions lib/spotlight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'friendly_id'
require 'tophat'
require 'paper_trail'
require 'clipboard/rails'

module Spotlight
##
Expand Down
14 changes: 13 additions & 1 deletion spec/features/site_admin_management_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
describe 'Site admin management', js: true do
let(:user) { FactoryGirl.create(:site_admin) }
let(:existing_user) { FactoryGirl.create(:exhibit_visitor) }
let!(:existing_user) { FactoryGirl.create(:exhibit_visitor) }
let!(:exhibit_admin) { FactoryGirl.create(:exhibit_admin) }
let!(:exhibit_curator) { FactoryGirl.create(:exhibit_curator) }

before do
login_as(user)
Expand All @@ -11,6 +13,16 @@
expect(page).to have_css('td', text: user.email)
end

describe 'copy email addresses' do
it 'displays only email addresses of users w/ roles' do
expect(page).to have_css('div#all_users', text: user.email)
expect(page).to have_css('div#all_users', text: exhibit_admin.email)
expect(page).to have_css('div#all_users', text: exhibit_curator.email)
expect(page).not_to have_css('div#all_users', text: existing_user.email)
expect(page).to have_css('button.copy-email-addresses')
end
end

it 'allows for existing users to be added as site adminstrators' do
expect(page).not_to have_css('td', text: existing_user.email)
click_link 'Add new administrator'
Expand Down

0 comments on commit 19294f2

Please sign in to comment.