From 85cfbd561dd98e01ca9dbcb9e4856dad4e30a866 Mon Sep 17 00:00:00 2001 From: Charles Pletcher Date: Mon, 27 Jul 2020 18:24:40 -0400 Subject: [PATCH 1/6] Enable inviting users with devise_invitable Need to test emails, but this seems promising --- Gemfile | 1 + Gemfile.lock | 4 ++ .../users/invitations_controller.rb | 9 ++++ app/controllers/users_controller.rb | 2 +- app/models/user.rb | 2 +- app/views/admin/index.html.haml | 2 +- app/views/users/invitations/edit.html.erb | 15 ++++++ app/views/users/invitations/new.html.erb | 19 +++++++ .../mailer/invitation_instructions.html.erb | 11 ++++ .../mailer/invitation_instructions.text.erb | 11 ++++ config/initializers/devise.rb | 51 ++++++++++++++++++- config/locales/devise_invitable.en.yml | 31 +++++++++++ config/routes.rb | 4 +- ...727210248_devise_invitable_add_to_users.rb | 23 +++++++++ db/schema.rb | 14 ++++- 15 files changed, 193 insertions(+), 6 deletions(-) create mode 100644 app/controllers/users/invitations_controller.rb create mode 100644 app/views/users/invitations/edit.html.erb create mode 100644 app/views/users/invitations/new.html.erb create mode 100644 app/views/users/mailer/invitation_instructions.html.erb create mode 100644 app/views/users/mailer/invitation_instructions.text.erb create mode 100644 config/locales/devise_invitable.en.yml create mode 100644 db/migrate/20200727210248_devise_invitable_add_to_users.rb diff --git a/Gemfile b/Gemfile index 5e8257309..ca39f3910 100644 --- a/Gemfile +++ b/Gemfile @@ -122,6 +122,7 @@ end gem "devise" gem "devise-guests", "~> 0.3" +gem 'devise_invitable', '~> 2.0.0' gem "cancancan" gem "rsolr" diff --git a/Gemfile.lock b/Gemfile.lock index a49f0c256..4b6d10306 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -172,6 +172,9 @@ GEM warden (~> 1.2.3) devise-guests (0.7.0) devise + devise_invitable (2.0.2) + actionmailer (>= 5.0) + devise (>= 4.6) diff-lcs (1.3) discard (1.2.0) activerecord (>= 4.2, < 7) @@ -624,6 +627,7 @@ DEPENDENCIES coffee-rails (~> 5.0.0) devise devise-guests (~> 0.3) + devise_invitable (~> 2.0.0) discard (~> 1.2) exception_notification factory_bot_rails diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb new file mode 100644 index 000000000..037107b83 --- /dev/null +++ b/app/controllers/users/invitations_controller.rb @@ -0,0 +1,9 @@ +class Users::InvitationsController < Devise::InvitationsController + before_action :verify_admin + + protected + + def verify_admin + !current_user.admin_at.nil? + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9f314a161..5d1ee1705 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,7 +2,7 @@ class UsersController < CatalogController self.copy_blacklight_config_from(CatalogController) before_action :check_for_logged_in_user, :only => [:my_tapas, :my_projects] - before_action :verify_admin, :only => [:index, :show, :create, :delete] + before_action :verify_admin, :only => [:index, :show, :create, :delete, :admin_show] def my_tapas @page_title = "My TAPAS" diff --git a/app/models/user.rb b/app/models/user.rb index 5f4c748d8..f392f0dd9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,7 +17,7 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable - devise :database_authenticatable, :registerable, + devise :invitable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable delegate :can?, :cannot?, :to => :ability diff --git a/app/views/admin/index.html.haml b/app/views/admin/index.html.haml index 555d9f944..94d51292c 100644 --- a/app/views/admin/index.html.haml +++ b/app/views/admin/index.html.haml @@ -33,7 +33,7 @@ %h3 = "Users" -=link_to "Create New User", new_user_registration_path, class:['btn', 'btn-primary', 'btn-large'] +=link_to "Create New User", new_user_invitation_path, class:['btn', 'btn-primary', 'btn-large'] %br =link_to "View all Users", users_path, class:['btn', 'btn-primary', 'btn-large'] %br diff --git a/app/views/users/invitations/edit.html.erb b/app/views/users/invitations/edit.html.erb new file mode 100644 index 000000000..356ffe6d2 --- /dev/null +++ b/app/views/users/invitations/edit.html.erb @@ -0,0 +1,15 @@ +

