blacklight-spotlight 0.27.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14ae1aa0767b7c480a27e35a4a6331075b1f3702
4
- data.tar.gz: dfa1d2438093e6b83410ec483848062973583516
3
+ metadata.gz: 00bc8950c632e97a365418053a379016e111b937
4
+ data.tar.gz: 4eb7a348e011e9e0fc646946b91126a0e017269d
5
5
  SHA512:
6
- metadata.gz: 7af943f098a05fa6f82edc569cf681d9729801506ac917799ea3a09bda594800ed1b7a22db24b5bcdc0e2a2eebd191091b915b35c0aceae2914b241954fa1396
7
- data.tar.gz: f64bf52002e9bf0c3f6ced2c1fac718368a8f6a3bd18916c4a09ffec164212fb4d54e252f06af00dc59fe5da72b930a90956a3ec7395c4e93ed57a7ee8b64cb7
6
+ metadata.gz: 9b6ce0ffe5fe536bbc4b73e845e3ccbe2ae48c01f43789463e6cab7e9454a9eaac5289b7c21da19ec4b66be634440adf1a460d02352c7baafee637c5e2761da3
7
+ data.tar.gz: 4ba852983e8568cc516e0a3e7cabfa7cd15b46c132ddb8d34bbd2fa2fde94625c411c7a76674632f16283f4f95947f6cd1609811450251546de4a7e7b335525a
@@ -35,6 +35,7 @@
35
35
  }
36
36
 
