bpluser 0.1.19 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +33 -0
  3. data/Rakefile +34 -3
  4. data/app/assets/config/bpluser_manifest.js +1 -0
  5. data/app/assets/javascripts/bpluser/folder_tools.js +26 -0
  6. data/app/controllers/bookmarks_controller.rb +50 -0
  7. data/app/controllers/concerns/bpluser/folders_verify_user.rb +20 -0
  8. data/app/controllers/concerns/bpluser/omniauth_callbacks.rb +27 -0
  9. data/app/controllers/concerns/bpluser/registrations.rb +35 -0
  10. data/app/controllers/concerns/bpluser/saved_searches.rb +62 -0
  11. data/app/controllers/folder_items_actions_controller.rb +77 -0
  12. data/app/controllers/folder_items_controller.rb +97 -0
  13. data/app/controllers/folders_controller.rb +100 -0
  14. data/app/controllers/saved_searches_controller.rb +5 -0
  15. data/app/controllers/users/omniauth_callbacks_controller.rb +7 -0
  16. data/app/controllers/users/registrations_controller.rb +7 -0
  17. data/app/controllers/users/sessions_controller.rb +6 -0
  18. data/app/controllers/users_controller.rb +25 -0
  19. data/app/helpers/bpluser/folders_helper_behavior.rb +11 -0
  20. data/app/helpers/folders_helper.rb +5 -0
  21. data/app/models/bpluser/folder.rb +21 -10
  22. data/app/models/bpluser/folder_item.rb +5 -7
  23. data/app/models/concerns/bpluser/users.rb +71 -0
  24. data/app/models/concerns/bpluser/validatable.rb +34 -0
  25. data/app/views/bookmarks/index.html.erb +58 -0
  26. data/app/views/bookmarks/update.js.erb +1 -0
  27. data/app/views/bpluser/folders/_folder.html.erb +36 -0
  28. data/app/views/catalog/_constraints.html.erb +14 -0
  29. data/app/views/catalog/_folder_item_control.html.erb +52 -0
  30. data/app/views/catalog/_save_search.html.erb +8 -0
  31. data/app/views/devise/confirmations/new.html.erb +14 -0
  32. data/app/views/devise/mailer/reset_password_instructions.html.erb +13 -0
  33. data/app/views/devise/passwords/edit.html.erb +32 -0
  34. data/app/views/devise/passwords/new.html.erb +30 -0
  35. data/app/views/devise/registrations/edit.html.erb +82 -0
  36. data/app/views/devise/registrations/new.html.erb +45 -0
  37. data/app/views/devise/sessions/new.html.erb +72 -0
  38. data/app/views/devise/shared/_links.erb +29 -0
  39. data/app/views/folder_items/create.js.erb +1 -0
  40. data/app/views/folder_items/destroy.js.erb +1 -0
  41. data/app/views/folder_items/item_actions.js.erb +2 -0
  42. data/app/views/folder_items/update.js.erb +1 -0
  43. data/app/views/folders/_in_folder.html.erb +3 -0
  44. data/app/views/folders/_new_edit_form_fields.html.erb +36 -0
  45. data/app/views/folders/edit.html.erb +25 -0
  46. data/app/views/folders/index.html.erb +67 -0
  47. data/app/views/folders/new.html.erb +26 -0
  48. data/app/views/folders/public_list.html.erb +41 -0
  49. data/app/views/folders/show.html.erb +82 -0
  50. data/app/views/saved_searches/index.html.erb +55 -0
  51. data/app/views/search_history/index.html.erb +57 -0
  52. data/app/views/shared/_folder_item_actions.html.erb +54 -0
  53. data/app/views/shared/_folder_tools.html.erb +4 -0
  54. data/app/views/shared/_tools.html.erb +16 -0
  55. data/app/views/shared/_user_util_links.html.erb +42 -0
  56. data/app/views/users/show.html.erb +33 -0
  57. data/config/locales/bpluser.en.yml +129 -0
  58. data/config/routes.rb +23 -2
  59. data/lib/bpluser/controller.rb +61 -0
  60. data/lib/bpluser/devise_guests_override.rb +21 -0
  61. data/lib/bpluser/engine.rb +27 -1
  62. data/lib/bpluser/version.rb +3 -1
  63. data/lib/bpluser.rb +21 -15
  64. data/lib/generators/bpluser/controller_generator.rb +29 -0
  65. data/lib/generators/bpluser/devise_generator.rb +40 -0
  66. data/lib/generators/bpluser/install_generator.rb +62 -0
  67. data/lib/generators/bpluser/templates/config/initializers/{devise.rb → devise.rb.bak} +0 -0
  68. data/lib/generators/bpluser/templates/config/locales/devise.en.yml +53 -0
  69. data/lib/generators/bpluser/templates/config/omniauth-polaris.yml +10 -15
  70. data/lib/generators/bpluser/templates/models/user.rb +3 -4
  71. data/lib/generators/bpluser/user_generator.rb +23 -0
  72. data/lib/tasks/bpluser_tasks.rake +27 -0
  73. metadata +132 -158
  74. data/app/controllers/bpluser/api_controller.rb +0 -8
  75. data/app/controllers/bpluser/users/omniauth_callbacks_controller.rb +0 -48
  76. data/app/controllers/bpluser/users/registrations_controller.rb +0 -35
  77. data/app/controllers/bpluser/users/sessions_controller.rb +0 -23
  78. data/app/models/bpluser/ability.rb +0 -22
  79. data/app/models/bpluser/application_record.rb +0 -5
  80. data/app/models/bpluser/concerns/users.rb +0 -190
  81. data/app/models/bpluser/concerns/validatable.rb +0 -47
  82. data/app/models/bpluser/user.rb~ +0 -213
  83. data/app/models/bpluser/user_institution.rb +0 -6
  84. data/app/models/bpluser/validatable.rb~ +0 -65
  85. data/lib/bpluser/routes.rb +0 -37
  86. data/lib/generators/bpluser/bpluser_generator.rb +0 -183
  87. data/lib/generators/bpluser/templates/config/hydra-ldap.yml +0 -33
  88. data/lib/generators/bpluser/templates/config/omniauth-facebook.yml +0 -14
  89. data/lib/generators/bpluser/templates/controllers/users/omniauth_callbacks_controller.rb +0 -3
  90. data/lib/generators/bpluser/templates/controllers/users/registrations_controller.rb +0 -3
  91. data/lib/generators/bpluser/templates/controllers/users/sessions_controller.rb +0 -3
  92. data/lib/generators/bpluser/templates/migrations/add_fields_to_user.rb +0 -22
  93. data/lib/generators/bpluser/templates/migrations/add_folder_items_to_folder.rb +0 -18
  94. data/lib/generators/bpluser/templates/migrations/add_folders_to_user.rb +0 -14
  95. data/lib/generators/bpluser/templates/migrations/create_institutions_for_users.rb +0 -16
  96. data/lib/generators/bpluser/templates/models/ability.rb +0 -4
  97. data/lib/generators/bpluser/templates/views/devise/registrations/edit.html.erb +0 -0
  98. data/lib/generators/bpluser/templates/views/devise/registrations/new.html.erb +0 -24
  99. data/lib/generators/bpluser/templates/views/devise/sessions/new.html.erb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8c08f03aeb2b30a9c376121bb846a875a8017858
