hyrax 2.0.0.beta1 → 2.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -2
  3. data/app/actors/hyrax/actors/file_set_actor.rb +12 -15
  4. data/app/assets/javascripts/hyrax.js +6 -5
  5. data/app/assets/javascripts/hyrax/{app.js → app.js.erb} +12 -8
  6. data/app/assets/javascripts/hyrax/channels/notifications.js +0 -0
  7. data/app/assets/javascripts/hyrax/notification.es6 +19 -31
  8. data/app/channels/hyrax/application_cable/channel.rb +6 -0
  9. data/app/channels/hyrax/application_cable/connection.rb +30 -0
  10. data/app/channels/hyrax/notifications_channel.rb +15 -0
  11. data/app/controllers/hyrax/depositors_controller.rb +2 -2
  12. data/app/controllers/hyrax/notifications_controller.rb +2 -0
  13. data/app/controllers/hyrax/users_controller.rb +0 -7
  14. data/app/helpers/hyrax/hyrax_helper_behavior.rb +27 -0
  15. data/app/jobs/import_url_job.rb +3 -1
  16. data/app/jobs/stream_notifications_job.rb +10 -0
  17. data/app/models/proxy_deposit_request.rb +2 -2
  18. data/app/models/user_mailbox.rb +19 -0
  19. data/app/services/hyrax/{message_user_service.rb → abstract_message_service.rb} +7 -4
  20. data/app/services/hyrax/batch_create_failure_service.rb +1 -1
  21. data/app/services/hyrax/batch_create_success_service.rb +1 -1
  22. data/app/services/hyrax/fixity_check_failure_service.rb +1 -1
  23. data/app/services/hyrax/import_url_failure_service.rb +1 -1
  24. data/app/services/hyrax/messenger_service.rb +8 -0
  25. data/app/services/hyrax/workflow/abstract_notification.rb +1 -1
  26. data/app/views/_user_util_links.html.erb +1 -1
  27. data/app/views/hyrax/homepage/index.html.erb +1 -1
  28. data/config/locales/hyrax.de.yml +5 -2
  29. data/config/locales/hyrax.en.yml +4 -1
  30. data/config/locales/hyrax.es.yml +4 -1
  31. data/config/locales/hyrax.fr.yml +5 -2
  32. data/config/locales/hyrax.it.yml +4 -1
  33. data/config/locales/hyrax.pt-BR.yml +5 -2
  34. data/config/locales/hyrax.zh.yml +5 -2
  35. data/config/routes.rb +4 -2
  36. data/db/migrate/20170905135339_add_preferred_locale_to_users.rb +5 -0
  37. data/lib/generators/hyrax/templates/config/authorities/licenses.yml +28 -10
  38. data/lib/generators/hyrax/templates/config/hyrax.rb +0 -3
  39. data/lib/hyrax/configuration.rb +0 -5
  40. data/lib/hyrax/engine.rb +5 -0
  41. data/lib/hyrax/version.rb +1 -1
  42. data/spec/actors/hyrax/actors/file_set_actor_spec.rb +74 -0
  43. data/spec/channels/hyrax/application_cable/channel_spec.rb +14 -0
  44. data/spec/channels/hyrax/application_cable/connection_spec.rb +31 -0
  45. data/spec/channels/hyrax/notifications_channel_spec.rb +45 -0
  46. data/spec/controllers/hyrax/notifications_controller_spec.rb +1 -0
  47. data/spec/helpers/blacklight_helper_spec.rb +4 -2
  48. data/spec/helpers/hyrax_helper_spec.rb +34 -4
  49. data/spec/jobs/import_url_job_spec.rb +1 -1
  50. data/spec/jobs/stream_notifications_job_spec.rb +30 -0
  51. data/spec/models/collection_spec.rb +13 -19
  52. data/spec/models/proxy_deposit_request_spec.rb +2 -1
  53. data/spec/models/user_mailbox_spec.rb +73 -0
  54. data/spec/services/hyrax/abstract_message_service_spec.rb +25 -0
  55. data/spec/services/hyrax/messenger_service_spec.rb +15 -0
  56. data/spec/test_app_templates/lib/generators/test_app_generator.rb +6 -0
  57. data/spec/views/_user_util_links.html.erb_spec.rb +3 -2
  58. data/spec/views/hyrax/homepage/index.html.erb_spec.rb +4 -0
  59. data/template.rb +1 -1
  60. metadata +23 -14
  61. data/app/assets/javascripts/hyrax/notifications.es6 +0 -63
  62. data/app/views/hyrax/users/_notify_number.html.erb +0 -8
  63. data/app/views/hyrax/users/notifications_number.json.jbuilder +0 -1
  64. data/app/views/kaminari/blacklight/_first_page.html.erb +0 -9
  65. data/app/views/kaminari/blacklight/_gap.html.erb +0 -8
  66. data/app/views/kaminari/blacklight/_last_page.html.erb +0 -9
  67. data/app/views/kaminari/blacklight/_next_page.html.erb +0 -9
  68. data/app/views/kaminari/blacklight/_page.html.erb +0 -10
  69. data/app/views/kaminari/blacklight/_paginator.html.erb +0 -19
  70. data/app/views/kaminari/blacklight/_prev_page.html.erb +0 -9