<%= t "devise.invitations.edit.header" %>

+ +<%= simple_form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :put }) do |f| %> + <%= f.error_notification %> + <%= f.hidden_field :invitation_token %> + +
+ <%= f.input :password %> + <%= f.input :password_confirmation %> +
+ +
+ <%= f.button :submit, t("devise.invitations.edit.submit_button") %> +
+<% end %> diff --git a/app/views/users/invitations/new.html.erb b/app/views/users/invitations/new.html.erb new file mode 100644 index 000000000..3aa8c317e --- /dev/null +++ b/app/views/users/invitations/new.html.erb @@ -0,0 +1,19 @@ +

<%= t "devise.invitations.new.header" %>

+ +<%= simple_form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :post }) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :name, required: true %> +
+ + <% resource.class.invite_key_fields.each do |field| -%> +
+ <%= f.input field, required: true %> +
+ <% end -%> + +
+ <%= f.button :submit, t("devise.invitations.new.submit_button") %> +
+<% end %> diff --git a/app/views/users/mailer/invitation_instructions.html.erb b/app/views/users/mailer/invitation_instructions.html.erb new file mode 100644 index 000000000..27a1c0c4c --- /dev/null +++ b/app/views/users/mailer/invitation_instructions.html.erb @@ -0,0 +1,11 @@ +

<%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %>

+ +

<%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %>

+ +

<%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token) %>

+ +<% if @resource.invitation_due_at %> +

<%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) %>

+<% end %> + +

<%= t("devise.mailer.invitation_instructions.ignore") %>

