diff --git a/app/controllers/admin/submissions_controller.rb b/app/controllers/admin/submissions_controller.rb index 27503d63f..513fa7068 100644 --- a/app/controllers/admin/submissions_controller.rb +++ b/app/controllers/admin/submissions_controller.rb @@ -16,6 +16,12 @@ def dashboard def edit @submission = Submission.find(params[:id]) @view = Admin::SubmissionFormView.new(@submission, session) + if @submission.format_review_notes.blank? && !@submission.status_behavior.beyond_waiting_for_format_review_response? + @submission.format_review_notes = current_partner.graduate? ? I18n.t('graduate.default_format_review_note') : '' + end + return unless @submission.final_submission_notes.blank? && !@submission.status_behavior.beyond_collecting_final_submission_files? + + @submission.final_submission_notes = current_partner.graduate? ? I18n.t('graduate.default_final_submission_note') : '' end def update diff --git a/app/controllers/author/files_controller.rb b/app/controllers/author/files_controller.rb index 8b4adcd90..9ab7821a1 100644 --- a/app/controllers/author/files_controller.rb +++ b/app/controllers/author/files_controller.rb @@ -7,6 +7,8 @@ def current_file # file type @current_file = if params[:action] == 'download_final_submission' FinalSubmissionFile.find(params[:id]) + elsif params[:action] == 'download_admin_feedback' + AdminFeedbackFile.find(params[:id]) else FormatReviewFile.find(params[:id]) end diff --git a/app/controllers/author/submission_format_review_controller.rb b/app/controllers/author/submission_format_review_controller.rb index 24cb79ba8..fc9a964a6 100644 --- a/app/controllers/author/submission_format_review_controller.rb +++ b/app/controllers/author/submission_format_review_controller.rb @@ -53,6 +53,7 @@ def format_review_params :semester, :year, :federal_funding, - format_review_files_attributes: [:asset, :asset_cache, :submission_id, :id, :_destroy]) + format_review_files_attributes: [:asset, :asset_cache, :submission_id, :id, :_destroy], + admin_feedback_files_attributes: [:asset, :asset_cache, :submission_id, :feedback_type, :id, :_destroy]) end end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index cc1869013..940286947 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -13,9 +13,16 @@ def download_final_submission # DownloadFileLog.save_download_details(file, request.remote_ip) end + def download_admin_feedback + file = AdminFeedbackFile.find(params[:id]) + authorize! :read, file, file.submission + send_file file.current_location, disposition: :inline + # DownloadFileLog.save_download_details(file, request.remote_ip) + end + private def files_params - params.require(:file).permit([:asset, :asset_cache, :id, :_destroy]) + params.require(:file).permit([:asset, :asset_cache, :feedback_type, :id, :_destroy]) end end diff --git a/app/models/admin_feedback_file.rb b/app/models/admin_feedback_file.rb new file mode 100644 index 000000000..20da050eb --- /dev/null +++ b/app/models/admin_feedback_file.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class AdminFeedbackFile < ApplicationRecord + mount_uploader :asset, SubmissionFileUploader + + belongs_to :submission + + def self.feedback_types + ['format-review', 'final-submission'].freeze + end + + validates :submission_id, :asset, presence: true + validates :asset, virus_free: true + validates :feedback_type, inclusion: { in: feedback_types }, presence: true + + def class_name + self.class.to_s.underscore.dasherize + end + + def link_identifier + self.class.to_s.underscore.split('_file').first.pluralize + end + + def full_file_path + # file path only + "#{WORKFLOW_BASE_PATH}admin_feedback_files/#{EtdaFilePaths.new.detailed_file_path(id)}" + end + + def current_location + # full file path including file name + full_file_path + asset_identifier + end +end diff --git a/app/models/author_ability.rb b/app/models/author_ability.rb index 27e8b9f53..fc1550eb4 100644 --- a/app/models/author_ability.rb +++ b/app/models/author_ability.rb @@ -7,5 +7,6 @@ def initialize(author, _file, _submission) can [:read, :edit, :view, :update, :destroy], Submission, author_id: author.id can [:read, :upload, :edit, :view], FormatReviewFile, submission: { author_id: author.id } can [:read, :upload, :edit, :view], FinalSubmissionFile, submission: { author_id: author.id } + can [:read, :view], AdminFeedbackFile, submission: { author_id: author.id } end end diff --git a/app/models/submission.rb b/app/models/submission.rb index 851b174ce..dcbd2877f 100755 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -12,6 +12,7 @@ class Submission < ApplicationRecord has_many :committee_members, dependent: :destroy has_many :format_review_files, inverse_of: :submission, dependent: :destroy has_many :final_submission_files, inverse_of: :submission, dependent: :destroy + has_many :admin_feedback_files, inverse_of: :submission, dependent: :destroy has_many :keywords, dependent: :destroy, validate: true has_many :invention_disclosures, dependent: :destroy, validate: true @@ -121,6 +122,7 @@ def cache_access_level allow_destroy: true accepts_nested_attributes_for :format_review_files, allow_destroy: true accepts_nested_attributes_for :final_submission_files, allow_destroy: true + accepts_nested_attributes_for :admin_feedback_files, allow_destroy: true accepts_nested_attributes_for :keywords, allow_destroy: true accepts_nested_attributes_for :invention_disclosures, allow_destroy: true, @@ -403,6 +405,14 @@ def proquest_agreement=(input) self[:proquest_agreement_at] = DateTime.now end + def final_submission_feedback_files? + admin_feedback_files.any? { |file| file.feedback_type == 'final-submission' } + end + + def format_review_feedback_files? + admin_feedback_files.any? { |file| file.feedback_type == 'format-review' } + end + private def file_check diff --git a/app/services/final_submission_params.rb b/app/services/final_submission_params.rb index cf8026fc9..963f115e6 100644 --- a/app/services/final_submission_params.rb +++ b/app/services/final_submission_params.rb @@ -24,6 +24,7 @@ def self.call(params) :is_voting, :federal_funding_used, :_destroy], format_review_files_attributes: [:asset, :asset_cache, :id, :_destroy], final_submission_files_attributes: [:asset, :asset_cache, :id, :_destroy], + admin_feedback_files_attributes: [:asset, :asset_cache, :submission_id, :feedback_type, :id, :_destroy], keywords_attributes: [:word, :id, :_destroy], invention_disclosures_attributes: [:id, :submission_id, :id_number, :_destroy] ) diff --git a/app/services/format_review_update_service.rb b/app/services/format_review_update_service.rb index 38fb9c0b7..6700bced8 100644 --- a/app/services/format_review_update_service.rb +++ b/app/services/format_review_update_service.rb @@ -60,7 +60,8 @@ def format_review_params :lion_path_degree_code, :federal_funding, committee_members_attributes: [:id, :committee_role_id, :name, :email, :status, :notes, :is_required, :is_voting, :federal_funding_used, :_destroy], - format_review_files_attributes: [:asset, :asset_cache, :id, :_destroy] + format_review_files_attributes: [:asset, :asset_cache, :id, :_destroy], + admin_feedback_files_attributes: [:asset, :asset_cache, :feedback_type, :id, :_destroy] ) end end diff --git a/app/uploaders/submission_file_uploader.rb b/app/uploaders/submission_file_uploader.rb index a6e5b0166..f73f3f768 100644 --- a/app/uploaders/submission_file_uploader.rb +++ b/app/uploaders/submission_file_uploader.rb @@ -31,6 +31,8 @@ def cache_dir def asset_prefix if model.class_name == 'final-submission-file' Rails.root.join(WORKFLOW_BASE_PATH, 'final_submission_files') + elsif model.class_name == 'admin-feedback-file' + Rails.root.join(WORKFLOW_BASE_PATH, 'admin_feedback_files') else Rails.root.join(WORKFLOW_BASE_PATH, 'format_review_files') end diff --git a/app/views/admin/submissions/edit/_admin_feedback_files.html.erb b/app/views/admin/submissions/edit/_admin_feedback_files.html.erb new file mode 100644 index 000000000..f3e2020af --- /dev/null +++ b/app/views/admin/submissions/edit/_admin_feedback_files.html.erb @@ -0,0 +1,22 @@ +
+ +
+ diff --git a/app/views/admin/submissions/edit/_final_submission_fields.html.erb b/app/views/admin/submissions/edit/_final_submission_fields.html.erb index 272c22dba..1faa02afe 100644 --- a/app/views/admin/submissions/edit/_final_submission_fields.html.erb +++ b/app/views/admin/submissions/edit/_final_submission_fields.html.erb @@ -58,4 +58,5 @@ <%= render partial: 'shared/final_submission_confidential_hold_checkbox', locals: {f: f} if @submission.author.confidential? %> <%= f.input :final_submission_notes, as: :text, label: "Final Submission Notes to Student", input_html: { class: 'can-toggle-editability' } %> + <%= render partial: 'admin/submissions/edit/admin_feedback_files', locals: {f: f, feedback_type: 'final-submission'} %> diff --git a/app/views/admin/submissions/edit/_format_review_files.html.erb b/app/views/admin/submissions/edit/_format_review_files.html.erb index e0c055e39..15192a99b 100644 --- a/app/views/admin/submissions/edit/_format_review_files.html.erb +++ b/app/views/admin/submissions/edit/_format_review_files.html.erb @@ -18,4 +18,5 @@ <%= render partial: '/shared/federal_funding_checkbox', locals: {f: f} unless @submission.status_behavior.beyond_waiting_for_format_review_response? %> <%= f.input :format_review_notes, as: :text, label: "Format Review Notes to Student".html_safe, input_html: { class: 'can-toggle-editability' } %> + <%= render partial: 'admin/submissions/edit/admin_feedback_files', locals: {f: f, feedback_type: 'format-review'} %> diff --git a/app/views/author/submissions/edit_final_submission.html.erb b/app/views/author/submissions/edit_final_submission.html.erb index 099f5ebd2..cce674698 100644 --- a/app/views/author/submissions/edit_final_submission.html.erb +++ b/app/views/author/submissions/edit_final_submission.html.erb @@ -33,6 +33,17 @@ <% end %> + <% if @submission.final_submission_feedback_files? %> +
+ <% @submission.admin_feedback_files.each do |file| %> + <% if file.feedback_type == 'final-submission' %> +
+ <%= link_to file.asset_identifier, "/author/files/#{file.link_identifier}/#{file.id}", class: 'file-link', target: '_blank' %> +
+ <% end %> + <% end %> + <% end %> + <%= render partial: 'title_and_checkbox', locals: {f: f} %> <%= render partial: 'semester_year', locals: {f: f} %> <%= render partial: 'defended_at_date', locals: {f: f} if current_partner.graduate? %> diff --git a/app/views/author/submissions/edit_format_review.html.erb b/app/views/author/submissions/edit_format_review.html.erb index f27d9fc5d..69521b6d1 100644 --- a/app/views/author/submissions/edit_format_review.html.erb +++ b/app/views/author/submissions/edit_format_review.html.erb @@ -18,6 +18,19 @@
<% end %> + + <% if @submission.format_review_feedback_files? %> +
+ <% @submission.admin_feedback_files.each do |file| %> + <% if file.feedback_type == 'format-review' %> +
+ <%= link_to file.asset_identifier, "/author/files/#{file.link_identifier}/#{file.id}", class: 'file-link', target: '_blank' %> +
+ <% end %> + <% end %> +
+ <% end %> + <%= render partial: '/author/submissions/title_and_checkbox', locals: {f: f} %> <%= render partial: '/author/submissions/semester_year', locals: {f: f} %> <%= render partial: '/shared/federal_funding_checkbox', locals: {f: f} %> diff --git a/app/views/author/submissions/format_review.html.erb b/app/views/author/submissions/format_review.html.erb index 732e22ce6..7cce685bf 100644 --- a/app/views/author/submissions/format_review.html.erb +++ b/app/views/author/submissions/format_review.html.erb @@ -17,6 +17,12 @@ <% end %> + <% @submission.admin_feedback_files.each do |file| %> +
+ <%= link_to file.asset_identifier, "/author/files/#{file.link_identifier}/#{file.id}", class: 'file-link', target: '_blank' %> +
+ <% end %> +

