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

Oliver Günthercb5fbb6a728a
diff --git a/lib/api/helpers/attachment_renderer.rb b/lib/api/helpers/attachment_renderer.rb
index 1e1f9cc6129..81d8dd706cf 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 7a09250250b..f4fb6e81b6d 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 1f3a1af56cb..dbdee3a3e12 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
diff --git a/spec/support/pages/projects/destroy.rb b/spec/support/pages/projects/destroy.rb
index 2e5c1630162..d4d7d187200 100644
--- a/spec/support/pages/projects/destroy.rb
+++ b/spec/support/pages/projects/destroy.rb
@@ -25,6 +25,7 @@
#
# See docs/COPYRIGHT.rdoc for more details.
#++
+require_relative '../page'
module Pages
module Projects