@@ -1,5 +1,5 @@
1
1
  module Hyrax
2
- class MessageUserService
2
+ class AbstractMessageService
3
3
  attr_reader :file_set, :user
4
4
 
5
5
  def initialize(file_set, user)
@@ -8,15 +8,18 @@ module Hyrax
8
8
  end
9
9
 
10
10
  def call
11
- job_user.send_message(user, message, subject)
11
+ Hyrax::MessengerService.deliver(job_user,
12
+ user,
13
+ message,
14
+ subject)
12
15
  end
13
16
 
14
- # Passed into send_message, override to provide message body for event.
17
+ # Passed to Hyrax::MessengerService, override to provide message body for event.
15
18
  def message
16
19
  raise "Override #message in the service class"
17
20
  end
18
21
 
19
- # Passed into send_message, override to provide subject for event.
22
+ # Passed to Hyrax::MessengerService, override to provide subject for event.
20
23
  def subject
21
24
  raise "Override #subject in the service class"
22
25
  end
@@ -1,5 +1,5 @@
1
1
  module Hyrax
2
- class BatchCreateFailureService < MessageUserService
2
+ class BatchCreateFailureService < AbstractMessageService
3
3
  attr_reader :user
4
4
  def initialize(user)
5
5
  @user = user
@@ -1,5 +1,5 @@
1
1
  module Hyrax
2
- class BatchCreateSuccessService < MessageUserService
2
+ class BatchCreateSuccessService < AbstractMessageService
3
3
  attr_reader :user
4
4
 
5
5
  def initialize(user)
@@ -1,5 +1,5 @@
1
1
  module Hyrax
2
- class FixityCheckFailureService < MessageUserService
2
+ class FixityCheckFailureService < AbstractMessageService
3
3
  attr_reader :log_date, :checksum_audit_log, :file_set
4
4
 
5
5
  def initialize(file_set, checksum_audit_log:)
@@ -1,5 +1,5 @@
1
1
  module Hyrax
2
- class ImportUrlFailureService < MessageUserService
2
+ class ImportUrlFailureService < AbstractMessageService
3
3
  def message
4
4
  file_set.errors.full_messages.join(', ')
5
5
  end
@@ -0,0 +1,8 @@
1
+ module Hyrax
2
+ class MessengerService
3
+ def self.deliver(sender, recipients, body, subject, *args)
4
+ sender.send_message(recipients, body, subject, *args)
5
+ StreamNotificationsJob.perform_later(recipients)
6
+ end
7
+ end
8
+ end
@@ -48,7 +48,7 @@ module Hyrax
48
48
 
49
49
  def call
