Skip to content

Commit e3416fd

Browse files
committed
fix document file authorization
1 parent 6ca3c12 commit e3416fd

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

app/models/document_file.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,18 @@ class DocumentFile < ApplicationRecord
1818
def owner
1919
@owner ||= operator_document || operator_document_history
2020
end
21+
22+
# TODO: revisit later when refactoring ownership of document for not_provided documents
23+
def needs_authorization_before_downloading?
24+
return true if owner.nil?
25+
return false if any_connected_document_without_authorization?
26+
27+
true
28+
end
29+
30+
private
31+
32+
def any_connected_document_without_authorization?
33+
[operator_document, *OperatorDocumentHistory.where(document_file: self).to_a].compact.any? { !it.needs_authorization_before_downloading? }
34+
end
2135
end

app/uploaders/document_file_uploader.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def filename
2626
sanitize_filename(filename + File.extname(super))
2727
end
2828

29-
# def protected?
30-
# return true if model.owner.nil?
31-
32-
# model.owner.needs_authorization_before_downloading?
33-
# end
29+
def protected?
30+
model.needs_authorization_before_downloading?
31+
end
3432
end

app/uploaders/operator_document_annex_uploader.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ def track_downloads?
99
true
1010
end
1111

12-
# def protected?
13-
# model.needs_authorization_before_downloading?
14-
# end
12+
def protected?
13+
model.needs_authorization_before_downloading?
14+
end
1515

1616
def filename
1717
return if super.blank?

0 commit comments

Comments
 (0)