diff --git a/app/views/users/mailer/invitation_instructions.text.erb b/app/views/users/mailer/invitation_instructions.text.erb new file mode 100644 index 000000000..f4912bf46 --- /dev/null +++ b/app/views/users/mailer/invitation_instructions.text.erb @@ -0,0 +1,11 @@ +<%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %> + +<%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %> + +<%= accept_invitation_url(@resource, invitation_token: @token) %> + +<% if @resource.invitation_due_at %> + <%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) %> +<% end %> + +<%= t("devise.mailer.invitation_instructions.ignore") %> diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 0aed4e8b2..7b1375d28 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -95,6 +95,55 @@ # Setup a pepper to generate the encrypted password. # config.pepper = '2f4245541163a6b54b92b6995f8414d024128079eee62e09513e9f3885201e007d9e6a1203cd998057175c14ef4d011312f3e15bfd06d9c2188e895f8b6553b3' + # ==> Configuration for :invitable + # The period the generated invitation token is valid. + # After this period, the invited resource won't be able to accept the invitation. + # When invite_for is 0 (the default), the invitation won't expire. + # config.invite_for = 2.weeks + + # Number of invitations users can send. + # - If invitation_limit is nil, there is no limit for invitations, users can + # send unlimited invitations, invitation_limit column is not used. + # - If invitation_limit is 0, users can't send invitations by default. + # - If invitation_limit n > 0, users can send n invitations. + # You can change invitation_limit column for some users so they can send more + # or less invitations, even with global invitation_limit = 0 + # Default: nil + # config.invitation_limit = 5 + + # The key to be used to check existing users when sending an invitation + # and the regexp used to test it when validate_on_invite is not set. + # config.invite_key = { email: /\A[^@]+@[^@]+\z/ } + # config.invite_key = { email: /\A[^@]+@[^@]+\z/, username: nil } + + # Ensure that invited record is valid. + # The invitation won't be sent if this check fails. + # Default: false + # config.validate_on_invite = true + + # Resend invitation if user with invited status is invited again + # Default: true + # config.resend_invitation = false + + # The class name of the inviting model. If this is nil, + # the #invited_by association is declared to be polymorphic. + # Default: nil + # config.invited_by_class_name = 'User' + + # The foreign key to the inviting model (if invited_by_class_name is set) + # Default: :invited_by_id + # config.invited_by_foreign_key = :invited_by_id + + # The column name used for counter_cache column. If this is nil, + # the #invited_by association is declared without counter_cache. + # Default: nil + # config.invited_by_counter_cache = :invitations_count + + # Auto-login after the user accepts the invite. If this is false, + # the user will need to manually log in after accepting the invite. + # Default: true + # config.allow_insecure_sign_in_after_accept = false + # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without # confirming their account. For instance, if set to 2.days, the user will be @@ -201,7 +250,7 @@ # Turn scoped views on. Before rendering "sessions/new", it will first check for # "users/sessions/new". It's turned off by default because it's slower if you # are using only default views. - # config.scoped_views = false + config.scoped_views = true # Configure the default scope given to Warden. By default it's the first # devise role declared in your routes (usually :user). diff --git a/config/locales/devise_invitable.en.yml b/config/locales/devise_invitable.en.yml new file mode 100644 index 000000000..f6bfee403 --- /dev/null +++ b/config/locales/devise_invitable.en.yml @@ -0,0 +1,31 @@ +en: + devise: + failure: + invited: "You have a pending invitation, accept it to finish creating your account." + invitations: + send_instructions: "An invitation email has been sent to %{email}." + invitation_token_invalid: "The invitation token provided is not valid!" + updated: "Your password was set successfully. You are now signed in." + updated_not_active: "Your password was set successfully." + no_invitations_remaining: "No invitations remaining" + invitation_removed: "Your invitation was removed." + new: + header: "Send invitation" + submit_button: "Send an invitation" + edit: + header: "Set your password" + submit_button: "Set my password" + mailer: + invitation_instructions: + subject: "Invitation instructions" + hello: "Hello %{email}" + someone_invited_you: "Someone has invited you to %{url}, you can accept it through the link below." + accept: "Accept invitation" + accept_until: "This invitation will be due in %{due_date}." + 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 and set your password." + time: + formats: + devise: + mailer: + invitation_instructions: + accept_until_format: "%B %d, %Y %I:%M %p" diff --git a/config/routes.rb b/config/routes.rb index 3634c5849..73fc607c0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,7 @@ root :to => "view_packages#index" # blacklight_for :catalog - devise_for :users + devise_for :users, controllers: { invitations: 'users/invitations' } # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". @@ -80,7 +80,9 @@ get 'my_projects' => 'users#my_projects' get 'my_collections' => 'users#my_collections' get 'my_records' => 'users#my_records' + get 'admin/users/new' => 'users#admin_new', as: 'admin_new_user' get 'admin/users/:id' => 'users#admin_show' + post 'admin/users' => 'users#admin_create', as: 'admin_create_user' get 'users/:id' => 'users#profile' get 'mail_users' => 'users#mail_all_users', as: 'mail_users' post 'mail_users' => 'users#mail_all_users' diff --git a/db/migrate/20200727210248_devise_invitable_add_to_users.rb b/db/migrate/20200727210248_devise_invitable_add_to_users.rb new file mode 100644 index 000000000..5fca629f1 --- /dev/null +++ b/db/migrate/20200727210248_devise_invitable_add_to_users.rb @@ -0,0 +1,23 @@ +class DeviseInvitableAddToUsers < ActiveRecord::Migration[5.2] + def up + change_table :users do |t| + t.string :invitation_token + t.datetime :invitation_created_at + t.datetime :invitation_sent_at + t.datetime :invitation_accepted_at + t.integer :invitation_limit + t.references :invited_by, polymorphic: true + t.integer :invitations_count, default: 0 + t.index :invitations_count + t.index :invitation_token, unique: true # for invitable + t.index :invited_by_id + end + end + + def down + change_table :users do |t| + t.remove_references :invited_by, polymorphic: true + t.remove :invitations_count, :invitation_limit, :invitation_sent_at, :invitation_accepted_at, :invitation_token, :invitation_created_at + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 1f097f450..e9651810a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_07_26_221259) do +ActiveRecord::Schema.define(version: 2020_07_27_210248) do create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name", null: false @@ -337,10 +337,22 @@ t.datetime "admin_at" t.datetime "paid_at" t.datetime "discarded_at" + t.string "invitation_token" + t.datetime "invitation_created_at" + t.datetime "invitation_sent_at" + t.datetime "invitation_accepted_at" + t.integer "invitation_limit" + t.string "invited_by_type" + t.bigint "invited_by_id" + t.integer "invitations_count", default: 0 t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["discarded_at"], name: "index_users_on_discarded_at" t.index ["email"], name: "index_users_on_email", unique: true t.index ["institution_id"], name: "index_users_on_institution_id" + t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true + t.index ["invitations_count"], name: "index_users_on_invitations_count" + t.index ["invited_by_id"], name: "index_users_on_invited_by_id" + t.index ["invited_by_type", "invited_by_id"], name: "index_users_on_invited_by_type_and_invited_by_id" t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end From f9c61110a57459bd635019a430f435c1a17b0846 Mon Sep 17 00:00:00 2001 From: Charles Pletcher Date: Sat, 1 Aug 2020 11:47:39 -0400 Subject: [PATCH 2/6] Allow admin overrides on users Admins can set paid and admin status Users can update everything else on their own (which admins can also update) --- app/controllers/users_controller.rb | 62 +++++++---------------------- app/models/user.rb | 16 ++++++++ app/views/users/edit.html.haml | 14 ++++--- 3 files changed, 40 insertions(+), 52 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5d1ee1705..03f7ba2be 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -60,22 +60,15 @@ def profile def edit @user = User.find(params[:id]) - i_s = Institution.all() - @institutions = [] - i_s.each do |i| - @institutions << [i.name, i.id] - end + @institutions = Institution.select(:name, :id) end def update @user = User.find(params[:id]) - @user.name = params[:user][:name] - @user.email = params[:user][:email] - @user.role = params[:user][:role] - @user.account_type = params[:user][:account_type] - @user.institution = Institution.find(params[:user][:institution_id]) - @user.save! - redirect_to @user + @user.update(user_params) + flash[:notice] = "#{@user.email} was updated" + + redirect_to edit_user_path(@user) end def destroy @@ -112,7 +105,16 @@ def mail_all_users end end - private + def user_params + params.require(:user).permit( + :name, + :email, + :institution_id, + :account_type, + :admin, + :paid + ) + end def five_communities @user.communities.kept.limit(5).order("RAND()") @@ -134,40 +136,6 @@ def five_records .order("RAND()") end - def my_communities_filter(solr_parameters, user_parameters) - model_type = RSolr.solr_escape "info:fedora/afmodel:Community" - query = "has_model_ssim:\"#{model_type}\" && (project_members_ssim:\"#{@user.id.to_s}\" OR depositor_tesim:\"#{@user.id.to_s}\" OR project_admins_ssim:\"#{@user.id.to_s}\" OR project_editors_ssim:\"#{@user.id.to_s}\")" - logger.error query - solr_parameters[:fq] ||= [] - solr_parameters[:fq] << query - end - - def my_collections_filter(solr_parameters, user_parameters) - model_type = RSolr.solr_escape "info:fedora/afmodel:Collection" - projects = ActiveFedora::SolrService.query("has_model_ssim:\"#{RSolr.solr_escape "info:fedora/afmodel:Community"}\" && (project_members_ssim:\"#{@user.id.to_s}\" OR depositor_tesim:\"#{@user.id.to_s}\" OR project_admins_ssim:\"#{@user.id.to_s}\" OR project_editors_ssim:\"#{@user.id.to_s}\")") - col_query = projects.map do |p| - "project_pid_ssi: #{RSolr.solr_escape(p['id'])}" - end - solr_parameters[:fq] ||= [] - solr_parameters[:fq] << col_query.join(" OR ") - solr_parameters[:fq] << "has_model_ssim: \"#{model_type}\"" - end - - def my_records_filter(solr_parameters, user_parameters) - model_type = RSolr.solr_escape "info:fedora/afmodel:CoreFile" - projects = ActiveFedora::SolrService.query("has_model_ssim:\"#{RSolr.solr_escape "info:fedora/afmodel:Community"}\" && (project_members_ssim:\"#{@user.id.to_s}\" OR depositor_tesim:\"#{@user.id.to_s}\" OR project_admins_ssim:\"#{@user.id.to_s}\" OR project_editors_ssim:\"#{@user.id.to_s}\")") - col_query = projects.map do |p| - "project_pid_ssi: #{RSolr.solr_escape(p['id'])}" - end - collections = ActiveFedora::SolrService.query("has_model_ssim:\"#{RSolr.solr_escape "info:fedora/afmodel:Collection"}\" && (#{col_query.join(" OR ")})") - rec_query = collections.map do |y| - "collections_pids_ssim: \"#{RSolr.solr_escape(y['id'])}\"" - end - solr_parameters[:fq] ||= [] - solr_parameters[:fq] << rec_query.join(" OR ") - solr_parameters[:fq] << "has_model_ssim: \"#{model_type}\"" - end - def check_for_logged_in_user redirect_to new_user_session_path if current_user.nil? end diff --git a/app/models/user.rb b/app/models/user.rb index f392f0dd9..b55e68c7c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -49,10 +49,26 @@ def user_key self.id.to_s end + def admin=(n) + if n.to_i == 0 + update(admin_at: nil) + else + update(admin_at: Time.zone.now) + end + end + def admin? !admin_at.nil? end + def paid=(n) + if n.to_i == 0 + update(paid_at: nil) + else + update(paid_at: Time.zone.now) + end + end + def paid_user? !paid_at.nil? end diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 03afe3ec2..90b58137b 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -15,20 +15,24 @@ .col-md-6 = f.text_field :email, required: true, class: "form-control", placeholder: "Email" .form-group - = f.label :institution, "Institution", class: "control-label col-md-2" + = f.label :institution_id, "Institution", class: "control-label col-md-2" .col-md-6 - = f.collection_select(:institution_id, Institution.all, :id, :name, :prompt => 'Please select institution') + = f.select :institution_id, options_for_select(@institutions.map { |i| [i.name, i.id] }, @user.institution_id), required: true, include_blank: true .form-group = f.label :account_type, "Account Type", class: "control-label col-md-2" .col-md-6 = f.select :account_type, options_for_select([['Free Account', 'free'], ['TEI-C Member Account', 'teic'], ['TEI-C Member via my institution', 'teic_inst']], @user.account_type), {} - if current_user.admin? .form-group - = f.label :role, "Admin", class: "control-label col-md-2" + = f.label :admin, "Admin?", class: "control-label col-md-2" .col-md-6 .checkbox - = f.select :role, options_for_select([['Admin', 'admin'], ['Unpaid User', 'unpaid_user'], ['Paid User', 'paid_user']], @user.role), {} - + = f.check_box :admin, {:checked => !@user.admin_at.nil?} + .form-group + = f.label :paid, "Paid?", class: "control-label col-md-2" + .col-md-6 + .checkbox + = f.check_box :paid, {:checked => !@user.paid_at.nil?} %hr .form-actions = f.submit class: ['btn', 'btn-primary', 'btn-large'], value: 'Submit' From d7c67f3ac55bcd63d752921054b1a70558e5a150 Mon Sep 17 00:00:00 2001 From: Charles Pletcher Date: Tue, 4 Aug 2020 20:04:32 -0400 Subject: [PATCH 3/6] Fix records browse view We will need to manually update the Solr/Blacklight stuff now that this is mostly working --- app/controllers/users_controller.rb | 6 ++--- app/views/catalog/_search_results.html.erb | 28 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 03f7ba2be..5914316b3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -24,16 +24,14 @@ def my_projects def my_collections @page_title = "My Collections" @user = current_user - # self.search_params_logic += [:my_collections_filter] - (@collections, @document_list) = search_results(params) #, search_params_logic) + @collections = Collection.kept.where(depositor_id: @user.id) render 'my_collections' end def my_records @page_title = "My Records" @user = current_user - # self.search_params_logic += [:my_records_filter] - (@records, @document_list) = search_results(params) #, search_params_logic) + @records = CoreFile.kept.where(depositor_id: @user.id) render 'my_records' end diff --git a/app/views/catalog/_search_results.html.erb b/app/views/catalog/_search_results.html.erb index 04ce47073..01c8b71c1 100644 --- a/app/views/catalog/_search_results.html.erb +++ b/app/views/catalog/_search_results.html.erb @@ -5,6 +5,34 @@ <%= render 'catalog/search_header' %>