Title

<%= @submission.title %>

diff --git a/app/views/shared/_file_fields.html.erb b/app/views/shared/_file_fields.html.erb index 11f0e4365..39f7ca02b 100644 --- a/app/views/shared/_file_fields.html.erb +++ b/app/views/shared/_file_fields.html.erb @@ -3,10 +3,10 @@
<% if file_fields.object.asset_identifier %> <% else %> @@ -15,5 +15,8 @@ <%= link_to_remove_association "[remove]", file_fields, class: 'text-danger can-toggle-clickability', html: {tabindex: '0'} %> <%= file_fields.input :asset_cache, :as => :hidden %> <%= file_fields.object.asset_identifier %> + <% if file_fields.object.respond_to?('feedback_type') %> + <%= file_fields.input :feedback_type, as: :hidden %> + <% end %> <% end %>
diff --git a/config/locales/partners/en/graduate/graduate.en.yml b/config/locales/partners/en/graduate/graduate.en.yml index 7547f616a..d549344af 100644 --- a/config/locales/partners/en/graduate/graduate.en.yml +++ b/config/locales/partners/en/graduate/graduate.en.yml @@ -428,6 +428,10 @@ en: login_html: 'Login using your Penn State access account to view the paper.' approval_help: message: "If you know you need to approve a student's work, but do not see it in your queue or the link is broken, your ability to vote has expired. To resolve this issue, please try clearing your cache and then trying the link again or try the link on a different browser. If that doesn't work, please call OTD at 814-865-5448 or email us at gradthesis@psu.edu so that we may proxy for you." + default_format_review_note: + "The documents below contain your format review corrections, information on supporting materials, and the graduation checklist. Please refer to the Thesis and Dissertation Handbook when making corrections. \n \n The next step is to submit your final dissertation. The final dissertation must be reviewed and approved by all committee members and all changes made before it is uploaded to the eTD site for electronic approval. Formatting changes requested by the Office of Theses and Dissertations will be the only changes permitted after the final is uploaded." + default_final_submission_note: + "Your final submission requires further revisions. To see these revisions, open the PDF below in Adobe Acrobat. Please note this DOES NOT require you to get committee approvals again. Rather, make the requested revisions and then upload the corrected file to the ETDA. The Office of Theses and Dissertations will review your submission again until it is error-free. Please resubmit by the deadline for your intended graduation semester requirements. Not doing so puts you at risk of being removed from the graduation list. \n \n Thank you and do reach out if you have any questions!" fee_message: master_thesis: message: "Before proceeding to your final submission, you must pay the $10 thesis fee. The fee can be paid at the Payment Section of the Graduate School Thesis and Dissertation Information webpage." diff --git a/config/routes.rb b/config/routes.rb index 7a75f6fb3..00d7e2029 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,6 +83,7 @@ get '/files/format_reviews/:id', to: 'files#download_format_review', as: :format_review_file get '/files/final_submissions/:id', to: 'files#download_final_submission', as: :final_submission_file + get '/files/admin_feedbacks/:id', to: 'files#download_admin_feedback', as: :admin_feedback_file root to: 'submissions#redirect_to_default_dashboard' end @@ -113,6 +114,7 @@ get '/files/format_reviews/:id', to: 'files#download_format_review', as: :format_review_file get '/files/final_submissions/:id', to: 'files#download_final_submission', as: :final_submission_file + get '/files/admin_feedbacks/:id', to: 'files#download_admin_feedback', as: :admin_feedback_file root to: 'submissions#index' get '/tips', to: 'authors#technical_tips', as: :technical_tips diff --git a/db/migrate/20240613195728_create_admin_feedback_files.rb b/db/migrate/20240613195728_create_admin_feedback_files.rb new file mode 100644 index 000000000..4cd71a916 --- /dev/null +++ b/db/migrate/20240613195728_create_admin_feedback_files.rb @@ -0,0 +1,11 @@ +class CreateAdminFeedbackFiles < ActiveRecord::Migration[6.1] + def change + create_table :admin_feedback_files do |t| + t.bigint :submission_id + t.text :asset + t.string :feedback_type + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5c9869e4c..63eee0ac2 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,15 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_06_03_141826) do +ActiveRecord::Schema.define(version: 2024_07_02_191344) do + + create_table "admin_feedback_files", charset: "utf8mb4", force: :cascade do |t| + t.bigint "submission_id" + t.text "asset" + t.string "feedback_type" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end create_table "admins", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "access_id", default: "", null: false diff --git a/spec/factories/admin_feedback_files.rb b/spec/factories/admin_feedback_files.rb new file mode 100644 index 000000000..be304a379 --- /dev/null +++ b/spec/factories/admin_feedback_files.rb @@ -0,0 +1,8 @@ +# # frozen_string_literal: true + +FactoryBot.define do + factory :admin_feedback_file, class: 'AdminFeedbackFile' do |_f| + submission + asset { File.open(fixture('admin_feedback_01.pdf')) } + end +end diff --git a/spec/fixtures/admin_feedback_01.pdf b/spec/fixtures/admin_feedback_01.pdf new file mode 100644 index 000000000..fed677586 Binary files /dev/null and b/spec/fixtures/admin_feedback_01.pdf differ diff --git a/spec/integration/admin/submissions/edit_submission_spec.rb b/spec/integration/admin/submissions/edit_submission_spec.rb index 1ce9cf69e..e4e43e3d0 100644 --- a/spec/integration/admin/submissions/edit_submission_spec.rb +++ b/spec/integration/admin/submissions/edit_submission_spec.rb @@ -74,8 +74,13 @@ end within('#format-review-files') do click_link "Additional File" - all('input[type="file"]').first.set(fixture('format_review_file_01.pdf')) - all('input[type="file"]').last.set(fixture('format_review_file_02.pdf')) + end + within('#format-review-file-fields') do + all('input[type="file"]')[0].set(fixture('format_review_file_01.pdf')) + all('input[type="file"]')[1].set(fixture('format_review_file_02.pdf')) + end + within('#admin-feedback-files') do + all('input[type="file"]')[0].set(fixture('admin_feedback_01.pdf')) end find('#submission_federal_funding_true').click @@ -104,10 +109,14 @@ expect(page).to have_link "format_review_file_02.pdf" end + within('#admin-feedback-files') do + expect(page).to have_link "admin_feedback_01.pdf" + end + expect(page.find_field("Format Review Notes to Student").value).to eq "New review notes" expect(page.find_field("Admin notes").value).to eq "Some admin notes" - within('#format-review-files') do + within('#format-review-file-fields') do delete_link = find_all('a#file_delete_link').first delete_link.click end @@ -116,6 +125,14 @@ visit admin_edit_submission_path(submission) expect(page).to have_link "format_review_file_02.pdf" expect(page).not_to have_link "format_review_file_01.pdf" + + within('#admin-feedback-files') do + delete_link = find_all('a#file_delete_link').first + delete_link.click + end + click_button 'Update Metadata' + visit admin_edit_submission_path(submission) + expect(page).not_to have_link "admin_feedback_01.pdf" end it 'Allows admin to upload and delete final submission files' do @@ -124,18 +141,25 @@ within('#final-submission-information') do click_link "Additional File" all('input[type="file"]').first.set(fixture('final_submission_file_01.pdf')) + click_link "Add File" + all('input[type="file"]').last.set(fixture('admin_feedback_01.pdf')) end click_button 'Update Metadata' visit admin_edit_submission_path(final_submission) expect(page).to have_link('final_submission_file_01.pdf') + expect(page).to have_link('admin_feedback_01.pdf') within('#final-submission-information') do - delete_link = find_all('a#file_delete_link').first + delete_links = find_all('a#file_delete_link') + delete_link = delete_links.first + delete_link2 = delete_links.last delete_link.click + delete_link2.click end expect(page).to have_content("Marked for deletion [undo]") click_button 'Update Metadata' visit admin_edit_submission_path(final_submission) expect(page).not_to have_link('final_submission_file_01.pdf') + expect(page).not_to have_link('admin_feedback_01.pdf') end it 'Allows admin to upload multiple final submission files' do diff --git a/spec/integration/author/submission_review_pages_spec.rb b/spec/integration/author/submission_review_pages_spec.rb index 758c2e775..a8a5f9e29 100644 --- a/spec/integration/author/submission_review_pages_spec.rb +++ b/spec/integration/author/submission_review_pages_spec.rb @@ -3,6 +3,9 @@ let!(:submission1) { FactoryBot.create :submission, :waiting_for_publication_release, author: current_author } let!(:submission2) { FactoryBot.create :submission, :waiting_for_committee_review, author: current_author } + let!(:submission3) { FactoryBot.create :submission, :collecting_format_review_files_rejected, author: current_author } + let!(:submission3_1) { FactoryBot.create :submission, :collecting_format_review_files_rejected, author: current_author } + let!(:submission4) { FactoryBot.create :submission, :collecting_final_submission_files_rejected, author: current_author } let!(:approval_configuration1) { FactoryBot.create :approval_configuration, degree_type: submission1.degree_type } let!(:approval_configuration2) { FactoryBot.create :approval_configuration, degree_type: submission2.degree_type } let(:invention_disclosures) { FactoryBot.create(:invention_disclosure, submission) } @@ -14,6 +17,8 @@ let(:final_submission_file) do FactoryBot.create :final_submission_file, submission: submission1 end + let(:admin_feedback_format) { FactoryBot.create :admin_feedback_file, submission: submission1, feedback_type: 'format-review' } + let(:admin_feedback_final) { FactoryBot.create :admin_feedback_file, submission: submission1, feedback_type: 'final-submission' } let(:long_note) do 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Amicitiam autem adhibendam esse censent, quia sit ex eo genere, quae prosunt. An vero, inquit, quisquam potest probare, quod perceptfum, quod. Hinc ceteri particulas arripere conati suam quisque videro voluit afferre sententiam. Illum mallem levares, quo optimum atque humanissimum virum, Cn. Ne amores quidem sanctos a sapiente alienos esse arbitrantur. Duo Reges: constructio interrete. Id enim volumus, id contendimus, ut officii fructus sit ipsum officium. Hoc ille tuus non vult omnibusque ex rebus voluptatem quasi mercedem exigit. Haec para/doca illi, nos admirabilia dicamus. Nobis aliter videtur, recte secusne, postea; Verum tamen cum de rebus grandioribus dicas, ipsae res verba rapiunt; Non quaeritur autem quid naturae tuae consentaneum sit, sed quid disciplinae. Eorum enim est haec querela, qui sibi cari sunt seseque diligunt. Paulum, cum regem Persem captum adduceret, eodem flumine invectio? Quantum Aristoxeni ingenium consumptum videmus in musicis? Fortemne possumus dicere eundem illum Torquatum? At iste non dolendi status non vocatur voluptas. Atque hoc loco similitudines eas, quibus illi uti solent, dissimillimas proferebas. Quare attende, quaeso. Et nemo nimium beatus est; Quid enim est a Chrysippo praetermissum in Stoicis? Lorem ipsum dolor sit amet, consectetur adipiscing elit. Amicitiam autem adhibendam esse censent, quia sit ex eo genere, quae prosunt. An vero, inquit, quisquam potest probare, quod perceptfum, quod. Hinc ceteri particulas arripere conati suam quisque videro voluit afferre sententiam. Illum mallem levares, quo optimum atque humanissimum virum, Cn. Ne amores quidem sanctos a sapiente alienos esse arbitrantur. Duo Reges: constructio interrete. Id enim volumus, id contendimus, ut officii fructus sit ipsum officium. Hoc ille tuus non vult omnibusque ex rebus voluptatem quasi mercedem exigit. Et nemo nimium beatus est; Quid enim est a Chrysippo praetermissum in Stoicis?' @@ -30,6 +35,15 @@ submission1.save submission2.committee_members << committee_member3 submission2.committee_members << committee_member4 + submission3.admin_feedback_files << admin_feedback_format + submission3.format_review_notes = "not your best work" + submission3.save + submission3_1.format_review_notes = "no files, just notes" + submission3_1.save + submission4.admin_feedback_files << admin_feedback_final + submission4.status = "collecting final submission files rejected" + submission4.final_submission_notes = "not your best work" + submission4.save oidc_authorize_author visit author_submissions_path end @@ -63,8 +77,40 @@ end end + context 'author can review admin feedback' do + it 'when format review is rejected' do + allow(admin_feedback_format).to receive(:current_location).and_return('spec/fixtures/admin_feedback_01.pdf') + visit "/author/submissions/#{submission3.id}/format_review/edit" + expect(page).to have_content('Format Review notes from the administrator') + expect(page).to have_content("not your best work") + expect(page).to have_link('admin_feedback_01.pdf') + # Makes sure that the file opens in a new tab + num_windows = page.driver.browser.window_handles.count + page.find_link('admin_feedback_01.pdf').click + expect(page.driver.browser.window_handles.count).to eql(num_windows + 1) + end + + it 'even if no feedback file is attached' do + visit "/author/submissions/#{submission3_1.id}/format_review/edit" + expect(page).to have_content('Format Review notes from the administrator') + expect(page).to have_content("no files, just notes") + end + + it 'when final submission is rejected' do + allow(admin_feedback_final).to receive(:current_location).and_return('spec/fixtures/admin_feedback_01.pdf') + visit "/author/submissions/#{submission4.id}/final_submission/edit" + expect(page).to have_content('Final Submission notes from the administrator') + expect(page).to have_content("not your best work") + expect(page).to have_link('admin_feedback_01.pdf') + # Makes sure that the file opens in a new tab + num_windows = page.driver.browser.window_handles.count + page.find_link('admin_feedback_01.pdf').click + expect(page.driver.browser.window_handles.count).to eql(num_windows + 1) + end + end + context 'author can review format review information' do - it 'displays format review information for the submission in a new browser tab' do + it 'in a new browser tab' do allow(format_review_file).to receive(:current_location).and_return('spec/fixtures/format_review_file_01.pdf') visit "/author/submissions/#{submission1.id}/format_review" expect(page).to have_content('Format Review Files') @@ -84,8 +130,8 @@ end end - context 'author can review final submission information in a new browser tab' do - it 'displays final submission information' do + context 'author can review final submission information ' do + it 'in a new browser tab' do allow(final_submission_file).to receive(:current_location).and_return('spec/fixtures/final_submission_file_01.pdf') visit "/author/submissions/#{submission1.id}/final_submission" expect(page).to have_content('Final Submission Files') diff --git a/spec/models/admin_feedback_file_spec.rb b/spec/models/admin_feedback_file_spec.rb new file mode 100644 index 000000000..beadba353 --- /dev/null +++ b/spec/models/admin_feedback_file_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'model_spec_helper' + +RSpec.describe AdminFeedbackFile, type: :model do + it { is_expected.to have_db_column(:id).of_type(:integer).with_options(null: false) } + it { is_expected.to have_db_column(:submission_id).of_type(:integer) } + it { is_expected.to have_db_column(:asset).of_type(:text) } + it { is_expected.to have_db_column(:created_at).of_type(:datetime) } + it { is_expected.to have_db_column(:updated_at).of_type(:datetime) } + it { is_expected.to have_db_column(:feedback_type).of_type(:string) } + + it { is_expected.to validate_presence_of :asset } + it { is_expected.to validate_presence_of :submission_id } + + it { is_expected.to belong_to :submission } + + it 'returns class name with dashes' do + final_submission_file = described_class.new + expect(final_submission_file.class_name).to eql('admin-feedback-file') + end + + it 'current_location returns full path and filename' do + submission = FactoryBot.create :submission, :waiting_for_publication_release + admin_feedback_file = described_class.new(submission_id: submission.id) + admin_feedback_file.id = 1234 + allow_any_instance_of(described_class).to receive(:asset_identifier).and_return('stubbed_filename.pdf') + expect(admin_feedback_file.current_location).to eq("#{WORKFLOW_BASE_PATH}admin_feedback_files/#{EtdaFilePaths.new.detailed_file_path(admin_feedback_file.id)}stubbed_filename.pdf") + end + + it 'full_file_path returns the full file path w/o filename' do + submission = FactoryBot.create :submission, :waiting_for_publication_release + admin_feedback_file = described_class.new(submission_id: submission.id) + admin_feedback_file.id = 1234 + expect(admin_feedback_file.full_file_path).to eq("#{WORKFLOW_BASE_PATH}admin_feedback_files/#{EtdaFilePaths.new.detailed_file_path(admin_feedback_file.id)}") + end + + describe 'feedback type validation' do + it 'validates the inclusion of feedback type in AdminFeedbackFile.feedback_types array' do + submission = FactoryBot.create :submission, :waiting_for_publication_release + admin_feedback_file = described_class.new(submission_id: submission.id) + expect(admin_feedback_file).to validate_inclusion_of(:feedback_type).in_array(described_class.feedback_types) + end + end +end diff --git a/spec/models/author_ability_spec.rb b/spec/models/author_ability_spec.rb index 48c25c9b5..de70a3423 100644 --- a/spec/models/author_ability_spec.rb +++ b/spec/models/author_ability_spec.rb @@ -23,5 +23,10 @@ expect(author_ability.can? :edit, different_person).to be_falsey expect(author_ability.can? :udpate, different_person).to be_falsey end + + it "does not allow author to create or delete an admin feedback file" do + expect(author_ability.can? :create, AdminFeedbackFile).to be_falsey + expect(author_ability.can? :destroy, AdminFeedbackFile).to be_falsey + end end end diff --git a/spec/models/submission_spec.rb b/spec/models/submission_spec.rb index cf507e871..f52ddcf6b 100755 --- a/spec/models/submission_spec.rb +++ b/spec/models/submission_spec.rb @@ -82,6 +82,7 @@ it { is_expected.to have_many :committee_members } it { is_expected.to have_many :format_review_files } it { is_expected.to have_many :final_submission_files } + it { is_expected.to have_many :admin_feedback_files } it { is_expected.to have_many :keywords } it { is_expected.to have_many :invention_disclosures } @@ -886,4 +887,32 @@ end end end + + describe "#final_submission_feedback_files?" do + it 'returns true if at least one admin feedback file with type final-submission' do + sub1 = described_class.new + sub1.admin_feedback_files.build(feedback_type: 'final-submission') + expect(sub1).to be_final_submission_feedback_files + end + + it 'returns false if no admin feedback file has the type of final-submission' do + sub2 = described_class.new + sub2.admin_feedback_files.build(feedback_type: 'format-review') + expect(sub2).not_to be_final_submission_feedback_files + end + end + + describe "#format_review_feedback_files?" do + it 'returns true if at least one admin feedback file with type format-review' do + sub3 = described_class.new + sub3.admin_feedback_files.build(feedback_type: 'format-review') + expect(sub3).to be_format_review_feedback_files + end + + it 'returns false if no admin feedback file has the type of format-review' do + sub4 = described_class.new + sub4.admin_feedback_files.build(feedback_type: 'final-submission') + expect(sub4).not_to be_format_review_feedback_files + end + end end