4
- data.tar.gz: 3cba37e4217227705179c59b1dedb58eb134ed80
2
+ SHA256:
3
+ metadata.gz: 542e2ec27e1951726cb444ed5fca214b92259c6f789df4833863cdc0613febde
4
+ data.tar.gz: 76d39f975ba98651d264b6a887650a9b19de73ac078a03d77f244b10687ea0dc
5
5
  SHA512:
6
- metadata.gz: c12bedf51df1e6704e97955160b05707175d92f1541d82b4a05bcf0c2e6041345c7afb64f289453c3291734233ef324b004688d1619070ecad3d93ff0c58e3a2
7
- data.tar.gz: 1fe6280143a5784bc5cc8cf098719e660b6406d9cce0c4adc00b201641760ac853e678e6a7bdaa1fb0e1ed7144b23b64f6e263c930bb273829d39c76cb2cded0
6
+ metadata.gz: 58203dff5734d2c8756b3e5d83849091e31fb0acc6e19cbe57319a43f471d9f6f5a2bb7264a20c96912ceb5fb803eef03927a53748b366ce371268fd7ab1f362
7
+ data.tar.gz: 10d8f61f9fcd013c57b2faac5293a12b30ceb0e47042f3f49344a06a6bfec8e70189c39ffcff438a93835e1ff90cfc2b98e99cba37dd3f79ef30afb98bd9da71
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Bpluser
2
+
3
+ [![Build Status](https://travis-ci.com/boston-library/bpluser.svg?branch=master)](https://travis-ci.com/boston-library/bpluser) [![Coverage Status](https://coveralls.io/repos/github/boston-library/bpluser/badge.svg?branch=master)](https://coveralls.io/github/boston-library/bpluser?branch=master)
4
+
5
+ Rails engine for providing Devise-based user models and functionality for digital repository applications using
6
+ [CommonwealthVlrEngine](https://github.com/boston-library/commonwealth-vlr-engine).
7
+
8
+ This includes bookmarks (Blacklight default), custom folders, and saved searches.
9
+
10
+ # Requirements
11
+ - `ruby >= 2.6.10`
12
+ - `rails ~> 6.0.6`
13
+ - `postgres v12 or higher`
14
+
15
+ To install, add the following to your Gemfile:
16
+ ```ruby
17
+ gem 'bpluser', '~> 0.1.0'
18
+ # OR
19
+ gem 'bpluser', git: 'https://github.com/boston-library/bpluser'
20
+ ```
21
+ Then run:
22
+ ```
23
+ $ bundle install
24
+ $ rails generate bpluser:install
25
+ ```
26
+
27
+ When updating run
28
+
29
+ ```
30
+ rails bpluser:install:update_migrations
31
+ ```
32
+
33
+ (Note that the installer will ask to overwrite your local `config/locales/devise.en.yml`).
data/Rakefile CHANGED
@@ -1,15 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'bundler/setup'
3
5
  rescue LoadError
4
6
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
7
  end
6
8
 
7
- APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
9
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
8
10
  # load rake tasks defined in lib/tasks that are not loaded in lib/active_fedora.rb
9
11
  Dir['lib/tasks/*.rake'].each { |rake| load rake }
10
12
 
11
13
  load 'rails/tasks/engine.rake'
12
-
13
14
  load 'rails/tasks/statistics.rake'
14
15
 
15
- task :default => [:spec]
16
+ begin
17
+ require 'rubocop/rake_task'
18
+ RuboCop::RakeTask.new(:rubocop) do |task|
19
+ task.requires << 'rubocop-rspec'
20
+ task.requires << 'rubocop-performance'
21
+ task.requires << 'rubocop-rails'
22
+ task.fail_on_error = true
23
+ end
24
+ rescue LoadError
25
+ task rubocop: :environment do
26
+ warn 'Rubocop is disabled'
27
+ end
28
+ end
29
+
30
+ require 'solr_wrapper'
31
+ require 'solr_wrapper/rake_task'
32
+
33
+ require 'rspec/core/rake_task'
34
+ RSpec::Core::RakeTask.new
35
+
36
+ desc 'Lint, spin up Solr, index test docs, run test suite'
37
+ task ci: [:environment, :rubocop] do
38
+ SolrWrapper.wrap(port: 8984, version: '8.11.2', persist: false) do |solr|
39
+ solr.with_collection(name: 'blacklight-core', dir: 'spec/dummy/solr/conf/') do
40
+ system 'RAILS_ENV=test rake app:bpluser:test_index:seed'
41
+ Rake::Task['spec'].invoke
42
+ end
43
+ end
44
+ end
45
+
46
+ task default: [:ci]
@@ -0,0 +1 @@
1
+ //= link bpluser/folder_tools.js
@@ -0,0 +1,26 @@
1
+ // item actions for folders and bookmarks
2
+
3
+ $(document).ready ( function () {
4
+ // remove duplicate buttons from form
5
+ $('#cite_btn,#email_btn').remove();
6
+ // add click event for any checkbox in doc list
7
+ $(':checkbox[name="selected[]"]').click( function () {
8
+ addCheckedToURL();
9
+ });
10
+
11
+ // select/unselect all
12
+ $('#selectAllItems').click( function () {
13
+ $(':checkbox[name="selected[]"]').prop('checked', this.checked);
14
+ addCheckedToURL();
15
+ });
16
+ });
17
+
18
+
19
+ // when any checkbox is selected, append the ids of all checked items to url
20
+ function addCheckedToURL () {
21
+ var checkboxValues = $('[name="selected[]"]:checked').serialize();
22
+ checkboxValues = checkboxValues.replace(/selected/g,"id");
23
+ $('#citeLink,#emailLink,#copyLink').attr('href', function(index,previousValue) {
24
+ return previousValue.replace(/\?.*/,"?" + checkboxValues);
25
+ });
26
+ }
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ class BookmarksController < CatalogController
4
+ include Blacklight::Bookmarks
5
+
6
+ # LOCAL OVERRIDE to render update.js.erb partial when bookmark created
7
+ def create
8
+ @bookmarks = params[:bookmarks].present? ? bookmark_params : default_bookmark_params
9
+
10
+ current_or_guest_user.save! unless current_or_guest_user.persisted?
11
+
12
+ success = @bookmarks.all? do |bookmark|
13
+ next true if current_or_guest_user.bookmarks.exists?(bookmark)
14
+
15
+ begin
16
+ current_or_guest_user.bookmarks.create!(bookmark)
17
+ next true
18
+ rescue ActiveRecord::RecordInvalid
19
+ break false
20
+ end
21
+ end
22
+
23
+ if request.xhr?
24
+ # success ? render(json: { bookmarks: { count: current_or_guest_user.bookmarks.count }}) : render(:text => "", :status => "500")
25
+ success ? render(:update) : render(plain: '', status: '500')
26
+ else
27
+ if @bookmarks.any? && success
28
+ flash[:notice] = I18n.t('blacklight.bookmarks.add.success', count: @bookmarks.count)
29
+ elsif @bookmarks.any?
30
+ flash[:error] = I18n.t('blacklight.bookmarks.add.failure', count: @bookmarks.count)
31
+ end
32
+
33
+ redirect_back fallback_location: bookmarks_path
34
+ end
35
+ end
36
+
37
+ def folder_item_actions
38
+ redirect_to action: 'index'
39
+ end
40
+
41
+ private
42
+
43
+ def default_bookmark_params
44
+ [{ document_id: params[:id], document_type: blacklight_config.document_model.to_s }]
45
+ end
46
+
47
+ def bookmark_params
48
+ params.require(:bookmarks).map { |item_params| item_params.permit(:document_id, :document_type) }
49
+ end
50
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bpluser
4
+ module FoldersVerifyUser
5
+ # Concern that adds verify_user method for folder related controller endopints t('blacklight.folders.need_login')
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ include InstanceMethods
10
+ end
11
+
12
+ module InstanceMethods
13
+ protected
14
+
15
+ def verify_user
16
+ flash[:notice] = t('blacklight.folders.need_login') and raise Blacklight::Exceptions::AccessDenied unless current_user
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bpluser
4
+ module OmniauthCallbacks
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include InstanceMethods
9
+
10
+ skip_before_action :verify_authenticity_token, only: :polaris
11
+ end
12
+
13
+ module InstanceMethods
14
+ def polaris
15
+ @user = User.find_for_polaris_oauth(request.env['omniauth.auth'])
16
+
17
+ if @user.persisted?
18
+ sign_in_and_redirect @user, event: :authentication
19
+ set_flash_message(:notice, :success, kind: 'Polaris') if is_navigational_format?
20
+ else
21
+ session['devise.polaris_data'] = request.env['omniauth.auth'].except(:extra)
22
+ redirect_to new_user_registration_url
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bpluser
4
+ module Registrations
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include InstanceMethods
9
+ before_action :configure_permitted_parameters, only: [:create, :update], if: :devise_controller?
10
+ end
11
+
12
+ module InstanceMethods
13
+ # POST /resource
14
+ def create
15
+ if User.exists?(email: sign_up_params[:email])
16
+ flash[:error] = "An account with that email (#{sign_up_params[:email]}) already exists. Please sign in or click the \"Forgot your password?\" link below."
17
+ redirect_to new_user_session_path and return
18
+ end
19
+
20
+ super
21
+ end
22
+
23
+ protected
24
+
25
+ def configure_permitted_parameters
26
+ case params[:action]
27
+ when 'create'
28
+ devise_parameter_sanitizer.permit(:sign_up, keys: %i[first_name last_name])
29
+ when 'update'
30
+ devise_parameter_sanitizer.permit(:account_update, keys: %i[first_name last_name])
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ # copied from Blacklight 6.19.2 -- this feature is no longer provided by Blacklight >= 7
4
+ module Bpluser
5
+ module SavedSearches
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ include Blacklight::Configurable
10
+ copy_blacklight_config_from(CatalogController)
11
+ # before_action :require_user_authentication_provider This is deprecated
12
+ before_action :verify_user
13
+ end
14
+
15
+ def index
16
+ @searches = current_user.searches
17
+ end
18
+
19
+ def save
20
+ current_user.searches << searches_from_history.find(params[:id])
21
+
22
+ if current_user.save
23
+ flash[:notice] = t('blacklight.saved_searches.add.success')
24
+ else
25
+ flash[:error] = t('blacklight.saved_searches.add.failure')
26
+ end
27
+
28
+ redirect_back fallback_location: saved_searches_path
29
+ end
30
+
31
+ # Only dereferences the user rather than removing the item in case it
32
+ # is in the session[:history]
33
+ def forget
34
+ search = current_user.searches.find(params[:id])
35
+
36
+ if search.update(user_id: nil)
37
+ flash[:notice] = t('blacklight.saved_searches.remove.success')
38
+ else
39
+ flash[:error] = t('blacklight.saved_searches.remove.failure')
40
+ end
41
+
42
+ redirect_back fallback_location: saved_searches_path
43
+ end
44
+
45
+ # Only dereferences the user rather than removing the items in case they
46
+ # are in the session[:history]
47
+ def clear
48
+ if current_user.searches.all? { |s| s.update(user_id: nil) } && current_user.save
49
+ flash[:notice] = t('blacklight.saved_searches.clear.success')
50
+ else
51
+ flash[:error] = t('blacklight.saved_searches.clear.failure')
52
+ end
53
+ redirect_to saved_searches_url
54
+ end
55
+
56
+ protected
57
+
58
+ def verify_user
59
+ flash[:notice] = t('blacklight.saved_searches.need_login') and raise Blacklight::Exceptions::AccessDenied unless current_user
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # use to share folder item actions (email, cite, delete) between folders and bookmarks
4
+ class FolderItemsActionsController < ApplicationController
5
+ def folder_item_actions
6
+ @folder = Bpluser::Folder.find(params[:id]) if params[:origin] == 'folders'
7
+ @user = current_or_guest_user
8
+
9
+ unless params[:selected]
10
+ flash[:error] = t('blacklight.folders.update_items.remove.no_items')
11
+ redirect_back(fallback_location: root_path)
12
+ end
13
+
14
+ items = params[:selected]
15
+ case params[:commit]
16
+ # email
17
+ when t('blacklight.tools.email')
18
+ redirect_to email_solr_document_path(id: items)
19
+ # cite
20
+ when t('blacklight.tools.citation')
21
+ redirect_to citation_solr_document_path(id: items)
22
+ # remove
23
+ when t('blacklight.tools.remove')
24
+ if params[:origin] == 'folders'
25
+ if @folder.folder_items.destroy_by(document_id: items)
26
+ flash[:notice] = t('blacklight.folders.update_items.remove.success')
27
+ else
28
+ flash[:error] = t('blacklight.folders.update_items.remove.failure')
29
+ end
30
+ redirect_to folder_path(@folder, view_params)
31
+ else
32
+ if current_or_guest_user.bookmarks.destroy_by(document_id: items)
33
+ flash[:notice] = t('blacklight.folders.update_items.remove.success')
34
+ else
35
+ flash[:error] = t('blacklight.folders.update_items.remove.failure')
36
+ end
37
+ redirect_to bookmarks_path(view_params)
38
+ end
39
+ # copy
40
+ when /#{t('blacklight.tools.copy_to')}/
41
+ destination = params[:commit].split("#{t('blacklight.tools.copy_to')} ")[1]
42
+ if destination == t('blacklight.bookmarks.title')
43
+ success = items.all? do |item_id|
44
+ next true if current_or_guest_user.bookmarks.exists?(document_id: item_id)
45
+
46
+ current_or_guest_user.bookmarks.create(document_id: item_id)
47
+ end
48
+ else
49
+ folder_to_update = current_user.folders.find(destination)
50
+ success = items.all? do |item_id|
51
+ next true if folder_to_update.folder_item?(item_id)
52
+
53
+ begin
54
+ folder_to_update.folder_items.create!(document_id: item_id)
55
+ next true
56
+ rescue ActiveRecord::RecordInvalid
57
+ break false
58
+ end
59
+ end
60
+ end
61
+
62
+ if success
63
+ folder_display_name = destination == t('blacklight.bookmarks.title') ? t('blacklight.bookmarks.title') : folder_to_update.title
64
+ flash[:notice] = t('blacklight.folders.update_items.copy.success', folder_name: folder_display_name)
65
+ else
66
+ flash[:error] = t('blacklight.folders.update_items.copy.failure')
67
+ end
68
+ redirect_back(fallback_location: root_path)
69
+ end
70
+ end
71
+
72
+ private
73
+
74
+ def view_params
75
+ params.permit(:sort, :per_page, :view)
76
+ end
77
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FolderItemsController < CatalogController
4
+ include Bpluser::FoldersVerifyUser
5
+
6
+ before_action :verify_user
7
+
8
+ def create
9
+ @response, @document = search_service.fetch(params[:id])
10
+
11
+ @folder_items = params[:folder_items].present? ? folder_items_params : default_folder_item_params
12
+
13
+ success = @folder_items.all? do |f_item|
14
+ folder_to_update = current_user.folders.find(f_item[:folder_id])
15
+
16
+ next true if folder_to_update.folder_item?(f_item[:document_id])
17
+
18
+ begin
19
+ folder_to_update.folder_items.create!(document_id: f_item[:document_id])
20
+ next true
21
+ rescue ActiveRecord::RecordInvalid
22
+ break false
23
+ end
24
+ end
25
+
26
+ unless request.xhr?
27
+ if success
28
+ flash[:notice] = t('blacklight.folder_items.add.success')
29
+ else
30
+ flash[:error] = t('blacklight.folder_items.add.failure')
31
+ end
32
+ end
33
+
34
+ respond_to do |format|
35
+ format.html { redirect_back(fallback_location: root_path) }
36
+ format.js
37
+ end
38
+ end
39
+
40
+ def update
41
+ create
42
+ end
43
+
44
+ # Beware, :id is the Solr document_id, not the actual Bookmark id.
45
+ # idempotent, as DELETE is supposed to be.
46
+ # PRETTY SURE THIS METHOD IS NEVER USED!
47
+ def destroy
48
+ @response, @document = search_service.fetch(params[:id])
49
+ folder_item = current_user.existing_folder_item_for(params[:id])
50
+
51
+ Bpluser::FolderItem.find(folder_item.id).destroy
52
+
53
+ respond_to do |format|
54
+ format.html { redirect_back(fallback_location: root_path) }
55
+ format.js
56
+ end
57
+ end
58
+
59
+ def clear
60
+ @folder = current_user.folders.find(params[:id])
61
+
62
+ if @folder.folder_items.clear && @folder.save
63
+ flash[:notice] = t('blacklight.folder_items.clear.success')
64
+ else
65
+ flash[:error] = t('blacklight.folder_items.clear.failure')
66
+ end
67
+ redirect_to folders_path(@folder)
68
+ end
69
+
70
+ # PRETTY SURE THIS METHOD IS NEVER USED!
71
+ def delete_selected
72
+ @folder = Bpluser::Folder.find(params[:id])
73
+
74
+ if params[:selected]
75
+ if @folder.folder_items.destroy_by(document_id: params[:selected])
76
+ flash[:notice] = t('blacklight.folders.update_items.remove.success')
77
+ else
78
+ flash[:error] = t('blacklight.folders.update_items.remove.failure')
79
+ end
80
+
81
+ redirect_to folders_path(@folder)
82
+ else
83
+ flash[:error] = t('blacklight.folders.update_items.remove.no_items')
84
+ redirect_back(fallback_location: root_path)
85
+ end
86
+ end
87
+
88
+ protected
89
+
90
+ def default_folder_item_params
91
+ [{ document_id: params[:id], folder_id: params[:folder_id] }]
92
+ end
93
+
94
+ def folder_items_params
95
+ params.require(:folder_items).map { |fi_params| fi_params.permit(:document_id, :folder_id) }
96
+ end
97
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FoldersController < CatalogController
4
+ ##
5
+ # Give Bookmarks access to the CatalogController configuration
6
+ include Blacklight::Configurable
7
+ include Blacklight::TokenBasedUser
8
+ include Bpluser::FoldersVerifyUser
9
+
10
+ copy_blacklight_config_from(CatalogController)
11
+
12
+ # Blacklight uses #search_action_url to figure out the right URL for
13
+ # the global search box
14
+ def search_action_url(options = {})
15
+ search_catalog_url(options.except(:controller, :action))
16
+ end
17
+ helper_method :search_action_url
18
+
19
+ before_action :verify_user, except: [:index, :show, :public_list]
20
+ before_action :check_visibility, only: [:show]
21
+ before_action :correct_user_for_folder, only: [:update, :edit, :destroy]
22
+
23
+ blacklight_config.track_search_session = false
24
+ blacklight_config.http_method = Blacklight::Engine.config.bookmarks_http_method
25
+
26
+ def index
27
+ @folders = current_or_guest_user.folders.with_folder_items if current_or_guest_user
28
+ end
29
+
30
+ def show
31
+ # @folder is set by correct_user_for_folder
32
+ @folder_items = @folder.folder_items
33
+ folder_items_ids = @folder_items.pluck(:document_id)
34
+ params[:sort] ||= 'title_info_primary_ssort asc, date_start_dtsi asc'
35
+ @response, @document_list = search_service.fetch(folder_items_ids)
36
+ end
37
+
38
+ def new
39
+ @folder = current_user.folders.build
40
+ end
41
+
42
+ def edit; end
43
+
44
+ def create
45
+ @folder = current_user.folders.new(folder_params)
46
+
47
+ if @folder.save
48
+ flash[:notice] = t('blacklight.folders.create.success')
49
+ redirect_to action: 'index'
50
+ else
51
+ render action: 'new'
52
+ end
53
+ end
54
+
55
+ def update
56
+ # @folder is set by correct_user_for_folder
57
+ if @folder.update(folder_params)
58
+ flash[:notice] = t('blacklight.folders.update.success')
59
+ redirect_to @folder
60
+ else
61
+ render action: :edit
62
+ end
63
+ end
64
+
65
+ def destroy
66
+ # @folder is set by correct_user_for_folder
67
+ @folder.destroy
68
+ flash[:notice] = t('blacklight.folders.delete.success')
69
+ redirect_to action: 'index'
70
+ end
71
+
72
+ # return a list of publicly visible folders that have items
73
+ def public_list
74
+ @folders = Bpluser::Folder.public_list
75
+ end
76
+
77
+ private
78
+
79
+ def folder_params
80
+ params.require(:folder).permit(:title, :description, :visibility)
81
+ end
82
+
83
+ def check_visibility
84
+ @folder = Bpluser::Folder.with_folder_items.find(params[:id])
85
+
86
+ return if @folder&.public?
87
+
88
+ correct_user_for_folder
89
+ end
90
+
91
+ def correct_user_for_folder
92
+ @folder ||= Bpluser::Folder.with_folder_items.find(params[:id])
93
+
94
+ if current_or_guest_user
95
+ flash[:notice] = t('blacklight.folders.private') and redirect_to root_path unless current_or_guest_user.folders.include?(@folder)
96
+ else
97
+ flash[:notice] = t('blacklight.folders.private') and redirect_to root_path
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SavedSearchesController < ApplicationController
4
+ include Bpluser::SavedSearches
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Users
4
+ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
5
+ include Bpluser::OmniauthCallbacks
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Users
4
+ class RegistrationsController < Devise::RegistrationsController
5
+ include Bpluser::Registrations
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Users
4
+ class SessionsController < Devise::SessionsController
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UsersController < ApplicationController
4
+ before_action :authenticate_user!, :correct_user, only: [:show]
5
+
6
+ # getting some weird intermittent errors where users are being redirected
7
+ # to '/users' after signup. this is a failsafe last-resort solution
8
+ def index
9
+ redirect_to root_path
10
+ end
11
+
12
+ def show
13
+ respond_to do |format|
14
+ format.html
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def correct_user
21
+ @user = User.find(params[:id])
22
+
23
+ redirect_to root_path unless current_user == @user
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bpluser
4
+ module FoldersHelperBehavior
5
+ def folder_belongs_to_user(folder)
6
+ return false if folder.blank?
7
+
8
+ current_or_guest_user.folders.include?(folder)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FoldersHelper
4
+ include Bpluser::FoldersHelperBehavior
5
+ end