50
50
  users_to_notify.uniq.each do |recipient|
51
- user.send_message(recipient, message, subject)
51
+ Hyrax::MessengerService.deliver(user, recipient, message, subject)
52
52
  end
53
53
  end
54
54
 
@@ -2,7 +2,7 @@
2
2
  <%= render 'shared/locale_picker' if available_translations.size > 1 %>
3
3
  <% if user_signed_in? %>
4
4
  <li>
5
- <%= render 'hyrax/users/notify_number' %>
5
+ <%= render_notifications(user: current_user) %>
6
6
  </li>
7
7
  <li class="dropdown">
8
8
  <%= link_to hyrax.dashboard_profile_path(current_user), role: 'button', data: { toggle: 'dropdown' }, aria: { haspopup: true, expanded: false} do %>
@@ -17,7 +17,7 @@
17
17
  <% end %>
18
18
  <% end %>
19
19
  <% else %>
20
- <%= link_to hyrax.dashboard_path,
20
+ <%= link_to hyrax.my_works_path,
21
21
  class: "btn btn-primary btn-lg" do %>
22
22
  <i class="glyphicon glyphicon-upload"></i> <%= t('hyrax.share_button') %>
23
23
  <% end %>
@@ -511,7 +511,7 @@ de:
511
511
  user_activity: Benutzeraktivität
512
512
  user_notifications: Benutzerbenachrichtigungen
513
513
  view_files: Dateien ansehen
514
- document_language: En
514
+ document_language: de
515
515
  edit_profile: Profil bearbeiten
516
516
  embargoes:
517
517
  edit:
@@ -697,7 +697,10 @@ de:
697
697
  dashboard:
698
698
  menu: Instrumententafel
699
699
  language_switch: Sprache wechseln
700
- notifications: Sie haben keine ungelesenen Benachrichtigungen
700
+ notifications:
701
+ many: Sie haben %{count} ungelesene Benachrichtigungen
702
+ one: Sie haben eine ungelesene Benachrichtigung
703
+ zero: Sie haben keine ungelesenen Benachrichtigungen
701
704
  profile:
702
705
  login: Anmeldung
703
706
  logout: Ausloggen
@@ -686,7 +686,10 @@ en:
686
686
  dashboard:
687
687
  menu: "Dashboard"
688
688
  language_switch: "Switch language"
689
- notifications: "You have no unread notifications"
689
+ notifications:
690
+ zero: "You have no unread notifications"
691
+ one: "You have one unread notification"
692
+ many: "You have %{count} unread notifications"
690
693
  profile:
691
694
  login: "Login"
692
695
  logout: "Logout"
@@ -694,7 +694,10 @@ es:
694
694
  dashboard:
695
695
  menu: Panel de Control
696
696
  language_switch: Cambiar idioma
697
- notifications: No hay notificaciones sin leer.
697
+ notifications:
698
+ many: Tienes notificaciones no leídas de %{count}
699
+ one: Tienes una notificación no leída
700
+ zero: No tienes notificaciones no leídas.
698
701
  profile:
699
702
  login: Iniciar sesión
700
703
  logout: Cerrar sesión
@@ -511,7 +511,7 @@ fr:
511
511
  user_activity: Activité de l'utilisateur
512
512
  user_notifications: Notifications de l'utilisateur
513
513
  view_files: Afficher les fichiers
514
- document_language: En
514
+ document_language: fr
515
515
  edit_profile: Editer le profil
516
516
  embargoes:
517
517
  edit:
@@ -697,7 +697,10 @@ fr:
697
697
  dashboard:
698
698
  menu: Tableau de bord
699
699
  language_switch: Changer de langue
700
- notifications: Vous n'avez aucune notification non lue
700
+ notifications:
701
+ many: Vous avez des notifications non-lues %{count}
702
+ one: Vous avez une notification non lue
703
+ zero: Vous n'avez aucune notification non lue
701
704
  profile:
702
705
  login: S'identifier
