From a8e84a18f1d84943e8332ff8deba9d91b1cb3efd Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 14 Jul 2020 18:50:19 +0200 Subject: Fix larger video files not being transcoded (#14306) Since #14145, the `set_type_and_extension` has been moved from `before_post_process` to `before_file_post_process`, but while the former runs before all validations performed by Paperclip, the latter is dependent on the order validations and hooks are defined. In our case, this meant video files could be checked against the generic 10MB limit, causing validation failures, which, internally, make Paperclip skip post-processing, and thus, transcoding of the video file. The actual validation would then happen after the type is correctly set, so the large file would pass validation, but without being transcoded first. This commit moves the hook definition so that it is run before checking for the file size. --- app/models/media_attachment.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 519711401..3f2e0ceb1 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -165,6 +165,9 @@ class MediaAttachment < ApplicationRecord processors: ->(f) { file_processors f }, convert_options: GLOBAL_CONVERT_OPTIONS + before_file_post_process :set_type_and_extension + before_file_post_process :check_video_dimensions + validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES validates_attachment_size :file, less_than: IMAGE_LIMIT, unless: :larger_media_format? validates_attachment_size :file, less_than: VIDEO_LIMIT, if: :larger_media_format? @@ -257,9 +260,6 @@ class MediaAttachment < ApplicationRecord after_post_process :set_meta - before_file_post_process :set_type_and_extension - before_file_post_process :check_video_dimensions - class << self def supported_mime_types IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES -- cgit From 6a96af4d20129cea06c716393338aa4f730b7b35 Mon Sep 17 00:00:00 2001 From: abcang Date: Wed, 15 Jul 2020 02:05:07 +0900 Subject: Fix rubocop warning (#14288) * Fix rubocop warning * use limit variable * use ContextCreatingMethods option --- .rubocop.yml | 4 ++++ app/controllers/auth/sessions_controller.rb | 1 + app/controllers/tags_controller.rb | 2 +- app/lib/activitypub/activity/create.rb | 2 +- app/lib/proof_provider/keybase/config_serializer.rb | 2 +- app/lib/request.rb | 1 + app/lib/settings/scoped_settings.rb | 5 ++--- app/models/concerns/omniauthable.rb | 2 +- 8 files changed, 12 insertions(+), 7 deletions(-) (limited to 'app/models') diff --git a/.rubocop.yml b/.rubocop.yml index 3a11f7000..25e0fa940 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -28,6 +28,10 @@ Layout/EmptyLineAfterMagicComment: Layout/SpaceInsideHashLiteralBraces: EnforcedStyle: space +Lint/UselessAccessModifier: + ContextCreatingMethods: + - class_methods + Metrics/AbcSize: Max: 100 diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index 2415e2ef3..1fd755334 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -46,6 +46,7 @@ class Auth::SessionsController < Devise::SessionsController user = User.authenticate_with_ldap(user_params) if Devise.ldap_authentication user ||= User.authenticate_with_pam(user_params) if Devise.pam_authentication user ||= User.find_for_authentication(email: user_params[:email]) + user end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 234a0c411..6426a7d69 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -27,7 +27,7 @@ class TagsController < ApplicationController expires_in 0, public: true limit = params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE - @statuses = HashtagQueryService.new.call(@tag, filter_params, nil, @local).limit(PAGE_SIZE) + @statuses = HashtagQueryService.new.call(@tag, filter_params, nil, @local).limit(limit) @statuses = cache_collection(@statuses, Status) render xml: RSS::TagSerializer.render(@tag, @statuses) diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index d3d460551..e81452e3c 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -45,7 +45,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity RedisLock.acquire(lock_options) do |lock| if lock.acquired? - return if delete_arrived_first?(object_uri) || poll_vote? + return if delete_arrived_first?(object_uri) || poll_vote? # rubocop:disable Lint/NonLocalExitFromIterator @status = find_existing_status diff --git a/app/lib/proof_provider/keybase/config_serializer.rb b/app/lib/proof_provider/keybase/config_serializer.rb index fbce7aeee..c6c364d31 100644 --- a/app/lib/proof_provider/keybase/config_serializer.rb +++ b/app/lib/proof_provider/keybase/config_serializer.rb @@ -55,7 +55,7 @@ class ProofProvider::Keybase::ConfigSerializer < ActiveModel::Serializer end def profile_url - CGI.unescape(short_account_url('%{username}')) # rubocop:disable Style/FormatStringToken + CGI.unescape(short_account_url('%{username}')) end def check_url diff --git a/app/lib/request.rb b/app/lib/request.rb index 247c32958..bcba1eebf 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -231,6 +231,7 @@ class Request begin sock.connect_nonblock(addr_by_socket[sock]) rescue Errno::EISCONN + # Do nothing rescue => e sock.close outer_e = e diff --git a/app/lib/settings/scoped_settings.rb b/app/lib/settings/scoped_settings.rb index 9ca39510a..3bec9bd56 100644 --- a/app/lib/settings/scoped_settings.rb +++ b/app/lib/settings/scoped_settings.rb @@ -11,7 +11,7 @@ module Settings @object = object end - # rubocop:disable Style/MethodMissing + # rubocop:disable Style/MethodMissingSuper def method_missing(method, *args) method_name = method.to_s # set a value for a variable @@ -24,7 +24,7 @@ module Settings self[method_name] end end - # rubocop:enable Style/MethodMissing + # rubocop:enable Style/MethodMissingSuper def respond_to_missing?(*) true @@ -48,7 +48,6 @@ module Settings record.update!(value: value) Rails.cache.write(Setting.cache_key(key, @object), value) - value end def [](key) diff --git a/app/models/concerns/omniauthable.rb b/app/models/concerns/omniauthable.rb index 736da6c1d..4ea219537 100644 --- a/app/models/concerns/omniauthable.rb +++ b/app/models/concerns/omniauthable.rb @@ -57,7 +57,7 @@ module Omniauthable user = User.new(user_params_from_auth(email, auth)) - user.account.avatar_remote_url = auth.info.image if auth.info.image =~ /\A#{URI.regexp(%w(http https))}\z/ + user.account.avatar_remote_url = auth.info.image if auth.info.image =~ /\A#{URI::DEFAULT_PARSER.make_regexp(%w(http https))}\z/ user.skip_confirmation! user.save! user -- cgit