diff --git a/app/models/user.rb b/app/models/user.rb index cc046cc4..c99e0ce8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -129,7 +129,7 @@ def self.needs_open_access_notification .where('publications.published_on >= user_organization_memberships.started_on AND (publications.published_on <= user_organization_memberships.ended_on OR user_organization_memberships.ended_on IS NULL)') .where('authorships.confirmed IS TRUE') .where('publications.visible = true') - .where('publications.activity_insight_postprint_status IS NULL OR publications.activity_insight_postprint_status != ?', 'In Progress') + .where('publications.id NOT IN (SELECT publication_id FROM activity_insight_oa_files)') .where("open_access_locations.id IS NULL OR open_access_locations.url = ''") .distinct(:id) end @@ -283,6 +283,7 @@ def potential_open_access_publications .published_during_membership .subject_to_open_access_policy .where('authorships.confirmed IS TRUE') + .where('publications.id NOT IN (SELECT publication_id FROM activity_insight_oa_files)') end def psu_identity_data diff --git a/spec/component/models/user_spec.rb b/spec/component/models/user_spec.rb index cad6811d..c442d111 100644 --- a/spec/component/models/user_spec.rb +++ b/spec/component/models/user_spec.rb @@ -448,7 +448,7 @@ user: email_user_1, started_on: Date.new(2019, 1, 1), ended_on: nil) } - let!(:eu_pub_1) { create(:publication, published_on: Date.new(2020, 7, 1), activity_insight_postprint_status: 'Cannot Deposit') } + let!(:eu_pub_1) { create(:publication, published_on: Date.new(2020, 7, 1)) } let!(:eu_auth_1) { create(:authorship, user: email_user_1, publication: eu_pub_1, @@ -472,7 +472,7 @@ user: email_user_2, started_on: Date.new(2019, 1, 1), ended_on: nil) } - let!(:eu_pub_2) { create(:publication, published_on: Date.new(2020, 7, 1), activity_insight_postprint_status: 'Cannot Deposit') } + let!(:eu_pub_2) { create(:publication, published_on: Date.new(2020, 7, 1)) } let!(:eu_auth_2) { create(:authorship, user: email_user_2, publication: eu_pub_2, @@ -496,7 +496,7 @@ user: email_user_3, started_on: Date.new(2019, 1, 1), ended_on: Date.new(2020, 7, 2)) } - let!(:eu_pub_3) { create(:publication, published_on: Date.new(2020, 7, 1), activity_insight_postprint_status: 'Cannot Deposit') } + let!(:eu_pub_3) { create(:publication, published_on: Date.new(2020, 7, 1)) } let!(:eu_auth_3) { create(:authorship, user: email_user_3, publication: eu_pub_3, @@ -794,7 +794,7 @@ publication: ou_pub_17, confirmed: true) } - # filtered out due to the publication being in process of deposit to Scholarsphere via AI (activity_insight_postprint_status is 'In Progress') + # filtered out due to the publication being in the Activity Insight OA Workflow (has activity_insight_oa_file) let!(:other_user_18) { create(:user, :with_psu_identity, open_access_notification_sent_at: 1.year.ago, first_name: 'other_user_18') } @@ -802,7 +802,8 @@ user: other_user_18, started_on: Date.new(2019, 1, 1), ended_on: nil)} - let!(:ou_pub_18) { create(:publication, published_on: Date.new(2020, 7, 1), activity_insight_postprint_status: 'In Progress') } + let!(:ou_pub_18) { create(:publication, published_on: Date.new(2020, 7, 1)) } + let!(:ou_aif18) { create(:activity_insight_oa_file, publication: ou_pub_18, version: 'publishedVersion', user: other_user_18) } let!(:ou_auth_18) { create(:authorship, user: other_user_18, publication: ou_pub_18, @@ -866,6 +867,16 @@ confirmed: true, open_access_notification_sent_at: 1.month.ago) } + # Filtered out due to being in the Activity Insight OA Workflow (has activity_insight_oa_file) + let!(:other_pub_2) { create(:publication, + published_on: Date.new(2020, 7, 1)) } + let!(:o_auth_2) { create(:authorship, + user: user, + publication: other_pub_2, + confirmed: true, + open_access_notification_sent_at: 1.month.ago) } + let!(:o_aif_2) { create(:activity_insight_oa_file, publication: other_pub_2, version: 'publishedVersion', user: user) } + # Filtered out due to presence of open_access_url let!(:other_pub_5) { create(:publication, published_on: Date.new(2020, 7, 1), @@ -1035,6 +1046,15 @@ user: user, publication: other_pub_1, confirmed: true) } + # Filtered out due to being in the Activity Insight OA Workflow (has activity_insight_oa_file) + let!(:other_pub_2) { create(:publication, + published_on: Date.new(2020, 7, 1)) } + let!(:o_auth_2) { create(:authorship, + user: user, + publication: other_pub_2, + confirmed: true, + open_access_notification_sent_at: 1.month.ago) } + let!(:o_aif_2) { create(:activity_insight_oa_file, publication: other_pub_2, version: 'publishedVersion', user: user) } # Filtered out due to presence of open_access_url let!(:other_pub_5) { create(:publication,