703
706
  logout: Connectez - Out
@@ -697,7 +697,10 @@ it:
697
697
  dashboard:
698
698
  menu: Cruscotto
699
699
  language_switch: Cambiare la lingua
700
- notifications: Non hai notifiche non letti
700
+ notifications:
701
+ many: Hai notifiche non letti %{count}
702
+ one: Hai una notifica non letti
703
+ zero: Non hai notifiche non letti
701
704
  profile:
702
705
  login: Accesso
703
706
  logout: Logout
@@ -511,7 +511,7 @@ pt-BR:
511
511
  user_activity: Atividade do usuário
512
512
  user_notifications: Notificações do usuário
513
513
  view_files: Ver arquivos
514
- document_language: En
514
+ document_language: pt-BR
515
515
  edit_profile: Editar Perfil
516
516
  embargoes:
517
517
  edit:
@@ -697,7 +697,10 @@ pt-BR:
697
697
  dashboard:
698
698
  menu: painel de controle
699
699
  language_switch: Alterar idioma
700
- notifications: Você não possui notificações não lidas
700
+ notifications:
701
+ many: Você recebeu notificações não lidas do %{count}
702
+ one: Você tem uma notificação não lida
703
+ zero: Você não possui notificações não lidas
701
704
  profile:
702
705
  login: Entrar
703
706
  logout: Sair
@@ -512,7 +512,7 @@ zh:
512
512
  user_activity: 用户活动
513
513
  user_notifications: 用户通知
514
514
  view_files: 阅览文件
515
- document_language: en
515
+ document_language: zh
516
516
  edit_profile: 编辑个人资料
517
517
  embargoes:
518
518
  edit:
@@ -700,7 +700,10 @@ zh:
700
700
  dashboard:
701
701
  menu: 控件板
702
702
  language_switch: 转换语言
703
- notifications: 您没有未曾阅读的通知
703
+ notifications:
704
+ many: 您有%{count}未读通知
705
+ one: 您有一个未读通知
706
+ zero: 您没有未读通知
704
707
  profile:
705
708
  login: 登录
706
709
  logout: 退出登录
data/config/routes.rb CHANGED
@@ -42,8 +42,6 @@ Hyrax::Engine.routes.draw do
42
42
  match 'batch_edits/:id' => 'batch_edits#add', :via => :put
43
43
  match 'batch_edits' => 'batch_edits#destroy_collection', :via => :delete
44
44
 
45
- # Notifications route for catalog index view
46
- get 'users/notifications_number' => 'users#notifications_number', as: :user_notify
47
45
  resources :batch_uploads, only: [:new, :create], controller: 'batch_uploads'
48
46
 
49
47
  resources :collections, only: :show do # public landing show page
@@ -94,6 +92,10 @@ Hyrax::Engine.routes.draw do
94
92
  delete 'delete_all'
95
93
  end
96
94
  end
95
+ namespace :notifications do
96
+ # WebSocket for notifications
97
+ mount ActionCable.server => 'endpoint', as: :endpoint
98
+ end
97
99
 
98
100
  # User profile
99
101
  resources :users, only: [:index, :show] do
@@ -0,0 +1,5 @@
1
+ class AddPreferredLocaleToUsers < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_column :users, :preferred_locale, :string
4
+ end
5
+ end
@@ -1,28 +1,46 @@
1
1
  terms:
2
2
  - id: http://creativecommons.org/licenses/by/3.0/us/
3
3
  term: Attribution 3.0 United States
4
- active: true
4
+ active: false
5
5
  - id: http://creativecommons.org/licenses/by-sa/3.0/us/
6
6
  term: Attribution-ShareAlike 3.0 United States
7
- active: true
7
+ active: false
8
8
  - id: http://creativecommons.org/licenses/by-nc/3.0/us/
9
9
  term: Attribution-NonCommercial 3.0 United States
10
- active: true
10
+ active: false
11
11
  - id: http://creativecommons.org/licenses/by-nd/3.0/us/