<%= t('blacklight.search.search_results') %>

+ + + + + + + + + <%- @records.map do |r| %> + + + + + + + <% end %> +
TitleDescriptionDepositorActions
+ <%= r.title %> + + <%= r.description %> + + <%= r.depositor.email %> + + <%- if can? :manage, r %> + Edit + Delete + <% end %> +
<%- if @response.empty? %> <%= render "zero_results" %> <%- end %> From a30f254a44e6295e4f09afa3d96ee1fd56ce5c28 Mon Sep 17 00:00:00 2001 From: Charles Pletcher Date: Tue, 4 Aug 2020 20:24:52 -0400 Subject: [PATCH 4/6] Fix results for UsersController#{my_projects,my_collections,my_records} There's a bit of a janky string substitution because the models for Projects and Records have different names internally (Communities and CoreFiles, respectively) --- app/controllers/users_controller.rb | 6 +++--- app/views/catalog/_search_results.html.erb | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5914316b3..d6aa4b31a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -16,7 +16,7 @@ def my_tapas def my_projects @page_title = "My Projects" @user = current_user - @projects = @user.communities + @results = @user.communities render 'my_projects' end @@ -24,14 +24,14 @@ def my_projects def my_collections @page_title = "My Collections" @user = current_user - @collections = Collection.kept.where(depositor_id: @user.id) + @results = Collection.kept.accessible_by(current_ability) render 'my_collections' end def my_records @page_title = "My Records" @user = current_user - @records = CoreFile.kept.where(depositor_id: @user.id) + @results = CoreFile.kept.accessible_by(current_ability) render 'my_records' end diff --git a/app/views/catalog/_search_results.html.erb b/app/views/catalog/_search_results.html.erb index 01c8b71c1..a34a17fa6 100644 --- a/app/views/catalog/_search_results.html.erb +++ b/app/views/catalog/_search_results.html.erb @@ -13,7 +13,7 @@ Depositor Actions - <%- @records.map do |r| %> + <%- @results.map do |r| %> <%= r.title %> @@ -26,13 +26,10 @@ <%- if can? :manage, r %> - Edit - Delete + Edit + Delete <% end %> <% end %> -<%- if @response.empty? %> - <%= render "zero_results" %> -<%- end %> From 7f443e846965424cf142ed81700ef76558a4869a Mon Sep 17 00:00:00 2001 From: Charles Pletcher Date: Fri, 14 Aug 2020 17:33:57 -0400 Subject: [PATCH 5/6] Make sure Projects load in browse view --- app/controllers/catalog_controller.rb | 2 +- app/controllers/communities_controller.rb | 6 ++---- app/views/catalog/_search_results.html.erb | 24 +++++++++++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index cceb0b7b5..271b7da99 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -1,5 +1,5 @@ -# -*- encoding : utf-8 -*- require 'blacklight/catalog' + class CatalogController < ApplicationController include Blacklight::Catalog include Hydra::Controller::ControllerBehavior diff --git a/app/controllers/communities_controller.rb b/app/controllers/communities_controller.rb index a22dd34be..c7a6f3b70 100644 --- a/app/controllers/communities_controller.rb +++ b/app/controllers/communities_controller.rb @@ -1,8 +1,6 @@ -class CommunitiesController < CatalogController +class CommunitiesController < ApplicationController include ApiAccessible - self.copy_blacklight_config_from(CatalogController) - before_action :can_edit?, only: [:edit, :update, :destroy] before_action :can_read?, :only => :show # before_action :enforce_show_permissions, :only=>:index @@ -23,7 +21,7 @@ def upsert def index @page_title = "All Projects" - (@response, @document_list) = search_results(params) + @results = Community.all respond_to do |format| format.html { render :template => 'shared/index' } diff --git a/app/views/catalog/_search_results.html.erb b/app/views/catalog/_search_results.html.erb index a34a17fa6..3eb5ca7c7 100644 --- a/app/views/catalog/_search_results.html.erb +++ b/app/views/catalog/_search_results.html.erb @@ -22,12 +22,30 @@ <%= r.description %> - <%= r.depositor.email %> + <%= r.depositor.nil? ? "No depositor on file" : r.depositor.email %> <%- if can? :manage, r %> - Edit - Delete + Edit + Delete <% end %> From c82e77aa47e949b45b8b2c3b45823ff6db65e224 Mon Sep 17 00:00:00 2001 From: Charles Pletcher Date: Mon, 17 Aug 2020 11:04:41 -0400 Subject: [PATCH 6/6] Fix browse view for CoreFiles and Collections --- app/controllers/collections_controller.rb | 5 ++--- app/controllers/core_files_controller.rb | 4 ++-- app/views/catalog/_facets.html.erb | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index 784441b3b..a8b1a624a 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -19,9 +19,8 @@ def upsert def index @page_title = "All Collections" - # self.search_params_logic += [:collections_filter] - # self.search_params_logic += [:add_access_controls_to_solr_params] - (@response, @document_list) = search_results(params) #, search_params_logic) + @results = Collection.order(updated_at: :desc) + respond_to do |format| format.html { render :template => 'shared/index' } format.js { render :template => 'shared/index', :layout => false } diff --git a/app/controllers/core_files_controller.rb b/app/controllers/core_files_controller.rb index 0a3a096ce..db6053b7a 100644 --- a/app/controllers/core_files_controller.rb +++ b/app/controllers/core_files_controller.rb @@ -22,8 +22,8 @@ class CoreFilesController < CatalogController def index @page_title = "All CoreFiles" - # self.search_params_logic += [:core_files_filter] - (@response, @document_list) = search_results(params) #, search_params_logic) + @results = CoreFile.order(updated_at: :desc) + respond_to do |format| format.html { render :template => 'shared/index' } format.js { render :template => 'shared/index', :layout => false } diff --git a/app/views/catalog/_facets.html.erb b/app/views/catalog/_facets.html.erb index 7c4bc1ce0..571265349 100644 --- a/app/views/catalog/_facets.html.erb +++ b/app/views/catalog/_facets.html.erb @@ -14,5 +14,6 @@
+