check correct shard for content share linked to export

the content share lives in the user's shard, not necessarily
the export's shard or the domain root account's shard

test plan:
 - have multiple shards set up
 - as a teacher/admin, find a content share you sent
   more than 30 days ago (or create a new content share
   and modify the linked content_export's created_at date
   to be older than 30 days)
 - ensure if you hit the /api/v1/users/self/content_shares/sent
   endpoint, the attachment is included under the content_export
   in the results, regardless of which domain you hit the endpoint
   from (the user's native domain or another one)

fixes LS-2171

Change-Id: I56390adaf29f600f4fbf666d8dbed06615a7fadb
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/263550
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Eric Saupe <eric.saupe@instructure.com>
QA-Review: Eric Saupe <eric.saupe@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Jeremy Stanley 2021-04-23 12:11:24 -06:00
parent 8e0c378644
commit 52e4e7c864
2 changed files with 4 additions and 2 deletions

View File

@ -578,7 +578,9 @@ class ContentExport < ActiveRecord::Base
def expired?
return false unless ContentExport.expire?
return false if ContentShare.where(content_export: self).exists?
if self.user
return false if self.user.content_shares.where(content_export: self).exists?
end
created_at < ContentExport.expire_days.days.ago
end

View File

@ -289,7 +289,7 @@ describe ContentExport do
it "does not mark expired if part of a ContentShare" do
@teacher.sent_content_shares.create!(read_state: 'read', name: 'test', content_export_id: @ce.id)
ContentExport.where(id: @ce.id).update_all(created_at: 35.days.ago)
ContentExport.where(id: @ce.id).update_all(created_at: 35.days.ago, user_id: @teacher.id)
expect(@ce.reload).not_to be_expired
end
end