12
12
  term: Attribution-NoDerivs 3.0 United States
13
- active: true
13
+ active: false
14
14
  - id: http://creativecommons.org/licenses/by-nc-nd/3.0/us/
15
15
  term: Attribution-NonCommercial-NoDerivs 3.0 United States
16
- active: true
16
+ active: false
17
17
  - id: http://creativecommons.org/licenses/by-nc-sa/3.0/us/
18
18
  term: Attribution-NonCommercial-ShareAlike 3.0 United States
19
+ active: false
20
+ - id: http://www.europeana.eu/portal/rights/rr-r.html
21
+ term: All rights reserved
22
+ active: false
23
+ - id: https://creativecommons.org/licenses/by/4.0/
24
+ term: Creative Commons BY Attribution 4.0 International
19
25
  active: true
20
- - id: http://creativecommons.org/publicdomain/mark/1.0/
21
- term: Public Domain Mark 1.0
26
+ - id: https://creativecommons.org/licenses/by-sa/4.0/
27
+ term: Creative Commons BY-SA Attribution-ShareAlike 4.0 International
28
+ active: true
29
+ - id: https://creativecommons.org/licenses/by-nd/4.0/
30
+ term: Creative Commons BY-ND Attribution-NoDerivatives 4.0 International
31
+ active: true
32
+ - id: https://creativecommons.org/licenses/by-nc/4.0/
33
+ term: Creative Commons BY-NC Attribution-NonCommercial 4.0 International
34
+ active: true
35
+ - id: https://creativecommons.org/licenses/by-nc-nd/4.0/
36
+ term: Creative Commons BY-NC-ND Attribution-NonCommercial-NoDerivs 4.0 International
37
+ active: true
38
+ - id: https://creativecommons.org/licenses/by-nc-sa/4.0/
39
+ term: Creative Commons BY-NC-SA Attribution-NonCommercial-ShareAlike 4.0 International
22
40
  active: true
23
41
  - id: http://creativecommons.org/publicdomain/zero/1.0/
24
- term: CC0 1.0 Universal
42
+ term: Creative Commons CC0 1.0 Universal
25
43
  active: true
26
- - id: http://www.europeana.eu/portal/rights/rr-r.html
27
- term: All rights reserved
44
+ - id: http://creativecommons.org/publicdomain/mark/1.0/
45
+ term: Creative Commons Public Domain Mark 1.0
28
46
  active: true
@@ -20,9 +20,6 @@ Hyrax.config do |config|
20
20
  # How many notifications should be displayed on the dashboard
21
21
  # config.max_notifications_for_dashboard = 5
22
22
 
23
- # How often clients should poll for notifications
24
- # config.notifications_update_poll_interval = 30.seconds
25
-
26
23
  # How frequently should a file be fixity checked
27
24
  # config.max_days_between_fixity_checks = 7
28
25
 
@@ -261,11 +261,6 @@ module Hyrax
261
261
  @max_notifications_for_dashboard ||= 5
262
262
  end
263
263
 
264
- attr_writer :notifications_update_poll_interval
265
- def notifications_update_poll_interval
266
- @notifications_update_poll_interval ||= 30.seconds
267
- end
268
-
269
264
  attr_writer :activity_to_show_default_seconds_since_now
270
265
  def activity_to_show_default_seconds_since_now
271
266
  @activity_to_show_default_seconds_since_now ||= 24 * 60 * 60
data/lib/hyrax/engine.rb CHANGED
@@ -25,6 +25,11 @@ module Hyrax
25
25
  "Blacklight::Exceptions::RecordNotFound" => :not_found
26
26
  )
27
27
 
28
+ config.before_initialize do
29
+ # ActionCable should use Hyrax's connection class instead of app's
30
+ config.action_cable.connection_class = -> { 'Hyrax::ApplicationCable::Connection'.safe_constantize }
31
+ end
32
+
28
33
  config.after_initialize do
