Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use the configured variable for expiry (#8985)

Oliver Günther8df966abff12
diff --git a/lib/api/helpers/attachment_renderer.rb b/lib/api/helpers/attachment_renderer.rb
index 7f82fa51bc3..665add07920 100644
--- a/lib/api/helpers/attachment_renderer.rb
+++ b/lib/api/helpers/attachment_renderer.rb
@@ -43,9 +43,7 @@ module API
get do
attachment = instance_exec(&block)
- # Cache that value at max 604799 seconds, which is the max
- # allowed expiry time for AWS generated links
- respond_with_attachment attachment, cache_seconds: max_aws_cache_seconds
+ respond_with_attachment attachment, cache_seconds: fog_cache_seconds
end
}
end
@@ -100,8 +98,11 @@ module API
end
end
- def max_aws_cache_seconds
- 604799
+ def fog_cache_seconds
+ [
+ 0,
+ OpenProject::Configuration.fog_download_url_expires_in.to_i - 10
+ ].max
end
def avatar_link_expires_in
diff --git a/modules/bim/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb b/modules/bim/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb
index 29133b16a7f..87aa1c53fad 100644
--- a/modules/bim/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb
+++ b/modules/bim/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb
@@ -204,13 +204,15 @@ describe 'BCF 2.1 viewpoints resource', type: :request, content_type: :json, wit
expect(subject.status).to eq 200
expect(subject.headers['Content-Type']).to eq 'image/jpeg'
- expect(subject.headers["Cache-Control"]).to eq "public, max-age=604799"
+ max_age = OpenProject::Configuration.fog_download_url_expires_in - 10
+
+ expect(subject.headers["Cache-Control"]).to eq "public, max-age=#{max_age}"
expect(subject.headers["Expires"]).to be_present
expires_time = Time.parse response.headers["Expires"]
- expect(expires_time < Time.now.utc + 604799).to be_truthy
- expect(expires_time > Time.now.utc + 604799 - 60).to be_truthy
+ expect(expires_time < Time.now.utc + max_age).to be_truthy
+ expect(expires_time > Time.now.utc + max_age - 60).to be_truthy
end
end
diff --git a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
index e6ef3af91e7..b0f9b3068de 100644
--- a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
+++ b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
@@ -415,13 +415,15 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
expect(subject.headers['Content-Type'])
.to eql mock_file.content_type
- expect(subject.headers["Cache-Control"]).to eq "public, max-age=604799"
+ max_age = OpenProject::Configuration.fog_download_url_expires_in.to_i - 10
+
+ expect(subject.headers["Cache-Control"]).to eq "public, max-age=#{max_age}"
expect(subject.headers["Expires"]).to be_present
expires_time = Time.parse response.headers["Expires"]
- expect(expires_time < Time.now.utc + 604799).to be_truthy
- expect(expires_time > Time.now.utc + 604799 - 60).to be_truthy
+ expect(expires_time < Time.now.utc + max_age).to be_truthy
+ expect(expires_time > Time.now.utc + max_age - 60).to be_truthy
end
it 'sends the file in binary' do
@@ -472,13 +474,15 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
expect(subject.headers['Location'])
.to eql external_url
- expect(subject.headers["Cache-Control"]).to eq "public, max-age=604799"
+ max_age = OpenProject::Configuration.fog_download_url_expires_in.to_i - 10
+
+ expect(subject.headers["Cache-Control"]).to eq "public, max-age=#{max_age}"
expect(subject.headers["Expires"]).to be_present
expires_time = Time.parse response.headers["Expires"]
- expect(expires_time < Time.now.utc + 604799).to be_truthy
- expect(expires_time > Time.now.utc + 604799 - 60).to be_truthy
+ expect(expires_time < Time.now.utc + max_age).to be_truthy
+ expect(expires_time > Time.now.utc + max_age - 60).to be_truthy
end
end
end