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

Fix/bump gems (#8770)

ulferts4dd8e433b450
diff --git a/.codeclimate.yml b/.codeclimate.yml
index 326fcfc1ef6..7c38db52916 100644
--- a/.codeclimate.yml
+++ b/.codeclimate.yml
@@ -27,7 +27,7 @@ checks:
plugins:
rubocop:
enabled: true
- channel: rubocop-0-91
+ channel: rubocop-0-93
# Codeclimate uses brakeman 4.3.1 which does not support rails 6
# Check https://docs.codeclimate.com/docs/brakeman for updates.
brakeman:
diff --git a/Gemfile b/Gemfile
index 3c7d5a7490b..9c2bfd8c215 100644
--- a/Gemfile
+++ b/Gemfile
@@ -288,10 +288,7 @@ end
gem 'bootsnap', '~> 1.4.5', require: false
# API gems
-# Grape 1.4.0 has a bug which requires us to wait until 1.4.1 is released.
-# https://github.com/ruby-grape/grape/pull/2088
-# In 1.4.0, the Cache-Control will always be set to no-cache when sending a file.
-gem 'grape', '~> 1.3.0'
+gem 'grape', '~> 1.5.0'
gem 'roar', '~> 1.1.0'
# CORS for API
diff --git a/Gemfile.lock b/Gemfile.lock
index 158615684cf..c5beca9c187 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -288,8 +288,8 @@ GEM
awesome_nested_set (3.2.1)
activerecord (>= 4.0.0, < 7.0)
aws-eventstream (1.1.0)
- aws-partitions (1.380.0)
- aws-sdk-core (3.109.0)
+ aws-partitions (1.381.0)
+ aws-sdk-core (3.109.1)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
@@ -390,7 +390,7 @@ GEM
cucumber-wire (0.0.1)
daemons (1.3.1)
dalli (2.7.11)
- danger (8.0.5)
+ danger (8.0.6)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
@@ -526,7 +526,7 @@ GEM
i18n (>= 0.7)
multi_json
request_store (>= 1.0)
- grape (1.3.3)
+ grape (1.5.0)
activesupport
builder
dry-types (>= 1.1)
@@ -656,7 +656,7 @@ GEM
parallel (1.19.2)
parallel_tests (3.2.0)
parallel
- parser (2.7.1.5)
+ parser (2.7.2.0)
ast (~> 2.4.1)
pdf-core (0.8.1)
pdf-inspector (1.3.0)
@@ -774,7 +774,7 @@ GEM
recaptcha (5.5.0)
json
redcarpet (3.5.0)
- regexp_parser (1.8.1)
+ regexp_parser (1.8.2)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
@@ -819,13 +819,13 @@ GEM
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.9.3)
- rubocop (0.92.0)
+ rubocop (0.93.1)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
- regexp_parser (>= 1.7)
+ regexp_parser (>= 1.8)
rexml
- rubocop-ast (>= 0.5.0)
+ rubocop-ast (>= 0.6.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.7.1)
@@ -936,7 +936,7 @@ GEM
webfinger (1.1.0)
activesupport
httpclient (>= 2.4)
- webmock (3.9.1)
+ webmock (3.9.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
@@ -1005,7 +1005,7 @@ DEPENDENCIES
friendly_id (~> 5.4.0)
fuubar (~> 2.5.0)
gon (~> 6.4.0)
- grape (~> 1.3.0)
+ grape (~> 1.5.0)
grids!
html-pipeline (~> 2.14.0)
htmldiff
diff --git a/lib/api/helpers/attachment_renderer.rb b/lib/api/helpers/attachment_renderer.rb
index 76359ce4925..1e1f9cc6129 100644
--- a/lib/api/helpers/attachment_renderer.rb
+++ b/lib/api/helpers/attachment_renderer.rb
@@ -33,6 +33,23 @@
module API
module Helpers
module AttachmentRenderer
+ def self.content_endpoint(&block)
+ ->(*) {
+ helpers ::API::Helpers::AttachmentRenderer
+
+ finally do
+ set_cache_headers
+ end
+
+ 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
+ end
+ }
+ end
+
##
# Render an attachment, either by redirecting
# to the external storage,
@@ -43,23 +60,48 @@ module API
# @param cache_seconds [integer] Time in seconds the cache headers signal the browser to cache the attachment.
# Defaults to no cache headers.
def respond_with_attachment(attachment, cache_seconds: nil)
- if cache_seconds
- set_cache_headers!(cache_seconds)
- end
+ prepare_cache_headers(cache_seconds) if cache_seconds
if attachment.external_storage?
- redirect attachment.external_url(expires_in: cache_seconds).to_s
+ redirect_to_external_attachment(attachment, cache_seconds)
else
- content_type attachment.content_type
- header['Content-Disposition'] = "#{attachment.content_disposition}; filename=#{attachment.filename}"
- env['api.format'] = :binary
- file attachment.diskfile.path
+ send_attachment(attachment)
+ end
+ end
+
+ private
+
+ def redirect_to_external_attachment(attachment, cache_seconds)
+ set_cache_headers!
+ redirect attachment.external_url(expires_in: cache_seconds).to_s
+ end
+
+ def send_attachment(attachment)
+ content_type attachment.content_type
+ header['Content-Disposition'] = "#{attachment.content_disposition}; filename=#{attachment.filename}"
+ env['api.format'] = :binary
+ sendfile attachment.diskfile.path
+ end
+
+ def set_cache_headers
+ set_cache_headers! if @stream
+ end
+
+ def prepare_cache_headers(seconds)
+ @prepared_cache_headers = { "Cache-Control" => "public, max-age=#{seconds}",
+ "Expires" => CGI.rfc1123_date(Time.now.utc + seconds) }
+ end
+
+ def set_cache_headers!(seconds = nil)
+ prepare_cache_headers(seconds) if seconds
+
+ (@prepared_cache_headers || {}).each do |key, value|
+ header key, value
end
end
- def set_cache_headers!(seconds)
- header "Cache-Control", "public, max-age=#{seconds}"
- header "Expires", CGI.rfc1123_date(Time.now.utc + seconds)
+ def max_aws_cache_seconds
+ 604799
end
def avatar_link_expires_in
diff --git a/lib/api/v3/attachments/attachments_api.rb b/lib/api/v3/attachments/attachments_api.rb
index 384cbaac23e..80a20aad9e0 100644
--- a/lib/api/v3/attachments/attachments_api.rb
+++ b/lib/api/v3/attachments/attachments_api.rb
@@ -73,15 +73,9 @@ module API
delete &::API::V3::Utilities::Endpoints::Delete.new(model: Attachment).mount
- namespace :content do
- helpers ::API::Helpers::AttachmentRenderer
-
- get do
- # Cache that value at max 604799 seconds, which is the max
- # allowed expiry time for AWS generated links
- respond_with_attachment @attachment, cache_seconds: 604799
- end
- end
+ namespace :content, &::API::Helpers::AttachmentRenderer.content_endpoint(&-> {
+ @attachment
+ })
namespace :uploaded do
get do
diff --git a/modules/avatars/lib/api/v3/users/user_avatar_api.rb b/modules/avatars/lib/api/v3/users/user_avatar_api.rb
index 2e59f328e2e..d6553370f6f 100644
--- a/modules/avatars/lib/api/v3/users/user_avatar_api.rb
+++ b/modules/avatars/lib/api/v3/users/user_avatar_api.rb
@@ -34,13 +34,17 @@ module API
helpers ::AvatarHelper
helpers ::API::Helpers::AttachmentRenderer
+ finally do
+ set_cache_headers
+ end
+
get '/avatar' do
cache_seconds = @user == current_user ? nil : avatar_link_expires_in
if (local_avatar = local_avatar?(@user))
respond_with_attachment(local_avatar, cache_seconds: cache_seconds)
elsif avatar_manager.gravatar_enabled?
- set_cache_headers!(cache_seconds) unless cache_seconds.nil?
+ set_cache_headers!(cache_seconds) if cache_seconds
redirect build_gravatar_image_url(@user)
else
diff --git a/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb b/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb
index c1eeadf830e..ec3241be81a 100644
--- a/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb
+++ b/modules/bim/app/controllers/bim/bcf/api/v2_1/viewpoints/api.rb
@@ -75,20 +75,11 @@ module Bim::Bcf::API::V2_1
raise NotImplementedError, 'Bitmaps are not yet implemented.'
end
- namespace :snapshot do
- helpers ::API::Helpers::AttachmentRenderer
+ namespace :snapshot, &::API::Helpers::AttachmentRenderer.content_endpoint(&-> {
+ snapshot = @issue.viewpoints.find_by!(uuid: params[:viewpoint_uuid]).snapshot
- get do
- viewpoint = @issue.viewpoints.find_by!(uuid: params[:viewpoint_uuid])
- if snapshot = viewpoint.snapshot
- # Cache that value at max 604799 seconds, which is the max
- # allowed expiry time for AWS generated links
- respond_with_attachment snapshot, cache_seconds: 604799
- else
- raise ActiveRecord::RecordNotFound
- end
- end
- end
+ snapshot || raise(ActiveRecord::RecordNotFound)
+ })
end
end
end