29
34
  begin
30
35
  Hyrax.config.persist_registered_roles!
data/lib/hyrax/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hyrax
2
- VERSION = '2.0.0.beta1'.freeze
2
+ VERSION = '2.0.0.beta2'.freeze
3
3
  end
@@ -133,6 +133,80 @@ RSpec.describe Hyrax::Actors::FileSetActor do
133
133
  end
134
134
  end
135
135
 
136
+ describe '#create_content when from_url is true' do
137
+ before do
138
+ expect(JobIoWrapper).to receive(:create_with_varied_file_handling!).with(any_args).once.and_call_original
139
+ end
140
+
141
+ it 'calls ingest_file' do
142
+ actor.create_content(file, from_url: true)
143
+ end
144
+
145
+ context 'when an alternative relationship is specified' do
146
+ before do
147
+ # Relationship must be declared before being used. Inject it here.
148
+ FileSet.class_eval do
149
+ directly_contains_one :remastered, through: :files, type: ::RDF::URI("http://otherpcdm.example.org/use#Remastered"), class_name: 'Hydra::PCDM::File'
150
+ end
151
+ end
152
+
153
+ it 'calls ingest_file' do
154
+ actor.create_content(file, :remastered, from_url: true)
155
+ end
156
+ end
157
+
158
+ context 'using ::File' do
159
+ let(:file) { local_file }
160
+
161
+ before { actor.create_content(local_file, from_url: true) }
162
+
163
+ it 'sets the label and title' do
164
+ expect(file_set.label).to eq(File.basename(local_file))
165
+ expect(file_set.title).to eq([File.basename(local_file)])
166
+ end
167
+
168
+ it 'gets the mime_type from original_file' do
169
+ expect(file_set.mime_type).to eq('image/png')
170
+ end
171
+ end
172
+
173
+ context 'when file_set.title is empty and file_set.label is not' do
174
+ let(:long_name) do
175
+ 'an absurdly long title that goes on way to long and messes up the display of the page which should not need ' \
176
+ 'to be this big in order to show this impossibly long, long, long, oh so long string'
177
+ end
178
+ let(:short_name) { 'Nice Short Name' }
179
+
180
+ before do
181
+ allow(file_set).to receive(:label).and_return(short_name)
182
+ actor.create_content(file, from_url: true)
183
+ end
184
+
185
+ subject { file_set.title }
186
+
187
+ it { is_expected.to match_array [short_name] }
188
+ end
189
+
190
+ context 'when a label is already specified' do
191
+ let(:label) { 'test_file.png' }
192
+ let(:file_set) do
193
+ FileSet.new do |f|
194
+ f.apply_depositor_metadata(user.user_key)
195
+ f.label = label
196
+ end
197
+ end
198
+ let(:actor) { described_class.new(file_set, user) }
199
+
200
+ before do
201
+ actor.create_content(file, from_url: true)
202
+ end
203
+
204
+ it "retains the object's original label" do
205
+ expect(file_set.label).to eql(label)
206
+ end
207
+ end
208
+ end
209
+
136
210
  describe "#update_metadata" do
137
211
  it "is successful" do
138
212
  expect(actor.update_metadata("title" => ["updated title"])).to be true
@@ -0,0 +1,14 @@
1
+ RSpec.describe Hyrax::ApplicationCable::Channel, no_clean: true do
2
+ subject { described_class.new(connection, identifier) }
3
+
4
+ let(:connection) { double('connection', identifiers: []) }
5
+ let(:identifier) { double }
6
+
7
+ describe 'behaves like an ActionCable::Channel::Base' do
8
+ it { is_expected.to respond_to(:perform_action) }
9
+ it { is_expected.to respond_to(:unsubscribe_from_channel) }
10
+ it { is_expected.to respond_to(:stop_all_streams) }
11
+ it { is_expected.to respond_to(:stream_for) }
12
+ it { is_expected.to respond_to(:stream_from) }
13
+ end
14
+ end