37
37
  .twitter-typeahead {
38
+ z-index: 1000 !important; /* get typeahead to float on top of e.g. jcrop */
38
39
  .tt-suggestion {
39
40
  font-size: 18px;
40
41
  line-height: 24px;
@@ -2,9 +2,6 @@ module Spotlight
2
2
  ##
3
3
  # A controller to handle the adminstration of site admin users
4
4
  class AdminUsersController < Spotlight::ApplicationController
5
- include Spotlight::Concerns::UserExistable
6
- include Spotlight::Concerns::UserInvitable
7
-
8
5
  before_action :authenticate_user!
9
6
  before_action :load_site
10
7
  load_and_authorize_resource :site, class: 'Spotlight::Site'
@@ -42,8 +39,7 @@ module Spotlight
42
39
  end
43
40
 
44
41
  def update_roles
45
- user = Spotlight::Engine.user_class.where(email: create_params[:email]).first
46
- Spotlight::Role.create(user: user, role: 'admin', resource: @site).save
42
+ Spotlight::Role.create(user_key: create_params[:email], role: 'admin', resource: @site).save
47
43
  end
48
44
  end
49
45
  end
@@ -3,8 +3,6 @@ module Spotlight
3
3
  # CRUD actions for assigning exhibit roles to
4
4
  # existing users
5
5
  class RolesController < Spotlight::ApplicationController
6
- include Spotlight::Concerns::UserExistable
7
- include Spotlight::Concerns::UserInvitable
8
6
  before_action :authenticate_user!
9
7
  load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
10
8
  load_and_authorize_resource through: :exhibit, except: [:update_all]
@@ -0,0 +1,19 @@
1
+ module Spotlight
2
+ # Mailer for contacting new exhibit curators or administrators
3
+ class InvitationMailer < ActionMailer::Base
4
+ include Devise::Mailers::Helpers
5
+
6
+ def exhibit_invitation_notification(role)
7
+ initialize_from_record(role.user)
8
+ @role = role
9
+ @key = if @role.resource.is_a?(Spotlight::Site)
10
+ 'exhibits_admin_invitation_mailer'
11
+ else
12
+ 'invitation_mailer'
13
+ end
14
+ mail(to: role.user.email,
15
+ from: mailer_sender(devise_mapping),
16
+ subject: I18n.t("spotlight.#{@key}.invitation_instructions.subject", exhibit_name: @role.resource.title))
17
+ end
18
+ end
19
+ end
@@ -28,7 +28,9 @@ module Spotlight
28
28
  protected
29
29
 
30
30
  def user_must_exist
31
- errors.add(:user_key, 'User must sign up first.') unless user.present?
31
+ return if user.present?
32
+
33
+ self.user ||= Spotlight::Engine.user_class.invite!(email: user_key, skip_invitation: true)
32
34
  end
33
35
 
34
36
  # This is just like
@@ -6,8 +6,7 @@ module Spotlight
6
6
  belongs_to :resource
7
7
  belongs_to :document, required: true, polymorphic: true
8
8
  serialize :data, Hash
9
-
10
- store :data, accessors: [:index_status]
9
+ serialize :index_status, Hash
11
10
 
12
11
  delegate :has_key?, :key?, to: :data
13
12
 
@@ -22,7 +22,7 @@
22
22
  <% end %>
23
23
  <tr data-edit-for='new'>
24
24
  <td>
25
- <%= f.email_field :email, hide_label: true, data: { behavior: 'check-user-existence', 'user-exists-url': spotlight.exists_admin_users_path } %>
25
+ <%= f.email_field :email, hide_label: true %>
26
26
  <span data-user-role='admin'></span>
27
27
  </td>
28
28
  <td>
@@ -36,9 +36,6 @@
36
36
  </tr>
37
37
  <tr data-edit-for='new'>
38
38
  <td colspan='2'>
39
- <span style='display:none' class='help-block' data-behavior='no-user-note'>
40
- <%= t('spotlight.roles.edit_fields.invite_html', link: link_to(t('spotlight.roles.edit_fields.invite_link'), 'javascript:;', data: { method: 'post', 'invite-url': spotlight. invite_admin_users_path })) %>
41
- </span>
42
39
  </td>
43
40
  </tr>
44
41
  </tbody>
@@ -0,0 +1,12 @@
1
+ <p><%= t("spotlight.#{@key}.invitation_instructions.hello", email: @role.user.email) %></p>
2
+
3
+ <p><%= t("spotlight.#{@key}.invitation_instructions.someone_invited_you", role: @role, exhibit_name: @role.resource.title) %></p>
4
+
5
+ <% if @role.user.invite_pending? %>
6
+ <p><%= t("spotlight.#{@key}.invitation_instructions.accept_invitation") %></p>
7
+ <p><%= link_to t("spotlight.#{@key}.invitation_instructions.accept"), accept_invitation_url(@role.user, invitation_token: @role.user.invitation_token) %></p>
8
+ <% elsif @role.resource.is_a? Spotlight::Exhibit %>
9
+ <p><%= link_to t("spotlight.#{@key}.invitation_instructions.visit"), url: spotlight.exhibit_home_page_url(@role.resource) %></p>
10
+ <% end %>
11
+
12
+ <p><%= t("spotlight.#{@key}.invitation_instructions.ignore") %></p>
@@ -1,10 +1,6 @@
1
1
  <tr data-edit-for="<%= f.object.new_record? ? 'new' : f.object.id %>">
2
2
  <td>
3
- <%= f.email_field :user_key, hide_label: true, disabled: f.object.persisted?, data: { behavior: 'check-user-existence' } %>
4
- <span style='display:none' class='help-block' data-behavior='no-user-note'>
5
- <%= t('.invite_html', link: link_to(t('.invite_link'), spotlight.invite_exhibit_roles_path(current_exhibit), data: { method: 'post', 'invite-url' => spotlight.invite_exhibit_roles_path(current_exhibit) })) %>
6
- <span class='label label-warning pending-label'><%= t('.pending') %></span>
7
- </span>
3
+ <%= f.email_field :user_key, hide_label: true, disabled: f.object.persisted? %>
8
4
  </td>
9
5
  <td><%= f.select :role, roles_for_select, hide_label: true %></td>
10
6
  <td></td>
@@ -1,5 +1,5 @@
1
1
  <%= render 'spotlight/shared/exhibit_sidebar' %>
2
- <div id="content" class="col-md-9" data-user-exists-url="<%= spotlight.exists_exhibit_roles_path(current_exhibit) %>">
2
+ <div id="content" class="col-md-9">
3
3
  <%= configuration_page_title %>
4
4
  <%= bootstrap_form_for current_exhibit, url: spotlight.update_all_exhibit_roles_path(current_exhibit) do |f| %>
5
5
  <table class="table table-striped users">
@@ -301,16 +301,21 @@ en:
301
301
  error: 'An error occured while reindexing. Contact your exhibits administrator for more information.'
302
302
  invitation_mailer:
303
303
  invitation_instructions:
304
+ subject: 'Invitation to manage \"%{exhibit_name}\"'
304
305
  hello: "Hello!"
305
- someone_invited_you: "The Exhibits Administrator has invited you to help work on the \"%{exhibit_name}\" exhibit. You can accept this invitation by clicking the link below."
306
- accept: "Accept invitation"
307
- ignore_html: "If you don't want to accept the invitation, please ignore this email. Your account won't be created until you access the link above."
306
+ someone_invited_you: "The Exhibits Administrator has invited you to help work on the \"%{exhibit_name}\" exhibit."
307
+ accept_invitation: "You can accept this invitation by clicking the link below."
308
+ accept_link: "Accept invitation"
309
+ ignore: "If you don't want to accept the invitation, please ignore this email. Your account won't be created until you access the link above."
310
+ visit: 'Visit exhibit'
308
311
  exhibits_admin_invitation_mailer:
309
312
  invitation_instructions:
313
+ subject: 'Invitation to manage \"%{exhibit_name}\"'
310
314
  hello: "Hello!"
311
- someone_invited_you: "The Exhibits Administrator has invited you to help manage exhibits. You can accept this invitation by clicking the link below."
315
+ someone_invited_you: "The Exhibits Administrator has invited you to help manage exhibits."
316
+ accept_invitation: " You can accept this invitation by clicking the link below."
312
317
  accept: "Accept invitation"
313
- ignore_html: "If you don't want to accept the invitation, please ignore this email. Your exhibits administrator account won't be created until you access the link above."
318
+ ignore: "If you don't want to accept the invitation, please ignore this email. Your exhibits administrator account won't be created until you access the link above."
314
319
  confirmation_mailer:
315
320
  confirmation_instructions:
316
321
  welcome: "Welcome %{email}!"
@@ -1,18 +1,6 @@
1
1
  Spotlight::Engine.routes.draw do
2
2
  devise_for :contact_email, class_name: 'Spotlight::ContactEmail', only: [:confirmations]
3
3
 
4
- concern :user_existable do
5
- collection do
6
- get :exists
7
- end
8
- end
9
-
10
- concern :user_invitable do
11
- collection do
12
- post :invite
13
- end
14
- end
15
-
16
4
  resource :site, only: [:edit, :update] do
17
5
  collection do
18
6
  get '/tags', to: 'sites#tags'
@@ -21,7 +9,7 @@ Spotlight::Engine.routes.draw do
21
9
 
22
10
  get '/exhibits/edit', to: 'sites#edit_exhibits', as: 'edit_site_exhibits'
23
11
 
24
- resources :admin_users, only: [:index, :create, :destroy], concerns: [:user_existable, :user_invitable]
12
+ resources :admin_users, only: [:index, :create, :destroy]
25
13
 
26
14
  resources :exhibits, path: '/', except: [:show] do
27
15
  member do
@@ -115,7 +103,7 @@ Spotlight::Engine.routes.draw do
115
103
 
116
104
  resources :lock, only: [:destroy]
117
105
 
118
- resources :roles, path: 'users', only: [:index, :create, :destroy], concerns: [:user_existable, :user_invitable] do
106
+ resources :roles, path: 'users', only: [:index, :create, :destroy] do
119
107
  collection do
120
108
  patch :update_all
121
109
  end
@@ -0,0 +1,5 @@
1
+ class AddIndexStatusToSolrDocumentSidecar < ActiveRecord::Migration
2
+ def change
3
+ add_column :spotlight_solr_document_sidecars, :index_status, :binary
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Spotlight
2
- VERSION = '0.27.0'.freeze
2
+ VERSION = '0.28.0'.freeze
3
3
  end
@@ -22,59 +22,13 @@ describe Spotlight::AdminUsersController, type: :controller do
22
22
  end
23
23
 
24
24
  describe 'DELETE destroy' do
25
- before do
26
- post :invite, params: { user: 'user@example.com', role: 'admin' }
27
- end
25
+ let(:user) { FactoryGirl.create(:user) }
26
+ let!(:admin_role) { FactoryGirl.create(:role, role: 'admin', user: user, resource: Spotlight::Site.instance) }
28
27
  it 'removes the site admin role from the given user' do
29
- last_user = Spotlight::Site.instance.roles.last.user
30
- expect(last_user.email).to eq 'user@example.com'
31
-
32
- delete :destroy, params: { id: last_user.id }
28
+ delete :destroy, params: { id: user.id }
33
29
  expect(response).to redirect_to(admin_users_path)
34
30
  expect(flash[:notice]).to eq 'User removed from site adminstrator role'
35
- expect(Spotlight::Site.instance.roles.last.user.id).not_to eq last_user.id
36
- end
37
- end
38
-
39
- describe 'GET exists' do
40
- it 'requires a user parameter' do
41
- expect do
42
- get :exists
43
- end.to raise_error(ActionController::ParameterMissing)
44
- end
45
-
46
- it 'returns a successful status when the requested user exists' do
47
- user = FactoryGirl.create(:exhibit_curator)
48
- get :exists, params: { user: user.email }
49
- expect(response).to be_success
50
- end
51
-
52
- it 'returns an unsuccessful status when the user does not exist' do
53
- get :exists, params: { user: 'user@example.com' }
54
- expect(response).not_to be_success
55
- expect(response.status).to eq 404
56
- end
57
- end
58
-
59
- describe 'GET invite' do
60
- it 'invites the selected user to be an admin' do
61
- expect do
62
- post :invite, params: { user: 'user@example.com', role: 'admin' }
63
- end.to change { Spotlight::Engine.user_class.count }.by(1)
64
- expect(Spotlight::Engine.user_class.last.roles.length).to eq 1
65
- expect(Spotlight::Engine.user_class.last.roles.first.resource).to eq Spotlight::Site.instance
66
- end
67
-
68
- it 'redirects back with a flash notice upon success' do
69
- post :invite, params: { user: 'user@example.com', role: 'admin' }
70
- expect(flash[:notice]).to eq 'User has been invited.'
71
- expect(response).to redirect_to('http://example.com')
72
- end
73
-
74
- it 'redirects back with flash error upon failure' do
75
- post :invite, params: { user: 'user@example.com', role: 'not-a-real-role' }
76
- expect(flash[:alert]).to eq 'There was a problem saving the user.'
77
- expect(response).to redirect_to('http://example.com')
31
+ expect(Spotlight::Site.instance.roles.where(user_id: user.id)).to be_none
78
32
  end
79
33
  end
80
34
  end
@@ -115,55 +115,5 @@ describe Spotlight::RolesController, type: :controller do
115
115
  expect(flash[:alert]).to eq 'There was a problem saving the user.'
116
116
  end
117
117
  end
118
-
119
- describe 'GET exists' do
120
- it 'requires a user parameter' do
121
- expect do
122
- get :exists, params: { exhibit_id: exhibit }
123
- end.to raise_error(ActionController::ParameterMissing)
124
- end
125
-
126
- it 'returns a successful status when the requested user exists' do
127
- user = FactoryGirl.create(:exhibit_curator)
128
- get :exists, params: { exhibit_id: exhibit, user: user.email }
129
- expect(response).to be_success
130
- end
131
-
132
- it 'returns an unsuccessful status when the user does not exist' do
133
- get :exists, params: { exhibit_id: exhibit, user: 'user@example.com' }
134
- expect(response).not_to be_success
135
- expect(response.status).to eq 404
136
- end
137
- end
138
-
139
- describe 'GET invite' do
140
- before { request.env['HTTP_REFERER'] = 'http://example.com' }
141
-
142
- it 'invites the selected user' do
143
- expect do
144
- post :invite, params: { exhibit_id: exhibit, user: 'user@example.com', role: 'curator' }
145
- end.to change { Spotlight::Engine.user_class.count }.by(1)
146
- expect(Spotlight::Engine.user_class.last.roles.length).to eq 1
147
- expect(Spotlight::Engine.user_class.last.roles.first.resource).to eq exhibit
148
- end
149
-
150
- it 'adds the user to the exhibit via a role' do
151
- expect do
152
- post :invite, params: { exhibit_id: exhibit, user: 'user@example.com', role: 'curator' }
153
- end.to change { Spotlight::Role.count }.by(1)
154
- end
155
-
156
- it 'redirects back with a flash notice upon success' do
157
- post :invite, params: { exhibit_id: exhibit, user: 'user@example.com', role: 'curator' }
158
- expect(flash[:notice]).to eq 'User has been invited.'
159
- expect(response).to redirect_to('http://example.com')
160
- end
161
-
162
- it 'redirects back with flash error upon failure' do
163
- post :invite, params: { exhibit_id: exhibit, user: 'user@example.com', role: 'not-a-real-role' }
164
- expect(flash[:alert]).to eq 'There was a problem saving the user.'
165
- expect(response).to redirect_to('http://example.com')
166
- end
167
- end
168
118
  end
169
119
  end
@@ -8,18 +8,6 @@ describe 'Roles Admin', type: :feature, js: true do
8
8
  click_link 'Users'
9
9
  end
10
10
 
11
- it 'informs the admin that a user they are trying to add does not yet exist' do
12
- expect(page).to have_css('.help-block[data-behavior="no-user-note"]', visible: false)
13
- expect(page).not_to have_css('input[disabled]')
14
-
15
- click_link 'Add a new user'
16
- fill_in 'User key', with: 'user@example.com'
17
-
18
- expect(page).to have_css('.help-block[data-behavior="no-user-note"]', visible: true)
19
- expect(page).to have_link('invite', visible: true)
20
- expect(page).to have_css('input[disabled]')
21
- end
22
-
23
11
  it 'has the appropriate status message when an existing user is added' do
24
12
  second_user = FactoryGirl.create(:site_admin)
25
13
 
@@ -37,7 +25,7 @@ describe 'Roles Admin', type: :feature, js: true do
37
25
 
38
26
  click_link 'Add a new user'
39
27
  fill_in 'User key', with: 'user@example.com'
40
- click_link 'invite'
28
+ click_button 'Save changes'
41
29
 
42
30
  within('tr.invite-pending') do
43
31
  expect(page).to have_css('td', text: 'user@example.com')
@@ -39,11 +39,9 @@ describe 'Site admin management', js: true do
39
39
 
40
40
  fill_in 'user_email', with: 'not-an-existing-user@example.com'
41
41
 
42
- expect(page).to have_content('This user does not yet exist. Would you like to send them an invite?')
43
-
44
- expect { click_link('invite') }.to change { ActionMailer::Base.deliveries.count }.by(1)
42
+ click_button 'Add role'
45
43
 
46
- expect(page).to have_content('User has been invited.')
44
+ expect(page).to have_content('not-an-existing-user@example.com pending')
47
45
  end
48
46
 
49
47
  it 'allows the admin to remove the admin role from the user' do
@@ -51,8 +49,7 @@ describe 'Site admin management', js: true do
51
49
 
52
50
  fill_in 'user_email', with: 'not-an-admin@example.com'
53
51
 
54
- click_link 'invite'
55
- expect(page).to have_content('User has been invited.')
52
+ click_button 'Add role'
56
53
 
57
54
  expect(page).to have_css(:td, text: 'not-an-admin@example.com')
58
55
 
@@ -9,15 +9,17 @@ describe Spotlight::Role, type: :model do
9
9
  end
10
10
  end
11
11
  describe 'with user_key' do
12
- let(:user) { FactoryGirl.create(:user) }
13
12
  describe "that doesn't point at a user" do
14
- let(:args) { { role: 'curator', user_key: 'bob' } }
13
+ let(:user) { FactoryGirl.build(:user) }
14
+ let(:args) { { role: 'curator', user_key: user.email } }
15
15
  it 'does not be valid' do
16
- expect(subject).not_to be_valid
17
- expect(subject.errors.messages).to eq(user_key: ['User must sign up first.'])
16
+ expect(subject).to be_valid
17
+ subject.save!
18
+ expect(subject.user).to be_invite_pending
18
19
  end
19
20
  end
20
21
  describe 'that points at a user' do
22
+ let(:user) { FactoryGirl.create(:user) }
21
23
  let(:args) { { role: 'curator', user_key: user.email } }
22
24
  it 'is valid' do
23
25
  expect(subject).to be_valid
@@ -25,6 +27,7 @@ describe Spotlight::Role, type: :model do
25
27
  end
26
28
  end
27
29
  describe 'that points at a user with an existing role' do
30
+ let(:user) { FactoryGirl.create(:user) }
28
31
  before { described_class.create!(role: 'curator', user: user) }
29
32
  let(:args) { { role: 'curator', user_key: user.email } }
30
33
  it 'is valid' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight-spotlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-08-16 00:00:00.000000000 Z
14
+ date: 2016-08-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -725,7 +725,6 @@ files:
725
725
  - app/assets/javascripts/spotlight/blocks/solr_documents_grid_block.js
726
726
  - app/assets/javascripts/spotlight/blocks/uploaded_items_block.js
727
727
  - app/assets/javascripts/spotlight/catalog_edit.js
728
- - app/assets/javascripts/spotlight/check_user_existence.js
729
728
  - app/assets/javascripts/spotlight/compat.js
730
729
  - app/assets/javascripts/spotlight/copy_email_addresses.js
731
730
  - app/assets/javascripts/spotlight/croppable.js
@@ -795,8 +794,6 @@ files:
795
794
  - app/controllers/spotlight/catalog_controller.rb
796
795
  - app/controllers/spotlight/concerns/application_controller.rb
797
796
  - app/controllers/spotlight/concerns/catalog_search_context.rb
798
- - app/controllers/spotlight/concerns/user_existable.rb
799
- - app/controllers/spotlight/concerns/user_invitable.rb
800
797
  - app/controllers/spotlight/confirmations_controller.rb
801
798
  - app/controllers/spotlight/contact_forms_controller.rb
802
799
  - app/controllers/spotlight/contacts_controller.rb
@@ -839,6 +836,7 @@ files:
839
836
  - app/mailers/spotlight/confirmation_mailer.rb
840
837
  - app/mailers/spotlight/contact_mailer.rb
841
838
  - app/mailers/spotlight/indexing_complete_mailer.rb
839
+ - app/mailers/spotlight/invitation_mailer.rb
842
840
  - app/models/ability.rb
843
841
  - app/models/concerns/spotlight/access_controls_enforcement_search_builder.rb
844
842
  - app/models/concerns/spotlight/ar_light.rb
@@ -1008,6 +1006,7 @@ files:
1008
1006
  - app/views/spotlight/home_pages/_sidebar.html.erb
1009
1007
  - app/views/spotlight/home_pages/_tophat.html.erb
1010
1008
  - app/views/spotlight/indexing_complete_mailer/documents_indexed.html.erb
1009
+ - app/views/spotlight/invitation_mailer/exhibit_invitation_notification.html.erb
1011
1010
  - app/views/spotlight/locks/_lock.html.erb
1012
1011
  - app/views/spotlight/metadata_configurations/_metadata_field.html.erb
1013
1012
  - app/views/spotlight/metadata_configurations/edit.html.erb
@@ -1122,6 +1121,7 @@ files:
1122
1121
  - db/migrate/20160329215014_add_readonly_to_custom_fields.rb
1123
1122
  - db/migrate/20160711121314_add_default_view_to_spotlight_searches.rb
1124
1123
  - db/migrate/20160815165432_add_resource_to_solr_document_sidecar.rb
1124
+ - db/migrate/20160816165432_add_index_status_to_solr_document_sidecar.rb
1125
1125
  - lib/blacklight/spotlight.rb
1126
1126
  - lib/generators/spotlight/install_generator.rb
1127
1127
  - lib/generators/spotlight/scaffold_resource_generator.rb
@@ -1,84 +0,0 @@
1
- (function($) {
2
- $.fn.spotlightCheckUserExistence = function() {
3
- var formElements = this;
4
- var target;
5
-
6
- $(formElements).each(function() {
7
- $(this).on('blur', checkIfUserExists);
8
- $(this).on('change', cleanUpBlankUserField);
9
- });
10
-
11
- function checkIfUserExists() {
12
- target = $(this);
13
- if (target.val() !== '' && form()[0].checkValidity()) {
14
- $.ajax(userExistsUrl())
15
- .success(userExists)
16
- .fail(userDoesNotExist);
17
- } else {
18
- userExists();
19
- }
20
- }
21
-
22
- function cleanUpBlankUserField() {
23
- if ($(this).val() === '') {
24
- userExists();
25
- }
26
- }
27
-
28
- function userExists() {
29
- noUserNote().hide();
30
- submitButton().prop('disabled', false);
31
- }
32
-
33
- function userDoesNotExist() {
34
- updateNoUserNoteLink();
35
- noUserNote().show();
36
- roleSelect().on('change', updateNoUserNoteLink);
37
- submitButton().prop('disabled', true);
38
- }
39
-
40
- function updateNoUserNoteLink() {
41
- var link = noUserNote().find('a');
42
- var originalHref = link.data('inviteUrl');
43
- var userName = target.val();
44
- link.attr(
45
- 'href',
46
- originalHref + '?user=' + encodeURIComponent(userName) + '&role=' + encodeURIComponent(roleValue())
47
- );
48
- }
49
-
50
- function roleValue() {
51
- if (roleSelect().length > 0) {
52
- return roleSelect().val();
53
- } else {
54
- return target.closest('tr').find('[data-user-role]').data('userRole');
55
- }
56
- }
57
-
58
- function roleSelect() {
59
- return target.closest('tr').find('select');
60
- }
61
-
62
- function noUserNote() {
63
- return form().find('[data-behavior="no-user-note"]');
64
- }
65
-
66
- function submitButton() {
67
- return form().find('input[type="submit"]');
68
- }
69
-
70
- function form() {
71
- return target.closest('form');
72
- }
73
-
74
- function userExistsUrl() {
75
- return $('[data-user-exists-url]').data('userExistsUrl') + '?user=' + target.val();
76
- }
77
-
78
- return this;
79
- };
80
- })(jQuery);
81
-
82
- Spotlight.onLoad(function() {
83
- $('[data-behavior="check-user-existence"]').spotlightCheckUserExistence();
84
- });
@@ -1,24 +0,0 @@
1
- module Spotlight
2
- module Concerns
3
- ###
4
- # Mixin to be included into controllers that provides a
5
- # method to check if a particular user exists in the site
6
- module UserExistable
7
- def exists
8
- # note: the messages returned are not shown to users and really only useful for debug, hence no translation necessary
9
- # app uses html status code to act on response
10
- if Spotlight::Engine.user_class.where(email: exists_params).present?
11
- render json: { message: 'User exists' }
12
- else
13
- render json: { message: 'User does not exist' }, status: :not_found
14
- end
15
- end
16
-
17
- protected
18
-
19
- def exists_params
20
- params.require(:user)
21
- end
22
- end
23
- end
24
- end
@@ -1,38 +0,0 @@
1
- module Spotlight
2
- module Concerns
3
- ###
4
- # Mixin to be included into controllers that provides an action which
5
- # allows admins and curators to invite users and assign them a role.
6
- module UserInvitable
7
- def invite
8
- # skip_invitation stops the immediate delivery of the invitation
9
- user = Spotlight::Engine.user_class.invite!(email: invite_params[:user], skip_invitation: true)
10
- role = Spotlight::Role.create(resource: exhibit_or_site, user: user, role: invite_params[:role])
11
- if role.save
12
- user.deliver_invitation # now deliver it when we have saved the role
13
- redirect_back fallback_location: fallback_location, notice: t(:'helpers.submit.invite.invited')
14
- else
15
- redirect_back fallback_location: fallback_location, alert: t(:'helpers.submit.role.batch_error', count: 1)
16
- end
17
- end
18
-
19
- protected
20
-
21
- def invite_params
22
- params.permit(:user, :role)
23
- end
24
-
25
- def exhibit_or_site
26
- current_exhibit || @site
27
- end
28
-
29
- def fallback_location
30
- if current_exhibit
31
- spotlight.exhibit_roles_path(current_exhibit)
32
- else
33
- spotlight.admin_users_path
34
- end
35
- end
36
- end
37
- end
38
- end