From 9660aa4543deff41c60d131e081137f84e771499 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 8 Mar 2020 23:56:18 +0100 Subject: Change local media attachments to perform heavy processing asynchronously (#13210) Fix #9106 --- app/controllers/api/v1/media_controller.rb | 29 ++++++++++++++---- app/controllers/api/v2/media_controller.rb | 12 ++++++++ app/javascript/mastodon/actions/compose.js | 23 +++++++++++++-- app/models/concerns/attachmentable.rb | 2 +- app/models/media_attachment.rb | 26 +++++++++++++++-- .../rest/media_attachment_serializer.rb | 4 ++- app/services/post_status_service.rb | 1 + app/workers/backup_worker.rb | 8 +++-- app/workers/post_process_media_worker.rb | 34 ++++++++++++++++++++++ 9 files changed, 124 insertions(+), 15 deletions(-) create mode 100644 app/controllers/api/v2/media_controller.rb create mode 100644 app/workers/post_process_media_worker.rb (limited to 'app') diff --git a/app/controllers/api/v1/media_controller.rb b/app/controllers/api/v1/media_controller.rb index d87d7b946..0bb3d0d27 100644 --- a/app/controllers/api/v1/media_controller.rb +++ b/app/controllers/api/v1/media_controller.rb @@ -3,25 +3,42 @@ class Api::V1::MediaController < Api::BaseController before_action -> { doorkeeper_authorize! :write, :'write:media' } before_action :require_user! + before_action :set_media_attachment, except: [:create] + before_action :check_processing, except: [:create] def create - @media = current_account.media_attachments.create!(media_params) - render json: @media, serializer: REST::MediaAttachmentSerializer + @media_attachment = current_account.media_attachments.create!(media_attachment_params) + render json: @media_attachment, serializer: REST::MediaAttachmentSerializer rescue Paperclip::Errors::NotIdentifiedByImageMagickError render json: file_type_error, status: 422 rescue Paperclip::Error render json: processing_error, status: 500 end + def show + render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: status_code_for_media_attachment + end + def update - @media = current_account.media_attachments.where(status_id: nil).find(params[:id]) - @media.update!(media_params) - render json: @media, serializer: REST::MediaAttachmentSerializer + @media_attachment.update!(media_attachment_params) + render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: status_code_for_media_attachment end private - def media_params + def status_code_for_media_attachment + @media_attachment.not_processed? ? 206 : 200 + end + + def set_media_attachment + @media_attachment = current_account.media_attachments.unattached.find(params[:id]) + end + + def check_processing + render json: processing_error, status: 422 if @media_attachment.processing_failed? + end + + def media_attachment_params params.permit(:file, :description, :focus) end diff --git a/app/controllers/api/v2/media_controller.rb b/app/controllers/api/v2/media_controller.rb new file mode 100644 index 000000000..0c1baf01d --- /dev/null +++ b/app/controllers/api/v2/media_controller.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class Api::V2::MediaController < Api::V1::MediaController + def create + @media_attachment = current_account.media_attachments.create!({ delay_processing: true }.merge(media_attachment_params)) + render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: 202 + rescue Paperclip::Errors::NotIdentifiedByImageMagickError + render json: file_type_error, status: 422 + rescue Paperclip::Error + render json: processing_error, status: 500 + end +end diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index c3c6ff1a1..68ef8fbd5 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -230,12 +230,31 @@ export function uploadCompose(files) { // Account for disparity in size of original image and resized data total += file.size - f.size; - return api(getState).post('/api/v1/media', data, { + return api(getState).post('/api/v2/media', data, { onUploadProgress: function({ loaded }){ progress[i] = loaded; dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total)); }, - }).then(({ data }) => dispatch(uploadComposeSuccess(data, f))); + }).then(({ status, data }) => { + // If server-side processing of the media attachment has not completed yet, + // poll the server until it is, before showing the media attachment as uploaded + + if (status === 200) { + dispatch(uploadComposeSuccess(data, f)); + } else if (status === 202) { + const poll = () => { + api(getState).get(`/api/v1/media/${data.id}`).then(response => { + if (response.status === 200) { + dispatch(uploadComposeSuccess(data, f)); + } else if (response.status === 206) { + setTimeout(() => poll(), 1000); + } + }).catch(error => dispatch(uploadComposeFail(error))); + }; + + poll(); + } + }); }).catch(error => dispatch(uploadComposeFail(error))); }; }; diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb index 43ff8ac12..18b872c1e 100644 --- a/app/models/concerns/attachmentable.rb +++ b/app/models/concerns/attachmentable.rb @@ -74,7 +74,7 @@ module Attachmentable self.class.attachment_definitions.each_key do |attachment_name| attachment = send(attachment_name) - next if attachment.blank? || attachment.queued_for_write[:original].blank? + next if attachment.blank? || attachment.queued_for_write[:original].blank? || attachment.options[:preserve_files] attachment.instance_write :file_name, SecureRandom.hex(8) + File.extname(attachment.instance_read(:file_name)) end diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 1e36625ca..3fd4f231c 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -19,12 +19,14 @@ # description :text # scheduled_status_id :bigint(8) # blurhash :string +# processing :integer # class MediaAttachment < ApplicationRecord self.inheritance_column = nil enum type: [:image, :gifv, :video, :unknown, :audio] + enum processing: [:queued, :in_progress, :complete, :failed], _prefix: true MAX_DESCRIPTION_LENGTH = 1_500 @@ -156,6 +158,10 @@ class MediaAttachment < ApplicationRecord remote_url.blank? end + def not_processed? + processing.present? && !processing_complete? + end + def needs_redownload? file.blank? && remote_url.present? end @@ -203,10 +209,18 @@ class MediaAttachment < ApplicationRecord "#{x},#{y}" end + attr_writer :delay_processing + + def delay_processing? + @delay_processing + end + + after_commit :enqueue_processing, on: :create after_commit :reset_parent_cache, on: :update before_create :prepare_description, unless: :local? before_create :set_shortcode + before_create :set_processing before_post_process :set_type_and_extension @@ -277,6 +291,10 @@ class MediaAttachment < ApplicationRecord end end + def set_processing + self.processing = delay_processing? ? :queued : :complete + end + def set_meta meta = populate_meta @@ -322,9 +340,11 @@ class MediaAttachment < ApplicationRecord }.compact end - def reset_parent_cache - return if status_id.nil? + def enqueue_processing + PostProcessMediaWorker.perform_async(id) if delay_processing? + end - Rails.cache.delete("statuses/#{status_id}") + def reset_parent_cache + Rails.cache.delete("statuses/#{status_id}") if status_id.present? end end diff --git a/app/serializers/rest/media_attachment_serializer.rb b/app/serializers/rest/media_attachment_serializer.rb index 1b3498ea4..cc10e3001 100644 --- a/app/serializers/rest/media_attachment_serializer.rb +++ b/app/serializers/rest/media_attachment_serializer.rb @@ -12,7 +12,9 @@ class REST::MediaAttachmentSerializer < ActiveModel::Serializer end def url - if object.needs_redownload? + if object.not_processed? + nil + elsif object.needs_redownload? media_proxy_url(object.id, :original) else full_asset_url(object.file.url(:original)) diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 2301621ab..c61b3baa2 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -101,6 +101,7 @@ class PostStatusService < BaseService @media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i)) raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if @media.size > 1 && @media.find(&:audio_or_video?) + raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_ready') if @media.any?(&:not_processed?) end def language_from_option(str) diff --git a/app/workers/backup_worker.rb b/app/workers/backup_worker.rb index e4c609d70..7b0b52844 100644 --- a/app/workers/backup_worker.rb +++ b/app/workers/backup_worker.rb @@ -9,8 +9,12 @@ class BackupWorker backup_id = msg['args'].first ActiveRecord::Base.connection_pool.with_connection do - backup = Backup.find(backup_id) - backup&.destroy + begin + backup = Backup.find(backup_id) + backup.destroy + rescue ActiveRecord::RecordNotFound + true + end end end diff --git a/app/workers/post_process_media_worker.rb b/app/workers/post_process_media_worker.rb new file mode 100644 index 000000000..d3ebda194 --- /dev/null +++ b/app/workers/post_process_media_worker.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class PostProcessMediaWorker + include Sidekiq::Worker + + sidekiq_options retry: 1, dead: false + + sidekiq_retries_exhausted do |msg| + media_attachment_id = msg['args'].first + + ActiveRecord::Base.connection_pool.with_connection do + begin + media_attachment = MediaAttachment.find(media_attachment_id) + media_attachment.processing = :failed + media_attachment.save + rescue ActiveRecord::RecordNotFound + true + end + end + + Sidekiq.logger.error("Processing media attachment #{media_attachment_id} failed with #{msg['error_message']}") + end + + def perform(media_attachment_id) + media_attachment = MediaAttachment.find(media_attachment_id) + media_attachment.processing = :in_progress + media_attachment.save + media_attachment.file.reprocess_original! + media_attachment.processing = :complete + media_attachment.save + rescue ActiveRecord::RecordNotFound + true + end +end -- cgit From b154428e14861f5cdc7ba6e5f8e582dbf7d0a1c0 Mon Sep 17 00:00:00 2001 From: ThibG Date: Mon, 9 Mar 2020 00:10:29 +0100 Subject: Add federation support for the "hide network" preference (#11673) * Change ActivityPub follower/following collections to not link first page * Add support for hiding followers and following of remote users * Switch to using a single `hide_collections` column * Address code style remarks --- .../v1/accounts/follower_accounts_controller.rb | 2 +- .../v1/accounts/following_accounts_controller.rb | 2 +- app/controllers/follower_accounts_controller.rb | 11 +++++++++- app/controllers/following_accounts_controller.rb | 11 +++++++++- app/models/account.rb | 9 ++++++++ .../activitypub/process_account_service.rb | 25 ++++++++++++++++------ ...91212163405_add_hide_collections_to_accounts.rb | 5 +++++ db/schema.rb | 1 + 8 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20191212163405_add_hide_collections_to_accounts.rb (limited to 'app') diff --git a/app/controllers/api/v1/accounts/follower_accounts_controller.rb b/app/controllers/api/v1/accounts/follower_accounts_controller.rb index 850702cca..1daa1ed0d 100644 --- a/app/controllers/api/v1/accounts/follower_accounts_controller.rb +++ b/app/controllers/api/v1/accounts/follower_accounts_controller.rb @@ -25,7 +25,7 @@ class Api::V1::Accounts::FollowerAccountsController < Api::BaseController end def hide_results? - (@account.user_hides_network? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account)) + (@account.hides_followers? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account)) end def default_accounts diff --git a/app/controllers/api/v1/accounts/following_accounts_controller.rb b/app/controllers/api/v1/accounts/following_accounts_controller.rb index 830dcd8a1..6fc23cf75 100644 --- a/app/controllers/api/v1/accounts/following_accounts_controller.rb +++ b/app/controllers/api/v1/accounts/following_accounts_controller.rb @@ -25,7 +25,7 @@ class Api::V1::Accounts::FollowingAccountsController < Api::BaseController end def hide_results? - (@account.user_hides_network? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account)) + (@account.hides_following? && current_account&.id != @account.id) || (current_account && @account.blocking?(current_account)) end def default_accounts diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb index 7103749ad..14e22dd1e 100644 --- a/app/controllers/follower_accounts_controller.rb +++ b/app/controllers/follower_accounts_controller.rb @@ -28,7 +28,8 @@ class FollowerAccountsController < ApplicationController render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, - content_type: 'application/activity+json' + content_type: 'application/activity+json', + fields: restrict_fields_to end end end @@ -71,4 +72,12 @@ class FollowerAccountsController < ApplicationController ) end end + + def restrict_fields_to + if page_requested? || !@account.user_hides_network? + # Return all fields + else + %i(id type totalItems) + end + end end diff --git a/app/controllers/following_accounts_controller.rb b/app/controllers/following_accounts_controller.rb index 6c8fb84d8..95849ffb9 100644 --- a/app/controllers/following_accounts_controller.rb +++ b/app/controllers/following_accounts_controller.rb @@ -28,7 +28,8 @@ class FollowingAccountsController < ApplicationController render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, - content_type: 'application/activity+json' + content_type: 'application/activity+json', + fields: restrict_fields_to end end end @@ -71,4 +72,12 @@ class FollowingAccountsController < ApplicationController ) end end + + def restrict_fields_to + if page_requested? || !@account.user_hides_network? + # Return all fields + else + %i(id type totalItems) + end + end end diff --git a/app/models/account.rb b/app/models/account.rb index a1b4a065b..6aceb809c 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -46,6 +46,7 @@ # silenced_at :datetime # suspended_at :datetime # trust_level :integer +# hide_collections :boolean # class Account < ApplicationRecord @@ -323,6 +324,14 @@ class Account < ApplicationRecord save! end + def hides_followers? + hide_collections? || user_hides_network? + end + + def hides_following? + hide_collections? || user_hides_network? + end + def object_type :person end diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index d5ede0388..7b4c53d50 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -94,6 +94,7 @@ class ActivityPub::ProcessAccountService < BaseService @account.statuses_count = outbox_total_items if outbox_total_items.present? @account.following_count = following_total_items if following_total_items.present? @account.followers_count = followers_total_items if followers_total_items.present? + @account.hide_collections = following_private? || followers_private? @account.moved_to_account = @json['movedTo'].present? ? moved_account : nil end @@ -166,26 +167,36 @@ class ActivityPub::ProcessAccountService < BaseService end def outbox_total_items - collection_total_items('outbox') + collection_info('outbox').first end def following_total_items - collection_total_items('following') + collection_info('following').first end def followers_total_items - collection_total_items('followers') + collection_info('followers').first end - def collection_total_items(type) - return if @json[type].blank? + def following_private? + !collection_info('following').last + end + + def followers_private? + !collection_info('followers').last + end + + def collection_info(type) + return [nil, nil] if @json[type].blank? return @collections[type] if @collections.key?(type) collection = fetch_resource_without_id_validation(@json[type]) - @collections[type] = collection.is_a?(Hash) && collection['totalItems'].present? && collection['totalItems'].is_a?(Numeric) ? collection['totalItems'] : nil + total_items = collection.is_a?(Hash) && collection['totalItems'].present? && collection['totalItems'].is_a?(Numeric) ? collection['totalItems'] : nil + has_first_page = collection.is_a?(Hash) && collection['first'].present? + @collections[type] = [total_items, has_first_page] rescue HTTP::Error, OpenSSL::SSL::SSLError - @collections[type] = nil + @collections[type] = [nil, nil] end def moved_account diff --git a/db/migrate/20191212163405_add_hide_collections_to_accounts.rb b/db/migrate/20191212163405_add_hide_collections_to_accounts.rb new file mode 100644 index 000000000..fa99b32e5 --- /dev/null +++ b/db/migrate/20191212163405_add_hide_collections_to_accounts.rb @@ -0,0 +1,5 @@ +class AddHideCollectionsToAccounts < ActiveRecord::Migration[5.2] + def change + add_column :accounts, :hide_collections, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index ddb9a5d8c..a851e01fc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -170,6 +170,7 @@ ActiveRecord::Schema.define(version: 2020_03_06_035625) do t.datetime "silenced_at" t.datetime "suspended_at" t.integer "trust_level" + t.boolean "hide_collections" t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id" -- cgit From 7088633ae11bfb79bed0d853f70547396c4380f2 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 9 Mar 2020 00:12:52 +0100 Subject: Bump cld3 from 3.2.6 to 3.3.0 (#13107) * Bump cld3 from 3.2.6 to 3.3.0 Bumps [cld3](https://github.com/akihikodaki/cld3-ruby) from 3.2.6 to 3.3.0. - [Release notes](https://github.com/akihikodaki/cld3-ruby/releases) - [Commits](https://github.com/akihikodaki/cld3-ruby/compare/v3.2.6...v3.3.0) Signed-off-by: dependabot-preview[bot] * Fix compatibility with cld3 3.3.0 Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Eugen Rochko --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/lib/language_detector.rb | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/Gemfile b/Gemfile index f6c705765..d3056c929 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,7 @@ gem 'browser' gem 'charlock_holmes', '~> 0.7.7' gem 'iso-639' gem 'chewy', '~> 5.1' -gem 'cld3', '~> 3.2.6' +gem 'cld3', '~> 3.3.0' gem 'devise', '~> 4.7' gem 'devise-two-factor', '~> 3.1' diff --git a/Gemfile.lock b/Gemfile.lock index cd255bc3e..82e6360ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -160,7 +160,7 @@ GEM elasticsearch (>= 2.0.0) elasticsearch-dsl chunky_png (1.3.11) - cld3 (3.2.6) + cld3 (3.3.0) ffi (>= 1.1.0, < 1.12.0) climate_control (0.2.0) cocaine (0.5.8) @@ -681,7 +681,7 @@ DEPENDENCIES capybara (~> 3.31) charlock_holmes (~> 0.7.7) chewy (~> 5.1) - cld3 (~> 3.2.6) + cld3 (~> 3.3.0) climate_control (~> 0.2) concurrent-ruby connection_pool diff --git a/app/lib/language_detector.rb b/app/lib/language_detector.rb index 302072bcc..05a06726d 100644 --- a/app/lib/language_detector.rb +++ b/app/lib/language_detector.rb @@ -52,8 +52,10 @@ class LanguageDetector def detect_language_code(text) return if unreliable_input?(text) + result = @identifier.find_language(text) - iso6391(result.language.to_s).to_sym if result.reliable? + + iso6391(result.language.to_s).to_sym if result&.reliable? end def iso6391(bcp47) -- cgit From dc15c81e67da4df932233c3c40f6fada206c71e3 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 9 Mar 2020 02:19:07 +0100 Subject: Change video uploads to enforce certain limits (#13218) - Dimensions at most 1920x1200 - Frame rate at most 60 --- app/models/media_attachment.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 3fd4f231c..49e2e5e27 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -126,6 +126,9 @@ class MediaAttachment < ApplicationRecord IMAGE_LIMIT = 10.megabytes VIDEO_LIMIT = 40.megabytes + MAX_VIDEO_MATRIX_LIMIT = 2_304_000 # 1920x1200px + MAX_VIDEO_FRAME_RATE = 60 + belongs_to :account, inverse_of: :media_attachments, optional: true belongs_to :status, inverse_of: :media_attachments, optional: true belongs_to :scheduled_status, inverse_of: :media_attachments, optional: true @@ -223,6 +226,7 @@ class MediaAttachment < ApplicationRecord before_create :set_processing before_post_process :set_type_and_extension + before_post_process :check_video_dimensions before_save :set_meta @@ -295,6 +299,17 @@ class MediaAttachment < ApplicationRecord self.processing = delay_processing? ? :queued : :complete end + def check_video_dimensions + return unless (video? || gifv?) && file.queued_for_write[:original].present? + + movie = FFMPEG::Movie.new(file.queued_for_write[:original].path) + + return unless movie.valid? + + raise Mastodon::DimensionsValidationError, "#{movie.width}x#{movie.height} videos are not supported" if movie.width * movie.height > MAX_VIDEO_MATRIX_LIMIT + raise Mastodon::DimensionsValidationError, "#{movie.frame_rate.to_i}fps videos are not supported" if movie.frame_rate > MAX_VIDEO_FRAME_RATE + end + def set_meta meta = populate_meta -- cgit From 8a2b8e0321691ceab1c0c0c00c686d71cb065ae6 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 9 Mar 2020 02:20:18 +0100 Subject: Change video uploads to always be converted to H264/MP4 (#13220) Even if the container format is the same (.mp4), the codec could be different and not playable in web browsers --- app/models/media_attachment.rb | 52 +++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) (limited to 'app') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 49e2e5e27..7c9b4b909 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -57,6 +57,26 @@ class MediaAttachment < ApplicationRecord }, }.freeze + VIDEO_FORMAT = { + format: 'mp4', + content_type: 'video/mp4', + convert_options: { + output: { + 'loglevel' => 'fatal', + 'movflags' => 'faststart', + 'pix_fmt' => 'yuv420p', + 'vf' => 'scale=\'trunc(iw/2)*2:trunc(ih/2)*2\'', + 'vsync' => 'cfr', + 'c:v' => 'h264', + 'maxrate' => '1300K', + 'bufsize' => '1300K', + 'frames:v' => 60 * 60 * 3, + 'crf' => 18, + 'map_metadata' => '-1', + }, + }, + }.freeze + VIDEO_STYLES = { small: { convert_options: { @@ -71,17 +91,7 @@ class MediaAttachment < ApplicationRecord blurhash: BLURHASH_OPTIONS, }, - original: { - keep_same_format: true, - convert_options: { - output: { - 'loglevel' => 'fatal', - 'map_metadata' => '-1', - 'c:v' => 'copy', - 'c:a' => 'copy', - }, - }, - }, + original: VIDEO_FORMAT, }.freeze AUDIO_STYLES = { @@ -98,26 +108,6 @@ class MediaAttachment < ApplicationRecord }, }.freeze - VIDEO_FORMAT = { - format: 'mp4', - content_type: 'video/mp4', - convert_options: { - output: { - 'loglevel' => 'fatal', - 'movflags' => 'faststart', - 'pix_fmt' => 'yuv420p', - 'vf' => 'scale=\'trunc(iw/2)*2:trunc(ih/2)*2\'', - 'vsync' => 'cfr', - 'c:v' => 'h264', - 'maxrate' => '1300K', - 'bufsize' => '1300K', - 'frames:v' => 60 * 60 * 3, - 'crf' => 18, - 'map_metadata' => '-1', - }, - }, - }.freeze - VIDEO_CONVERTED_STYLES = { small: VIDEO_STYLES[:small], original: VIDEO_FORMAT, -- cgit From 310d729745ad34b1b039f2ec611b9bda5b73f252 Mon Sep 17 00:00:00 2001 From: mayaeh Date: Mon, 9 Mar 2020 17:13:21 +0900 Subject: Change the string "hidden" to "blocked" in WebUI (#13221) * Change the string "hidden" to "blocked" in WebUI. * update --- app/javascript/mastodon/components/domain.js | 2 +- app/javascript/mastodon/containers/domain_container.js | 2 +- .../mastodon/features/account/components/header.js | 4 ++-- app/javascript/mastodon/features/domain_blocks/index.js | 6 +++--- app/javascript/mastodon/locales/defaultMessages.json | 12 ++++++------ app/javascript/mastodon/locales/en.json | 10 +++++----- 6 files changed, 18 insertions(+), 18 deletions(-) (limited to 'app') diff --git a/app/javascript/mastodon/components/domain.js b/app/javascript/mastodon/components/domain.js index 85729ca94..697065d87 100644 --- a/app/javascript/mastodon/components/domain.js +++ b/app/javascript/mastodon/components/domain.js @@ -5,7 +5,7 @@ import { defineMessages, injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; const messages = defineMessages({ - unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' }, + unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unblock domain {domain}' }, }); export default @injectIntl diff --git a/app/javascript/mastodon/containers/domain_container.js b/app/javascript/mastodon/containers/domain_container.js index 813178bbf..8a8ba1df1 100644 --- a/app/javascript/mastodon/containers/domain_container.js +++ b/app/javascript/mastodon/containers/domain_container.js @@ -6,7 +6,7 @@ import Domain from '../components/domain'; import { openModal } from '../actions/modal'; const messages = defineMessages({ - blockDomainConfirm: { id: 'confirmations.domain_block.confirm', defaultMessage: 'Hide entire domain' }, + blockDomainConfirm: { id: 'confirmations.domain_block.confirm', defaultMessage: 'Block entire domain' }, }); const makeMapStateToProps = () => { diff --git a/app/javascript/mastodon/features/account/components/header.js b/app/javascript/mastodon/features/account/components/header.js index 35cc3952f..92780a70b 100644 --- a/app/javascript/mastodon/features/account/components/header.js +++ b/app/javascript/mastodon/features/account/components/header.js @@ -39,7 +39,7 @@ const messages = defineMessages({ favourites: { id: 'navigation_bar.favourites', defaultMessage: 'Favourites' }, lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' }, blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' }, - domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' }, + domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Blocked domains' }, mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' }, endorse: { id: 'account.endorse', defaultMessage: 'Feature on profile' }, unendorse: { id: 'account.unendorse', defaultMessage: 'Don\'t feature on profile' }, @@ -142,7 +142,7 @@ class Header extends ImmutablePureComponent { if (me !== account.get('id') && account.getIn(['relationship', 'muting'])) { info.push(); } else if (me !== account.get('id') && account.getIn(['relationship', 'domain_blocking'])) { - info.push(); + info.push(); } if (me !== account.get('id')) { diff --git a/app/javascript/mastodon/features/domain_blocks/index.js b/app/javascript/mastodon/features/domain_blocks/index.js index 06533d5ac..a6d988912 100644 --- a/app/javascript/mastodon/features/domain_blocks/index.js +++ b/app/javascript/mastodon/features/domain_blocks/index.js @@ -13,8 +13,8 @@ import { fetchDomainBlocks, expandDomainBlocks } from '../../actions/domain_bloc import ScrollableList from '../../components/scrollable_list'; const messages = defineMessages({ - heading: { id: 'column.domain_blocks', defaultMessage: 'Hidden domains' }, - unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' }, + heading: { id: 'column.domain_blocks', defaultMessage: 'Blocked domains' }, + unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unblock domain {domain}' }, }); const mapStateToProps = state => ({ @@ -55,7 +55,7 @@ class Blocks extends ImmutablePureComponent { ); } - const emptyMessage = ; + const emptyMessage = ; return ( diff --git a/app/javascript/mastodon/locales/defaultMessages.json b/app/javascript/mastodon/locales/defaultMessages.json index d9c1c421f..4b971000c 100644 --- a/app/javascript/mastodon/locales/defaultMessages.json +++ b/app/javascript/mastodon/locales/defaultMessages.json @@ -523,7 +523,7 @@ { "descriptors": [ { - "defaultMessage": "Hide entire domain", + "defaultMessage": "Block entire domain", "id": "confirmations.domain_block.confirm" }, { @@ -737,7 +737,7 @@ "id": "navigation_bar.blocks" }, { - "defaultMessage": "Hidden domains", + "defaultMessage": "Blocked domains", "id": "navigation_bar.domain_blocks" }, { @@ -773,7 +773,7 @@ "id": "account.muted" }, { - "defaultMessage": "Domain hidden", + "defaultMessage": "Domain blocked", "id": "account.domain_blocked" }, { @@ -1466,7 +1466,7 @@ { "descriptors": [ { - "defaultMessage": "Hidden domains", + "defaultMessage": "Blocked domains", "id": "column.domain_blocks" }, { @@ -1474,7 +1474,7 @@ "id": "account.unblock_domain" }, { - "defaultMessage": "There are no hidden domains yet.", + "defaultMessage": "There are no blocked domains yet.", "id": "empty_column.domain_blocks" } ], @@ -2944,4 +2944,4 @@ ], "path": "app/javascript/mastodon/features/video/index.json" } -] +] \ No newline at end of file diff --git a/app/javascript/mastodon/locales/en.json b/app/javascript/mastodon/locales/en.json index 1a8fdd295..5d0b71f59 100644 --- a/app/javascript/mastodon/locales/en.json +++ b/app/javascript/mastodon/locales/en.json @@ -7,7 +7,7 @@ "account.blocked": "Blocked", "account.cancel_follow_request": "Cancel follow request", "account.direct": "Direct message @{name}", - "account.domain_blocked": "Domain hidden", + "account.domain_blocked": "Domain blocked", "account.edit_profile": "Edit profile", "account.endorse": "Feature on profile", "account.follow": "Follow", @@ -57,7 +57,7 @@ "column.community": "Local timeline", "column.direct": "Direct messages", "column.directory": "Browse profiles", - "column.domain_blocks": "Hidden domains", + "column.domain_blocks": "Blocked domains", "column.favourites": "Favourites", "column.follow_requests": "Follow requests", "column.home": "Home", @@ -103,7 +103,7 @@ "confirmations.delete.message": "Are you sure you want to delete this status?", "confirmations.delete_list.confirm": "Delete", "confirmations.delete_list.message": "Are you sure you want to permanently delete this list?", - "confirmations.domain_block.confirm": "Hide entire domain", + "confirmations.domain_block.confirm": "Block entire domain", "confirmations.domain_block.message": "Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed.", "confirmations.logout.confirm": "Log out", "confirmations.logout.message": "Are you sure you want to log out?", @@ -146,7 +146,7 @@ "empty_column.bookmarked_statuses": "You don't have any bookmarked toots yet. When you bookmark one, it will show up here.", "empty_column.community": "The local timeline is empty. Write something publicly to get the ball rolling!", "empty_column.direct": "You don't have any direct messages yet. When you send or receive one, it will show up here.", - "empty_column.domain_blocks": "There are no hidden domains yet.", + "empty_column.domain_blocks": "There are no blocked domains yet.", "empty_column.favourited_statuses": "You don't have any favourite toots yet. When you favourite one, it will show up here.", "empty_column.favourites": "No one has favourited this toot yet. When someone does, they will show up here.", "empty_column.follow_requests": "You don't have any follow requests yet. When you receive one, it will show up here.", @@ -265,7 +265,7 @@ "navigation_bar.compose": "Compose new toot", "navigation_bar.direct": "Direct messages", "navigation_bar.discover": "Discover", - "navigation_bar.domain_blocks": "Hidden domains", + "navigation_bar.domain_blocks": "Blocked domains", "navigation_bar.edit_profile": "Edit profile", "navigation_bar.favourites": "Favourites", "navigation_bar.filters": "Muted words", -- cgit From abd839488054b6de2dec9e7ec095d79e4a106573 Mon Sep 17 00:00:00 2001 From: ThibG Date: Mon, 9 Mar 2020 23:15:59 +0100 Subject: Fix MP4 (H264 + AAC) video files being needlessly re-encoded (#13239) --- app/models/media_attachment.rb | 18 +++++++++++++++++- lib/paperclip/video_transcoder.rb | 16 ++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 7c9b4b909..9ca0a6cda 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -77,6 +77,22 @@ class MediaAttachment < ApplicationRecord }, }.freeze + VIDEO_PASSTHROUGH_OPTIONS = { + video_codec_whitelist: ['h264'], + audio_codec_whitelist: ['aac', nil], + options: { + format: 'mp4', + convert_options: { + output: { + 'loglevel' => 'fatal', + 'map_metadata' => '-1', + 'c:v' => 'copy', + 'c:a' => 'copy', + }, + }, + }, + }.freeze + VIDEO_STYLES = { small: { convert_options: { @@ -91,7 +107,7 @@ class MediaAttachment < ApplicationRecord blurhash: BLURHASH_OPTIONS, }, - original: VIDEO_FORMAT, + original: VIDEO_FORMAT.merge(passthrough_options: VIDEO_PASSTHROUGH_OPTIONS), }.freeze AUDIO_STYLES = { diff --git a/lib/paperclip/video_transcoder.rb b/lib/paperclip/video_transcoder.rb index 66f7feda5..0de548964 100644 --- a/lib/paperclip/video_transcoder.rb +++ b/lib/paperclip/video_transcoder.rb @@ -5,12 +5,20 @@ module Paperclip # to check when uploaded videos are actually gifv's class VideoTranscoder < Paperclip::Processor def make - meta = ::Av.cli.identify(@file.path) + movie = FFMPEG::Movie.new(@file.path) + actual_options = options + passthrough_options = actual_options[:passthrough_options] + actual_options = passthrough_options[:options] if passthrough?(movie, passthrough_options) - attachment.instance.type = MediaAttachment.types[:gifv] unless meta[:audio_encode] - options[:format] = File.extname(attachment.instance.file_file_name)[1..-1] if options[:keep_same_format] + attachment.instance.type = MediaAttachment.types[:gifv] unless movie.audio_codec - Paperclip::Transcoder.make(file, options, attachment) + Paperclip::Transcoder.make(file, actual_options, attachment) + end + + private + + def passthrough?(movie, options) + options && options[:video_codec_whitelist].include?(movie.video_codec) && options[:audio_codec_whitelist].include?(movie.audio_codec) end end end -- cgit From 2c6099125d9ed5c2add62e84d5ba7b93de658910 Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 10 Mar 2020 11:58:40 +0100 Subject: Fix videos with unsupported colorspace not being transcoded (#13242) --- app/models/media_attachment.rb | 5 +++-- lib/paperclip/video_transcoder.rb | 14 ++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 9ca0a6cda..31aa918b7 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -78,8 +78,9 @@ class MediaAttachment < ApplicationRecord }.freeze VIDEO_PASSTHROUGH_OPTIONS = { - video_codec_whitelist: ['h264'], - audio_codec_whitelist: ['aac', nil], + video_codecs: ['h264'], + audio_codecs: ['aac', nil], + colorspaces: ['yuv420p'], options: { format: 'mp4', convert_options: { diff --git a/lib/paperclip/video_transcoder.rb b/lib/paperclip/video_transcoder.rb index 0de548964..4d9544231 100644 --- a/lib/paperclip/video_transcoder.rb +++ b/lib/paperclip/video_transcoder.rb @@ -6,19 +6,21 @@ module Paperclip class VideoTranscoder < Paperclip::Processor def make movie = FFMPEG::Movie.new(@file.path) - actual_options = options - passthrough_options = actual_options[:passthrough_options] - actual_options = passthrough_options[:options] if passthrough?(movie, passthrough_options) attachment.instance.type = MediaAttachment.types[:gifv] unless movie.audio_codec - Paperclip::Transcoder.make(file, actual_options, attachment) + Paperclip::Transcoder.make(file, actual_options(movie), attachment) end private - def passthrough?(movie, options) - options && options[:video_codec_whitelist].include?(movie.video_codec) && options[:audio_codec_whitelist].include?(movie.audio_codec) + def actual_options(movie) + opts = options[:passthrough_options] + if opts && opts[:video_codecs].include?(movie.video_codec) && opts[:audio_codecs].include?(movie.audio_codec) && opts[:colorspaces].include?(movie.colorspace) + opts[:options] + else + options + end end end end -- cgit From 90f3a0006243250ced6e7e192f81513d6b731b33 Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 10 Mar 2020 11:59:44 +0100 Subject: Fix regression in “Edit media” modal in web UI (#13243) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/mastodon/actions/compose.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index 68ef8fbd5..6b73fc90e 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -245,7 +245,7 @@ export function uploadCompose(files) { const poll = () => { api(getState).get(`/api/v1/media/${data.id}`).then(response => { if (response.status === 200) { - dispatch(uploadComposeSuccess(data, f)); + dispatch(uploadComposeSuccess(response.data, f)); } else if (response.status === 206) { setTimeout(() => poll(), 1000); } -- cgit From aeebbe90dc8224ae8bc9ac81fb68435105edb293 Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 10 Mar 2020 18:39:47 +0100 Subject: Fix detailed view of direct messages displaying a 0 boost count (#13244) The boost count is already removed from private toots, do the same with direct messages. --- app/javascript/mastodon/features/status/components/detailed_status.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/javascript/mastodon/features/status/components/detailed_status.js b/app/javascript/mastodon/features/status/components/detailed_status.js index 2fec247c1..7a82fa13a 100644 --- a/app/javascript/mastodon/features/status/components/detailed_status.js +++ b/app/javascript/mastodon/features/status/components/detailed_status.js @@ -166,7 +166,7 @@ export default class DetailedStatus extends ImmutablePureComponent { reblogIcon = 'lock'; } - if (status.get('visibility') === 'private') { + if (['private', 'direct'].includes(status.get('visibility'))) { reblogLink = ; } else if (this.context.router) { reblogLink = ( -- cgit From f556f79b7733834430b93109ac2c7f87529c8574 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 12 Mar 2020 17:57:59 +0100 Subject: Add titles to warning presets in admin UI (#13252) --- .../admin/warning_presets_controller.rb | 6 +++--- app/models/account_warning_preset.rb | 3 +++ app/views/admin/account_actions/new.html.haml | 2 +- .../warning_presets/_warning_preset.html.haml | 10 +++++++++ app/views/admin/warning_presets/edit.html.haml | 3 +++ app/views/admin/warning_presets/index.html.haml | 24 ++++++++-------------- config/locales/ar.yml | 1 - config/locales/ca.yml | 1 - config/locales/co.yml | 1 - config/locales/cs.yml | 1 - config/locales/cy.yml | 1 - config/locales/da.yml | 1 - config/locales/de.yml | 1 - config/locales/el.yml | 1 - config/locales/en.yml | 1 - config/locales/en_GB.yml | 1 - config/locales/eo.yml | 1 - config/locales/es-AR.yml | 1 - config/locales/es.yml | 1 - config/locales/et.yml | 1 - config/locales/eu.yml | 1 - config/locales/fa.yml | 1 - config/locales/fr.yml | 1 - config/locales/gl.yml | 1 - config/locales/hu.yml | 1 - config/locales/id.yml | 1 - config/locales/is.yml | 1 - config/locales/it.yml | 1 - config/locales/ja.yml | 1 - config/locales/kab.yml | 1 - config/locales/kk.yml | 1 - config/locales/ko.yml | 1 - config/locales/lt.yml | 1 - config/locales/nl.yml | 1 - config/locales/nn.yml | 1 - config/locales/no.yml | 1 - config/locales/oc.yml | 1 - config/locales/pl.yml | 1 - config/locales/pt-BR.yml | 1 - config/locales/pt-PT.yml | 1 - config/locales/ru.yml | 1 - config/locales/simple_form.en.yml | 2 ++ config/locales/sk.yml | 1 - config/locales/sl.yml | 1 - config/locales/sq.yml | 1 - config/locales/sr.yml | 1 - config/locales/sv.yml | 1 - config/locales/th.yml | 1 - config/locales/tr.yml | 1 - config/locales/uk.yml | 1 - config/locales/vi.yml | 1 - config/locales/zh-CN.yml | 1 - config/locales/zh-HK.yml | 1 - config/locales/zh-TW.yml | 1 - ...2144258_add_title_to_account_warning_presets.rb | 15 ++++++++++++++ db/schema.rb | 3 ++- 56 files changed, 48 insertions(+), 67 deletions(-) create mode 100644 app/views/admin/warning_presets/_warning_preset.html.haml create mode 100644 db/migrate/20200312144258_add_title_to_account_warning_presets.rb (limited to 'app') diff --git a/app/controllers/admin/warning_presets_controller.rb b/app/controllers/admin/warning_presets_controller.rb index 37be842c5..b376f8d9b 100644 --- a/app/controllers/admin/warning_presets_controller.rb +++ b/app/controllers/admin/warning_presets_controller.rb @@ -7,7 +7,7 @@ module Admin def index authorize :account_warning_preset, :index? - @warning_presets = AccountWarningPreset.all + @warning_presets = AccountWarningPreset.alphabetic @warning_preset = AccountWarningPreset.new end @@ -19,7 +19,7 @@ module Admin if @warning_preset.save redirect_to admin_warning_presets_path else - @warning_presets = AccountWarningPreset.all + @warning_presets = AccountWarningPreset.alphabetic render :index end end @@ -52,7 +52,7 @@ module Admin end def warning_preset_params - params.require(:account_warning_preset).permit(:text) + params.require(:account_warning_preset).permit(:title, :text) end end end diff --git a/app/models/account_warning_preset.rb b/app/models/account_warning_preset.rb index ba8ceabb3..c20f683cf 100644 --- a/app/models/account_warning_preset.rb +++ b/app/models/account_warning_preset.rb @@ -8,8 +8,11 @@ # text :text default(""), not null # created_at :datetime not null # updated_at :datetime not null +# title :string default(""), not null # class AccountWarningPreset < ApplicationRecord validates :text, presence: true + + scope :alphabetic, -> { order(title: :asc, text: :asc) } end diff --git a/app/views/admin/account_actions/new.html.haml b/app/views/admin/account_actions/new.html.haml index 20fbeef33..aa88b1448 100644 --- a/app/views/admin/account_actions/new.html.haml +++ b/app/views/admin/account_actions/new.html.haml @@ -21,7 +21,7 @@ - unless @warning_presets.empty? .fields-group - = f.input :warning_preset_id, collection: @warning_presets, label_method: :text, wrapper: :with_block_label + = f.input :warning_preset_id, collection: @warning_presets, label_method: ->(warning_preset) { [warning_preset.title.presence, truncate(warning_preset.text)].compact.join(' - ') }, wrapper: :with_block_label .fields-group = f.input :text, as: :text, wrapper: :with_block_label, hint: t('simple_form.hints.admin_account_action.text_html', path: admin_warning_presets_path) diff --git a/app/views/admin/warning_presets/_warning_preset.html.haml b/app/views/admin/warning_presets/_warning_preset.html.haml new file mode 100644 index 000000000..a58199c80 --- /dev/null +++ b/app/views/admin/warning_presets/_warning_preset.html.haml @@ -0,0 +1,10 @@ +.announcements-list__item + = link_to edit_admin_warning_preset_path(warning_preset), class: 'announcements-list__item__title' do + = warning_preset.title.presence || truncate(warning_preset.text) + + .announcements-list__item__action-bar + .announcements-list__item__meta + = truncate(warning_preset.text) + + %div + = table_link_to 'trash', t('admin.warning_presets.delete'), admin_warning_preset_path(warning_preset), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:destroy, warning_preset) diff --git a/app/views/admin/warning_presets/edit.html.haml b/app/views/admin/warning_presets/edit.html.haml index 9522746cd..b5c5107ef 100644 --- a/app/views/admin/warning_presets/edit.html.haml +++ b/app/views/admin/warning_presets/edit.html.haml @@ -4,6 +4,9 @@ = simple_form_for @warning_preset, url: admin_warning_preset_path(@warning_preset) do |f| = render 'shared/error_messages', object: @warning_preset + .fields-group + = f.input :title, wrapper: :with_block_label + .fields-group = f.input :text, wrapper: :with_block_label diff --git a/app/views/admin/warning_presets/index.html.haml b/app/views/admin/warning_presets/index.html.haml index 45913ef73..dbc23fa30 100644 --- a/app/views/admin/warning_presets/index.html.haml +++ b/app/views/admin/warning_presets/index.html.haml @@ -5,6 +5,9 @@ = simple_form_for @warning_preset, url: admin_warning_presets_path do |f| = render 'shared/error_messages', object: @warning_preset + .fields-group + = f.input :title, wrapper: :with_block_label + .fields-group = f.input :text, wrapper: :with_block_label @@ -13,18 +16,9 @@ %hr.spacer/ -- unless @warning_presets.empty? - .table-wrapper - %table.table - %thead - %tr - %th= t('simple_form.labels.account_warning_preset.text') - %th - %tbody - - @warning_presets.each do |preset| - %tr - %td - = Formatter.instance.linkify(preset.text) - %td - = table_link_to 'pencil', t('admin.warning_presets.edit'), edit_admin_warning_preset_path(preset) - = table_link_to 'trash', t('admin.warning_presets.delete'), admin_warning_preset_path(preset), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } +- if @warning_presets.empty? + %div.muted-hint.center-text + = t 'admin.warning_presets.empty' +- else + .announcements-list + = render partial: 'warning_preset', collection: @warning_presets diff --git a/config/locales/ar.yml b/config/locales/ar.yml index f5a6f067d..5c73967d6 100644 --- a/config/locales/ar.yml +++ b/config/locales/ar.yml @@ -562,7 +562,6 @@ ar: warning_presets: add_new: إضافة واحد جديد delete: حذف - edit: تعديل edit_preset: تعديل نموذج التحذير title: إدارة نماذج التحذير admin_mailer: diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 1c30b6b7a..22782ae16 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -573,7 +573,6 @@ ca: warning_presets: add_new: Afegeix-ne un de nou delete: Esborra - edit: Edita edit_preset: Edita l'avís predeterminat title: Gestiona les configuracions predefinides dels avisos admin_mailer: diff --git a/config/locales/co.yml b/config/locales/co.yml index 24f7f45fc..d9127a385 100644 --- a/config/locales/co.yml +++ b/config/locales/co.yml @@ -573,7 +573,6 @@ co: warning_presets: add_new: Aghjunghje delete: Sguassà - edit: Cambià edit_preset: Cambià a preselezzione d'avertimentu title: Amministrà e preselezzione d'avertimentu admin_mailer: diff --git a/config/locales/cs.yml b/config/locales/cs.yml index bab669e7e..23161ec5c 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -588,7 +588,6 @@ cs: warning_presets: add_new: Přidat nové delete: Smazat - edit: Upravit edit_preset: Upravit předlohu pro varování title: Spravovat předlohy pro varování admin_mailer: diff --git a/config/locales/cy.yml b/config/locales/cy.yml index afca0212a..a9e8a26da 100644 --- a/config/locales/cy.yml +++ b/config/locales/cy.yml @@ -605,7 +605,6 @@ cy: warning_presets: add_new: Ychwanegu newydd delete: Dileu - edit: Golygu edit_preset: Golygu rhagosodiad rhybudd title: Rheoli rhagosodiadau rhybudd admin_mailer: diff --git a/config/locales/da.yml b/config/locales/da.yml index 1cdf7722e..c978029b3 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -489,7 +489,6 @@ da: most_recent: Seneste warning_presets: delete: Slet - edit: Rediger admin_mailer: new_report: body: "%{reporter} har anmeldt %{target}" diff --git a/config/locales/de.yml b/config/locales/de.yml index 50f994473..6907efc60 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -573,7 +573,6 @@ de: warning_presets: add_new: Neu hinzufügen delete: Löschen - edit: Bearbeiten edit_preset: Warnungsvorlage bearbeiten title: Warnungsvorlagen verwalten admin_mailer: diff --git a/config/locales/el.yml b/config/locales/el.yml index 85c7bc648..dd9c93172 100644 --- a/config/locales/el.yml +++ b/config/locales/el.yml @@ -573,7 +573,6 @@ el: warning_presets: add_new: Πρόσθεση νέου delete: Διαγραφή - edit: Ενημέρωση edit_preset: Ενημέρωση προκαθορισμένης προειδοποίησης title: Διαχείριση προκαθορισμένων προειδοποιήσεων admin_mailer: diff --git a/config/locales/en.yml b/config/locales/en.yml index a031f9e9d..05d92b121 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -576,7 +576,6 @@ en: warning_presets: add_new: Add new delete: Delete - edit: Edit edit_preset: Edit warning preset title: Manage warning presets admin_mailer: diff --git a/config/locales/en_GB.yml b/config/locales/en_GB.yml index 0742559ed..1375ebb33 100644 --- a/config/locales/en_GB.yml +++ b/config/locales/en_GB.yml @@ -474,7 +474,6 @@ en_GB: warning_presets: add_new: Add new delete: Delete - edit: Edit edit_preset: Edit warning preset title: Manage warning presets admin_mailer: diff --git a/config/locales/eo.yml b/config/locales/eo.yml index b3cb2b523..32771b4c4 100644 --- a/config/locales/eo.yml +++ b/config/locales/eo.yml @@ -557,7 +557,6 @@ eo: warning_presets: add_new: Aldoni novan delete: Forigi - edit: Redakti edit_preset: Redakti avertan antaŭagordon title: Administri avertajn antaŭagordojn admin_mailer: diff --git a/config/locales/es-AR.yml b/config/locales/es-AR.yml index 6eec00cb6..67fb83de2 100644 --- a/config/locales/es-AR.yml +++ b/config/locales/es-AR.yml @@ -573,7 +573,6 @@ es-AR: warning_presets: add_new: Agregar nuevo delete: Eliminar - edit: Editar edit_preset: Editar preajuste de advertencia title: Administrar preajustes de advertencia admin_mailer: diff --git a/config/locales/es.yml b/config/locales/es.yml index a26143018..3acf29b15 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -573,7 +573,6 @@ es: warning_presets: add_new: Añadir nuevo delete: Borrar - edit: Editar edit_preset: Editar aviso predeterminado title: Editar configuración predeterminada de avisos admin_mailer: diff --git a/config/locales/et.yml b/config/locales/et.yml index 716da9010..8e3d56622 100644 --- a/config/locales/et.yml +++ b/config/locales/et.yml @@ -576,7 +576,6 @@ et: warning_presets: add_new: Lisa uus delete: Kustuta - edit: Redigeeri edit_preset: Redigeeri hoiatuse eelseadistust title: Halda hoiatuste eelseadistusi admin_mailer: diff --git a/config/locales/eu.yml b/config/locales/eu.yml index 3ca68d321..e44fc61b0 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -573,7 +573,6 @@ eu: warning_presets: add_new: Gehitu berria delete: Ezabatu - edit: Editatu edit_preset: Editatu abisu aurre-ezarpena title: Kudeatu abisu aurre-ezarpenak admin_mailer: diff --git a/config/locales/fa.yml b/config/locales/fa.yml index 02bbd2938..aca4df69b 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -575,7 +575,6 @@ fa: warning_presets: add_new: افزودن تازه delete: زدودن - edit: ویرایش edit_preset: ویرایش هشدار پیش‌فرض title: مدیریت هشدارهای پیش‌فرض admin_mailer: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index bf79bc0ff..c1d8cc2bf 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -573,7 +573,6 @@ fr: warning_presets: add_new: Ajouter un nouveau delete: Effacer - edit: Éditer edit_preset: Éditer les avertissements prédéfinis title: Gérer les avertissements prédéfinis admin_mailer: diff --git a/config/locales/gl.yml b/config/locales/gl.yml index c3a33932d..9f0f16b5b 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -573,7 +573,6 @@ gl: warning_presets: add_new: Engadir novo delete: Eliminar - edit: Editar edit_preset: Editar aviso preestablecido title: Xestionar avisos preestablecidos admin_mailer: diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 2d7f3a137..c6b619dd2 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -575,7 +575,6 @@ hu: warning_presets: add_new: Új hozzáadása delete: Törlés - edit: Szerkesztés edit_preset: Figyelmeztetés szerkesztése title: Figyelmeztetések admin_mailer: diff --git a/config/locales/id.yml b/config/locales/id.yml index ca222946c..bfa71184f 100644 --- a/config/locales/id.yml +++ b/config/locales/id.yml @@ -565,7 +565,6 @@ id: warning_presets: add_new: Tambah baru delete: Hapus - edit: Sunting edit_preset: Sunting preset peringatan title: Kelola preset peringatan admin_mailer: diff --git a/config/locales/is.yml b/config/locales/is.yml index d6cf23966..336533d52 100644 --- a/config/locales/is.yml +++ b/config/locales/is.yml @@ -573,7 +573,6 @@ is: warning_presets: add_new: Bæta við nýju delete: Eyða - edit: Breyta edit_preset: Breyta forstilltri aðvörun title: Sýsla með forstilltar aðvaranir admin_mailer: diff --git a/config/locales/it.yml b/config/locales/it.yml index 2ccdc076c..636ae8924 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -573,7 +573,6 @@ it: warning_presets: add_new: Aggiungi nuovo delete: Cancella - edit: Modifica edit_preset: Modifica avviso predefinito title: Gestisci avvisi predefiniti admin_mailer: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 24a159e57..c2a16fa15 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -565,7 +565,6 @@ ja: warning_presets: add_new: 追加 delete: 削除 - edit: 編集 edit_preset: プリセット警告文を編集 title: プリセット警告文を管理 admin_mailer: diff --git a/config/locales/kab.yml b/config/locales/kab.yml index 03f4d8c13..b398bebd9 100644 --- a/config/locales/kab.yml +++ b/config/locales/kab.yml @@ -330,7 +330,6 @@ kab: warning_presets: add_new: Rnu amaynut delete: Kkes - edit: Ẓreg admin_mailer: new_report: subject: Aneqqis amaynut i %{instance} (#%{id}) diff --git a/config/locales/kk.yml b/config/locales/kk.yml index 416a5fc7d..bb7a57e87 100644 --- a/config/locales/kk.yml +++ b/config/locales/kk.yml @@ -555,7 +555,6 @@ kk: warning_presets: add_new: Add nеw delete: Deletе - edit: Еdit edit_preset: Edit warning prеset title: Manage warning presеts admin_mailer: diff --git a/config/locales/ko.yml b/config/locales/ko.yml index e70fbef21..6ca0b2acc 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -567,7 +567,6 @@ ko: warning_presets: add_new: 새로 추가 delete: 삭제 - edit: 편집 edit_preset: 경고 틀 수정 title: 경고 틀 관리 admin_mailer: diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 9af094c01..5a4542ea8 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -410,7 +410,6 @@ lt: warning_presets: add_new: Pridėti naują delete: Ištrinti - edit: Keisti edit_preset: Keisti įspėjimo nustatymus title: Valdyti įspėjimo nustatymus admin_mailer: diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 976072368..f688d5dbd 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -573,7 +573,6 @@ nl: warning_presets: add_new: Nieuwe toevoegen delete: Verwijderen - edit: Bewerken edit_preset: Voorinstelling van waarschuwing bewerken title: Voorinstellingen van waarschuwingen beheren admin_mailer: diff --git a/config/locales/nn.yml b/config/locales/nn.yml index fd61f2156..07b6397c6 100644 --- a/config/locales/nn.yml +++ b/config/locales/nn.yml @@ -566,7 +566,6 @@ nn: warning_presets: add_new: Legg til ny delete: Slett - edit: Rediger edit_preset: Endr åtvaringsoppsett title: Handsam åtvaringsoppsett admin_mailer: diff --git a/config/locales/no.yml b/config/locales/no.yml index 256ed99a3..4a1b859dc 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -561,7 +561,6 @@ warning_presets: add_new: Legg til ny delete: Slett - edit: Rediger admin_mailer: new_pending_account: body: Detaljer om den nye kontoen er nedenfor. Du kan godkjenne eller avvise denne søknaden. diff --git a/config/locales/oc.yml b/config/locales/oc.yml index 4a60227ab..d3f3a1007 100644 --- a/config/locales/oc.yml +++ b/config/locales/oc.yml @@ -558,7 +558,6 @@ oc: warning_presets: add_new: N’ajustar un nòu delete: Escafar - edit: Modificar edit_preset: Modificar lo tèxt predefinit d’avertiment title: Gerir los tèxtes predefinits admin_mailer: diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 28a486145..339e87fa8 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -541,7 +541,6 @@ pl: warning_presets: add_new: Dodaj nowy delete: Usuń - edit: Edytuj edit_preset: Edytuj szablon ostrzeżenia title: Zarządzaj szablonami ostrzeżeń admin_mailer: diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index abea40130..419ea5a73 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -573,7 +573,6 @@ pt-BR: warning_presets: add_new: Adicionar novo delete: Excluir - edit: Editar edit_preset: Editar o aviso pré-definido title: Gerenciar os avisos pré-definidos admin_mailer: diff --git a/config/locales/pt-PT.yml b/config/locales/pt-PT.yml index 477c9d3a3..9d3a503b1 100644 --- a/config/locales/pt-PT.yml +++ b/config/locales/pt-PT.yml @@ -573,7 +573,6 @@ pt-PT: warning_presets: add_new: Adicionar novo delete: Apagar - edit: Editar edit_preset: Editar o aviso predefinido title: Gerir os avisos predefinidos admin_mailer: diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 6196ac3eb..f1547ddf2 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -594,7 +594,6 @@ ru: warning_presets: add_new: Добавить delete: Удалить - edit: Изменить edit_preset: Удалить шаблон предупреждения title: Управление шаблонами предупреждений admin_mailer: diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 92d51916b..f279a8e4f 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -8,6 +8,7 @@ en: acct: Specify the username@domain of the account you want to move to account_warning_preset: text: You can use toot syntax, such as URLs, hashtags and mentions + title: Optional. Not visible to the recipient admin_account_action: include_statuses: The user will see which toots have caused the moderation action or warning send_email_notification: The user will receive an explanation of what happened with their account @@ -78,6 +79,7 @@ en: acct: Handle of the new account account_warning_preset: text: Preset text + title: Title admin_account_action: include_statuses: Include reported toots in the e-mail send_email_notification: Notify the user per e-mail diff --git a/config/locales/sk.yml b/config/locales/sk.yml index dbee6bb12..2986f83d8 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -574,7 +574,6 @@ sk: warning_presets: add_new: Pridaj nové delete: Vymaž - edit: Uprav edit_preset: Uprav varovnú predlohu title: Spravuj varovné predlohy admin_mailer: diff --git a/config/locales/sl.yml b/config/locales/sl.yml index afb928f11..91720c602 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -485,7 +485,6 @@ sl: warning_presets: add_new: Dodaj novo delete: Izbriši - edit: Uredi edit_preset: Uredi prednastavitev opozoril title: Upravljaj prednastavitev opozoril admin_mailer: diff --git a/config/locales/sq.yml b/config/locales/sq.yml index 6a7a945c4..0e20902ff 100644 --- a/config/locales/sq.yml +++ b/config/locales/sq.yml @@ -415,7 +415,6 @@ sq: warning_presets: add_new: Shtoni të ri delete: Fshije - edit: Përpunoni edit_preset: Përpunoni sinjalizim të paracaktuar title: Administroni sinjalizime të paracaktuara admin_mailer: diff --git a/config/locales/sr.yml b/config/locales/sr.yml index c68681215..d7fb6f74d 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -431,7 +431,6 @@ sr: warning_presets: add_new: Додај нови delete: Избриши - edit: Уреди edit_preset: Уреди пресет упозорења title: Управљај пресетима упозорења admin_mailer: diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 0094ff06b..4b67ff19c 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -448,7 +448,6 @@ sv: warning_presets: add_new: Lägg till ny delete: Radera - edit: Redigera admin_mailer: new_report: body: "%{reporter} har rapporterat %{target}" diff --git a/config/locales/th.yml b/config/locales/th.yml index 7d6ec0b13..53267c805 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -488,7 +488,6 @@ th: warning_presets: add_new: เพิ่มใหม่ delete: ลบ - edit: แก้ไข edit_preset: แก้ไขคำเตือนที่ตั้งไว้ล่วงหน้า title: จัดการคำเตือนที่ตั้งไว้ล่วงหน้า admin_mailer: diff --git a/config/locales/tr.yml b/config/locales/tr.yml index cde7f1c83..1dcf9ccea 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -573,7 +573,6 @@ tr: warning_presets: add_new: Yeni ekle delete: Sil - edit: Düzenle edit_preset: Uyarı ön-ayarını düzenle title: Uyarı ön-ayarlarını yönet admin_mailer: diff --git a/config/locales/uk.yml b/config/locales/uk.yml index 967a02717..3df83e756 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -591,7 +591,6 @@ uk: warning_presets: add_new: Додати новий delete: Видалити - edit: Редагувати edit_preset: Редагувати шаблон попередження title: Управління шаблонами попереджень admin_mailer: diff --git a/config/locales/vi.yml b/config/locales/vi.yml index ec8e853fe..cba773417 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -534,7 +534,6 @@ vi: warning_presets: add_new: Thêm mới delete: Xóa bỏ - edit: Biên tập edit_preset: Chỉnh sửa cảnh báo đặt trước title: Quản lý cài đặt trước cảnh báo admin_mailer: diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index d6618dbbe..54230fb2f 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -565,7 +565,6 @@ zh-CN: warning_presets: add_new: 添加新条目 delete: 删除 - edit: 编辑 edit_preset: 编辑预置警告 title: 管理预设警告 admin_mailer: diff --git a/config/locales/zh-HK.yml b/config/locales/zh-HK.yml index ffd5ba5e9..fd988e443 100644 --- a/config/locales/zh-HK.yml +++ b/config/locales/zh-HK.yml @@ -409,7 +409,6 @@ zh-HK: warning_presets: add_new: 新增 delete: 刪除 - edit: 編輯 admin_mailer: new_report: body: "%{reporter} 舉報了用戶 %{target}" diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 5b25688ed..984bbcf13 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -408,7 +408,6 @@ zh-TW: warning_presets: add_new: 新增 delete: 刪除 - edit: 編輯 admin_mailer: new_report: body: "%{reporter} 檢舉了使用者 %{target}" diff --git a/db/migrate/20200312144258_add_title_to_account_warning_presets.rb b/db/migrate/20200312144258_add_title_to_account_warning_presets.rb new file mode 100644 index 000000000..46a5350e7 --- /dev/null +++ b/db/migrate/20200312144258_add_title_to_account_warning_presets.rb @@ -0,0 +1,15 @@ +require Rails.root.join('lib', 'mastodon', 'migration_helpers') + +class AddTitleToAccountWarningPresets < ActiveRecord::Migration[5.2] + include Mastodon::MigrationHelpers + + disable_ddl_transaction! + + def up + safety_assured { add_column_with_default :account_warning_presets, :title, :string, default: '', allow_null: false } + end + + def down + remove_column :account_warning_presets, :title + end +end diff --git a/db/schema.rb b/db/schema.rb index a851e01fc..5d3651e52 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_03_06_035625) do +ActiveRecord::Schema.define(version: 2020_03_12_144258) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -114,6 +114,7 @@ ActiveRecord::Schema.define(version: 2020_03_06_035625) do t.text "text", default: "", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "title", default: "", null: false end create_table "account_warnings", force: :cascade do |t| -- cgit From bea0bb39d6c1762c97da484ffa8b5d73341e67e2 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 12 Mar 2020 22:35:20 +0100 Subject: Add option to include resolved DNS records when blacklisting e-mail domains in admin UI (#13254) * Add shortcuts to blacklist a user's e-mail domain in admin UI * Add option to blacklist resolved MX and IP records for e-mail domains --- .../admin/email_domain_blocks_controller.rb | 28 +++++++++++++++++++--- app/models/email_domain_block.rb | 14 +++++++++++ app/views/admin/accounts/show.html.haml | 13 +++++++--- .../_email_domain_block.html.haml | 10 ++++++++ app/views/admin/email_domain_blocks/new.html.haml | 5 +++- config/locales/en.yml | 3 +++ config/locales/simple_form.en.yml | 5 ++++ ...2185443_add_parent_id_to_email_domain_blocks.rb | 5 ++++ db/schema.rb | 4 +++- 9 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20200312185443_add_parent_id_to_email_domain_blocks.rb (limited to 'app') diff --git a/app/controllers/admin/email_domain_blocks_controller.rb b/app/controllers/admin/email_domain_blocks_controller.rb index 9fe85064e..c25919726 100644 --- a/app/controllers/admin/email_domain_blocks_controller.rb +++ b/app/controllers/admin/email_domain_blocks_controller.rb @@ -6,12 +6,12 @@ module Admin def index authorize :email_domain_block, :index? - @email_domain_blocks = EmailDomainBlock.page(params[:page]) + @email_domain_blocks = EmailDomainBlock.where(parent_id: nil).includes(:children).order(id: :desc).page(params[:page]) end def new authorize :email_domain_block, :create? - @email_domain_block = EmailDomainBlock.new + @email_domain_block = EmailDomainBlock.new(domain: params[:_domain]) end def create @@ -21,6 +21,28 @@ module Admin if @email_domain_block.save log_action :create, @email_domain_block + + if @email_domain_block.with_dns_records? + hostnames = [] + ips = [] + + Resolv::DNS.open do |dns| + dns.timeouts = 1 + + hostnames = dns.getresources(@email_domain_block.domain, Resolv::DNS::Resource::IN::MX).to_a.map { |e| e.exchange.to_s } + + ([@email_domain_block.domain] + hostnames).uniq.each do |hostname| + ips.concat(dns.getresources(hostname, Resolv::DNS::Resource::IN::A).to_a.map { |e| e.address.to_s }) + ips.concat(dns.getresources(hostname, Resolv::DNS::Resource::IN::AAAA).to_a.map { |e| e.address.to_s }) + end + end + + (hostnames + ips).each do |hostname| + another_email_domain_block = EmailDomainBlock.new(domain: hostname, parent: @email_domain_block) + log_action :create, another_email_domain_block if another_email_domain_block.save + end + end + redirect_to admin_email_domain_blocks_path, notice: I18n.t('admin.email_domain_blocks.created_msg') else render :new @@ -41,7 +63,7 @@ module Admin end def resource_params - params.require(:email_domain_block).permit(:domain) + params.require(:email_domain_block).permit(:domain, :with_dns_records) end end end diff --git a/app/models/email_domain_block.rb b/app/models/email_domain_block.rb index bc70dea25..f50fa46ba 100644 --- a/app/models/email_domain_block.rb +++ b/app/models/email_domain_block.rb @@ -7,13 +7,27 @@ # domain :string default(""), not null # created_at :datetime not null # updated_at :datetime not null +# parent_id :bigint(8) # class EmailDomainBlock < ApplicationRecord include DomainNormalizable + belongs_to :parent, class_name: 'EmailDomainBlock', optional: true + has_many :children, class_name: 'EmailDomainBlock', foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy + validates :domain, presence: true, uniqueness: true, domain: true + def with_dns_records=(val) + @with_dns_records = ActiveModel::Type::Boolean.new.cast(val) + end + + def with_dns_records? + @with_dns_records + end + + alias with_dns_records with_dns_records? + def self.block?(email) _, domain = email.split('@', 2) diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml index a30b78db2..744d17d1f 100644 --- a/app/views/admin/accounts/show.html.haml +++ b/app/views/admin/accounts/show.html.haml @@ -96,10 +96,17 @@ = table_link_to 'angle-double-down', t('admin.accounts.demote'), demote_admin_account_role_path(@account.id), method: :post, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:demote, @account.user) %tr - %th= t('admin.accounts.email') - %td= @account.user_email + %th{ rowspan: can?(:create, :email_domain_block) ? 3 : 2 }= t('admin.accounts.email') + %td{ rowspan: can?(:create, :email_domain_block) ? 3 : 2 }= @account.user_email %td= table_link_to 'edit', t('admin.accounts.change_email.label'), admin_account_change_email_path(@account.id) if can?(:change_email, @account.user) + %tr + %td= table_link_to 'search', t('admin.accounts.search_same_email_domain'), admin_accounts_path(email: "%@#{@account.user_email.split('@').last}") + + - if can?(:create, :email_domain_block) + %tr + %td= table_link_to 'ban', t('admin.accounts.add_email_domain_block'), new_admin_email_domain_block_path(_domain: @account.user_email.split('@').last) + - if @account.user_unconfirmed_email.present? %tr %th= t('admin.accounts.unconfirmed_email') @@ -204,7 +211,7 @@ = link_to t('admin.accounts.perform_full_suspension'), new_admin_account_action_path(@account.id, type: 'suspend'), class: 'button button--destructive' if can?(:suspend, @account) - unless @account.local? - - if DomainBlock.where(domain: @account.domain).exists? + - if DomainBlock.rule_for(@account.domain) = link_to t('admin.domain_blocks.view'), admin_instance_path(@account.domain), class: 'button' - else = link_to t('admin.domain_blocks.add_new'), new_admin_domain_block_path(_domain: @account.domain), class: 'button button--destructive' diff --git a/app/views/admin/email_domain_blocks/_email_domain_block.html.haml b/app/views/admin/email_domain_blocks/_email_domain_block.html.haml index bf66c9001..41ab8c171 100644 --- a/app/views/admin/email_domain_blocks/_email_domain_block.html.haml +++ b/app/views/admin/email_domain_blocks/_email_domain_block.html.haml @@ -3,3 +3,13 @@ %samp= email_domain_block.domain %td = table_link_to 'trash', t('admin.email_domain_blocks.delete'), admin_email_domain_block_path(email_domain_block), method: :delete + +- email_domain_block.children.each do |child_email_domain_block| + %tr + %td + %samp= child_email_domain_block.domain + %span.muted-hint + = surround '(', ')' do + = t('admin.email_domain_blocks.from_html', domain: content_tag(:samp, email_domain_block.domain)) + %td + = table_link_to 'trash', t('admin.email_domain_blocks.delete'), admin_email_domain_block_path(child_email_domain_block), method: :delete diff --git a/app/views/admin/email_domain_blocks/new.html.haml b/app/views/admin/email_domain_blocks/new.html.haml index f372fa512..4a346f240 100644 --- a/app/views/admin/email_domain_blocks/new.html.haml +++ b/app/views/admin/email_domain_blocks/new.html.haml @@ -5,7 +5,10 @@ = render 'shared/error_messages', object: @email_domain_block .fields-group - = f.input :domain, wrapper: :with_label, label: t('admin.email_domain_blocks.domain') + = f.input :domain, wrapper: :with_block_label, label: t('admin.email_domain_blocks.domain') + + .fields-group + = f.input :with_dns_records, as: :boolean, wrapper: :with_label .actions = f.button :button, t('.create'), type: :submit diff --git a/config/locales/en.yml b/config/locales/en.yml index 05d92b121..13f22d922 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -92,6 +92,7 @@ en: delete: Delete destroyed_msg: Moderation note successfully destroyed! accounts: + add_email_domain_block: Blacklist e-mail domain approve: Approve approve_all: Approve all are_you_sure: Are you sure? @@ -172,6 +173,7 @@ en: staff: Staff user: User search: Search + search_same_email_domain: Other users with the same e-mail domain search_same_ip: Other users with the same IP shared_inbox_url: Shared inbox URL show: @@ -358,6 +360,7 @@ en: destroyed_msg: Successfully deleted e-mail domain from blacklist domain: Domain empty: No e-mail domains currently blacklisted. + from_html: from %{domain} new: create: Add domain title: New e-mail blacklist entry diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index f279a8e4f..fd56a35bf 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -54,6 +54,9 @@ en: whole_word: When the keyword or phrase is alphanumeric only, it will only be applied if it matches the whole word domain_allow: domain: This domain will be able to fetch data from this server and incoming data from it will be processed and stored + email_domain_block: + domain: This can be the domain name that shows up in the e-mail address, the MX record that domain resolves to, or IP of the server that MX record resolves to. Those will be checked upon user sign-up and the sign-up will be rejected. + with_dns_records: An attempt to resolve the given domain's DNS records will be made and the results will also be blacklisted featured_tag: name: 'You might want to use one of these:' form_challenge: @@ -152,6 +155,8 @@ en: username: Username username_or_email: Username or Email whole_word: Whole word + email_domain_block: + with_dns_records: Include MX records and IPs of the domain featured_tag: name: Hashtag interactions: diff --git a/db/migrate/20200312185443_add_parent_id_to_email_domain_blocks.rb b/db/migrate/20200312185443_add_parent_id_to_email_domain_blocks.rb new file mode 100644 index 000000000..03915040c --- /dev/null +++ b/db/migrate/20200312185443_add_parent_id_to_email_domain_blocks.rb @@ -0,0 +1,5 @@ +class AddParentIdToEmailDomainBlocks < ActiveRecord::Migration[5.2] + def change + add_reference :email_domain_blocks, :parent, null: true, default: nil, foreign_key: { on_delete: :cascade, to_table: :email_domain_blocks }, index: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 5d3651e52..7f28f2ec4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_03_12_144258) do +ActiveRecord::Schema.define(version: 2020_03_12_185443) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -336,6 +336,7 @@ ActiveRecord::Schema.define(version: 2020_03_12_144258) do t.string "domain", default: "", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "parent_id" t.index ["domain"], name: "index_email_domain_blocks_on_domain", unique: true end @@ -869,6 +870,7 @@ ActiveRecord::Schema.define(version: 2020_03_12_144258) do add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade add_foreign_key "conversation_mutes", "conversations", on_delete: :cascade add_foreign_key "custom_filters", "accounts", on_delete: :cascade + add_foreign_key "email_domain_blocks", "email_domain_blocks", column: "parent_id", on_delete: :cascade add_foreign_key "favourites", "accounts", name: "fk_5eb6c2b873", on_delete: :cascade add_foreign_key "favourites", "statuses", name: "fk_b0e856845e", on_delete: :cascade add_foreign_key "featured_tags", "accounts", on_delete: :cascade -- cgit From cb12a2cdd3fbe2c07a556610596a2de5446b1f50 Mon Sep 17 00:00:00 2001 From: ThibG Date: Thu, 12 Mar 2020 23:06:43 +0100 Subject: Fix some timeouts when searching URLs by limiting some database queries (#13253) Only look up private toots from database if the request failed because of 401, 403 or 404 errors, as those may indicate a private toot, rather than something that isn't a toot or cannot be processed. --- app/services/fetch_resource_service.rb | 3 +++ app/services/resolve_url_service.rb | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/services/fetch_resource_service.rb b/app/services/fetch_resource_service.rb index abe7766d4..880cdde92 100644 --- a/app/services/fetch_resource_service.rb +++ b/app/services/fetch_resource_service.rb @@ -5,6 +5,8 @@ class FetchResourceService < BaseService ACCEPT_HEADER = 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams", text/html;q=0.1' + attr_reader :response_code + def call(url) return if url.blank? @@ -27,6 +29,7 @@ class FetchResourceService < BaseService end def process_response(response, terminal = false) + @response_code = response.code return nil if response.code != 200 if ['application/activity+json', 'application/ld+json'].include?(response.mime_type) diff --git a/app/services/resolve_url_service.rb b/app/services/resolve_url_service.rb index 1a2b0d60c..78080d878 100644 --- a/app/services/resolve_url_service.rb +++ b/app/services/resolve_url_service.rb @@ -12,7 +12,7 @@ class ResolveURLService < BaseService process_local_url elsif !fetched_resource.nil? process_url - elsif @on_behalf_of.present? + else process_url_from_db end end @@ -30,6 +30,8 @@ class ResolveURLService < BaseService end def process_url_from_db + return unless @on_behalf_of.present? && [401, 403, 404].include?(fetch_resource_service.response_code) + # It may happen that the resource is a private toot, and thus not fetchable, # but we can return the toot if we already know about it. status = Status.find_by(uri: @url) || Status.find_by(url: @url) @@ -40,7 +42,11 @@ class ResolveURLService < BaseService end def fetched_resource - @fetched_resource ||= FetchResourceService.new.call(@url) + @fetched_resource ||= fetch_resource_service.call(@url) + end + + def fetch_resource_service + @_fetch_resource_service ||= FetchResourceService.new end def resource_url -- cgit From b998ec7c72adc3ff72d8929d03f6ed9dcc186c96 Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 17 Mar 2020 20:43:55 +0100 Subject: Fix WebUI crash in single-column mode on prehistoric browsers (#13267) Fixes #13266 --- .../mastodon/components/scrollable_list.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/javascript/mastodon/components/scrollable_list.js b/app/javascript/mastodon/components/scrollable_list.js index 3a490e78e..65ca43911 100644 --- a/app/javascript/mastodon/components/scrollable_list.js +++ b/app/javascript/mastodon/components/scrollable_list.js @@ -82,15 +82,19 @@ export default class ScrollableList extends PureComponent { lastScrollWasSynthetic = false; scrollToTopOnMouseIdle = false; + _getScrollingElement = () => { + if (this.props.bindToDocument) { + return (document.scrollingElement || document.body); + } else { + return this.node; + } + } + setScrollTop = newScrollTop => { if (this.getScrollTop() !== newScrollTop) { this.lastScrollWasSynthetic = true; - if (this.props.bindToDocument) { - document.scrollingElement.scrollTop = newScrollTop; - } else { - this.node.scrollTop = newScrollTop; - } + this._getScrollingElement().scrollTop = newScrollTop; } }; @@ -151,15 +155,15 @@ export default class ScrollableList extends PureComponent { } getScrollTop = () => { - return this.props.bindToDocument ? document.scrollingElement.scrollTop : this.node.scrollTop; + return this._getScrollingElement().scrollTop; } getScrollHeight = () => { - return this.props.bindToDocument ? document.scrollingElement.scrollHeight : this.node.scrollHeight; + return this._getScrollingElement().scrollHeight; } getClientHeight = () => { - return this.props.bindToDocument ? document.scrollingElement.clientHeight : this.node.clientHeight; + return this._getScrollingElement().clientHeight; } updateScrollBottom = (snapshot) => { -- cgit From 61f35c1a8a7c6544fe82b733e40267f4b28a3264 Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 21 Mar 2020 03:08:09 +0100 Subject: Fix reported accounts not being whitelisted when resolving a spamcheck report (#13289) --- app/models/admin/account_action.rb | 12 ------------ app/models/report.rb | 8 ++++++++ spec/controllers/admin/reports_controller_spec.rb | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb index e9da003a3..b30a82369 100644 --- a/app/models/admin/account_action.rb +++ b/app/models/admin/account_action.rb @@ -62,8 +62,6 @@ class Admin::AccountAction def process_action! case type - when 'none' - handle_resolve! when 'disable' handle_disable! when 'silence' @@ -105,16 +103,6 @@ class Admin::AccountAction end end - def handle_resolve! - if with_report? && report.account_id == -99 && target_account.trust_level == Account::TRUST_LEVELS[:untrusted] - # This is an automated report and it is being dismissed, so it's - # a false positive, in which case update the account's trust level - # to prevent further spam checks - - target_account.update(trust_level: Account::TRUST_LEVELS[:trusted]) - end - end - def handle_disable! authorize(target_account.user, :disable?) log_action(:disable, target_account.user) diff --git a/app/models/report.rb b/app/models/report.rb index fb2e040ee..356c23d68 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -59,6 +59,14 @@ class Report < ApplicationRecord end def resolve!(acting_account) + if account_id == -99 && target_account.trust_level == Account::TRUST_LEVELS[:untrusted] + # This is an automated report and it is being dismissed, so it's + # a false positive, in which case update the account's trust level + # to prevent further spam checks + + target_account.update(trust_level: Account::TRUST_LEVELS[:trusted]) + end + RemovalWorker.push_bulk(Status.with_discarded.discarded.where(id: status_ids).pluck(:id)) { |status_id| [status_id, { immediate: true }] } update!(action_taken: true, action_taken_by_account_id: acting_account.id) end diff --git a/spec/controllers/admin/reports_controller_spec.rb b/spec/controllers/admin/reports_controller_spec.rb index b428299ee..49d3e9707 100644 --- a/spec/controllers/admin/reports_controller_spec.rb +++ b/spec/controllers/admin/reports_controller_spec.rb @@ -46,6 +46,26 @@ describe Admin::ReportsController do end end + describe 'POST #resolve' do + it 'resolves the report' do + report = Fabricate(:report) + + put :resolve, params: { id: report } + expect(response).to redirect_to(admin_reports_path) + report.reload + expect(report.action_taken_by_account).to eq user.account + expect(report.action_taken).to eq true + end + + it 'sets trust level when the report is an antispam one' do + report = Fabricate(:report, account: Account.representative) + + put :resolve, params: { id: report } + report.reload + expect(report.target_account.trust_level).to eq Account::TRUST_LEVELS[:trusted] + end + end + describe 'POST #reopen' do it 'reopens the report' do report = Fabricate(:report) -- cgit From 8758221e7344645bc1357578ec1789aa7d46da08 Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Fri, 20 Mar 2020 22:10:42 -0400 Subject: Fix frontend crash when deleting announcements (#13283) This two-line change fixes a crash in the front end that occurred under the following circumstances: * A server had more than one announcement, * A user was displaying the announcements, and * An announcement was deleted (or unpublished, which amounts to the same thing.) As might be expected, the bug was caused by attempting to access a notification using an index value outside the bounds of the existing announcements. Specifically, in two places. First, `_markAnnouncementAsRead` attempts to modify announcements based on the current index. This is what caused the front end crash. Second, when rendering the `Announcements` component, the code paginates the announcements and displays the current one. This did not cause a crash, but caused the front end to confusingly display a blank announcement (in situations that would have caused a crash) with no way for the user to navigate back to previous announcements. This commit fixes both issues by adding a check to ensure that the code never attempts to access an announcement with an index greater than or equal to the number of announcements present. --- .../mastodon/features/getting_started/components/announcements.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/javascript/mastodon/features/getting_started/components/announcements.js b/app/javascript/mastodon/features/getting_started/components/announcements.js index fb4a6bf0d..ec57c41b2 100644 --- a/app/javascript/mastodon/features/getting_started/components/announcements.js +++ b/app/javascript/mastodon/features/getting_started/components/announcements.js @@ -389,7 +389,7 @@ class Announcements extends ImmutablePureComponent { _markAnnouncementAsRead () { const { dismissAnnouncement, announcements } = this.props; const { index } = this.state; - const announcement = announcements.get(index); + const announcement = announcements.get(index) || announcements.get(index - 1); if (!announcement.get('read')) dismissAnnouncement(announcement.get('id')); } @@ -407,7 +407,7 @@ class Announcements extends ImmutablePureComponent { render () { const { announcements, intl } = this.props; - const { index } = this.state; + const index = this.state.index < announcements.size ? this.state.index : announcements.size - 1; if (announcements.isEmpty()) { return null; -- cgit From 8c42e0b53c1e3f34846f15064ada2bec0c8cc907 Mon Sep 17 00:00:00 2001 From: Jeong Arm Date: Sat, 21 Mar 2020 11:14:10 +0900 Subject: Make bookmarks also searchable (#13271) --- app/models/status.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app') diff --git a/app/models/status.rb b/app/models/status.rb index 8e040f0e6..ff653100a 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -142,10 +142,12 @@ class Status < ApplicationRecord ids += mentions.where(account: Account.local).pluck(:account_id) ids += favourites.where(account: Account.local).pluck(:account_id) ids += reblogs.where(account: Account.local).pluck(:account_id) + ids += bookmarks.where(account: Account.local).pluck(:account_id) else ids += preloaded.mentions[id] || [] ids += preloaded.favourites[id] || [] ids += preloaded.reblogs[id] || [] + ids += preloaded.bookmarks[id] || [] end ids.uniq -- cgit From 44292a6952cfa1e87137eaecbd41269b35105a60 Mon Sep 17 00:00:00 2001 From: mayaeh Date: Sat, 21 Mar 2020 11:14:28 +0900 Subject: Add link to bookmarks in web UI dropdown (#13273) --- app/javascript/mastodon/features/compose/components/action_bar.js | 2 ++ app/javascript/mastodon/locales/defaultMessages.json | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'app') diff --git a/app/javascript/mastodon/features/compose/components/action_bar.js b/app/javascript/mastodon/features/compose/components/action_bar.js index dd2632796..07d92bb7e 100644 --- a/app/javascript/mastodon/features/compose/components/action_bar.js +++ b/app/javascript/mastodon/features/compose/components/action_bar.js @@ -16,6 +16,7 @@ const messages = defineMessages({ mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' }, filters: { id: 'navigation_bar.filters', defaultMessage: 'Muted words' }, logout: { id: 'navigation_bar.logout', defaultMessage: 'Logout' }, + bookmarks: { id: 'navigation_bar.bookmarks', defaultMessage: 'Bookmarks' }, }); export default @injectIntl @@ -42,6 +43,7 @@ class ActionBar extends React.PureComponent { menu.push(null); menu.push({ text: intl.formatMessage(messages.follow_requests), to: '/follow_requests' }); menu.push({ text: intl.formatMessage(messages.favourites), to: '/favourites' }); + menu.push({ text: intl.formatMessage(messages.bookmarks), to: '/bookmarks' }); menu.push({ text: intl.formatMessage(messages.lists), to: '/lists' }); menu.push(null); menu.push({ text: intl.formatMessage(messages.mutes), to: '/mutes' }); diff --git a/app/javascript/mastodon/locales/defaultMessages.json b/app/javascript/mastodon/locales/defaultMessages.json index 4b971000c..3142487ea 100644 --- a/app/javascript/mastodon/locales/defaultMessages.json +++ b/app/javascript/mastodon/locales/defaultMessages.json @@ -917,6 +917,10 @@ { "defaultMessage": "Logout", "id": "navigation_bar.logout" + }, + { + "defaultMessage": "Bookmarks", + "id": "navigation_bar.bookmarks" } ], "path": "app/javascript/mastodon/features/compose/components/action_bar.json" -- cgit From 221eda646b09a5d993a999d000af9de6c7f25b50 Mon Sep 17 00:00:00 2001 From: Shlee Date: Sat, 21 Mar 2020 10:14:50 +0800 Subject: Migrate Rails ujs as required for Rails 6 Upgrade. (#13280) * Update yarn.lock * Update package.json * Update public.js * Update admin.js * Update log_out.js * Update common.js --- app/javascript/mastodon/common.js | 2 +- app/javascript/mastodon/utils/log_out.js | 2 +- app/javascript/packs/admin.js | 2 +- app/javascript/packs/public.js | 2 +- package.json | 2 +- yarn.lock | 10 +++++----- 6 files changed, 10 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/javascript/mastodon/common.js b/app/javascript/mastodon/common.js index fba21316a..6818aa5d5 100644 --- a/app/javascript/mastodon/common.js +++ b/app/javascript/mastodon/common.js @@ -1,4 +1,4 @@ -import Rails from 'rails-ujs'; +import Rails from '@rails/ujs'; export function start() { require('font-awesome/css/font-awesome.css'); diff --git a/app/javascript/mastodon/utils/log_out.js b/app/javascript/mastodon/utils/log_out.js index b43417f4b..3a4cc8ecb 100644 --- a/app/javascript/mastodon/utils/log_out.js +++ b/app/javascript/mastodon/utils/log_out.js @@ -1,4 +1,4 @@ -import Rails from 'rails-ujs'; +import Rails from '@rails/ujs'; export const logOut = () => { const form = document.createElement('form'); diff --git a/app/javascript/packs/admin.js b/app/javascript/packs/admin.js index b318cadc6..061287f89 100644 --- a/app/javascript/packs/admin.js +++ b/app/javascript/packs/admin.js @@ -1,4 +1,4 @@ -import { delegate } from 'rails-ujs'; +import { delegate } from '@rails/ujs'; import ready from '../mastodon/ready'; const batchCheckboxClassName = '.batch-checkbox input[type="checkbox"]'; diff --git a/app/javascript/packs/public.js b/app/javascript/packs/public.js index 2fb9cb29d..8ba4f6ee0 100644 --- a/app/javascript/packs/public.js +++ b/app/javascript/packs/public.js @@ -25,7 +25,7 @@ window.addEventListener('message', e => { function main() { const IntlMessageFormat = require('intl-messageformat').default; const { timeAgoString } = require('../mastodon/components/relative_timestamp'); - const { delegate } = require('rails-ujs'); + const { delegate } = require('@rails/ujs'); const emojify = require('../mastodon/features/emoji/emoji').default; const { getLocale } = require('../mastodon/locales'); const { messages } = getLocale(); diff --git a/package.json b/package.json index 09002b6b2..8ad05c64d 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "promise.prototype.finally": "^3.1.2", "prop-types": "^15.5.10", "punycode": "^2.1.0", - "rails-ujs": "^5.2.4", + "@rails/ujs": "^6.0.2", "react": "^16.12.0", "react-dom": "^16.13.0", "react-hotkeys": "^1.1.4", diff --git a/yarn.lock b/yarn.lock index b4c3c5f03..ed0eef8d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1164,6 +1164,11 @@ "@types/yargs" "^15.0.0" chalk "^3.0.0" +"@rails/ujs@^6.0.2": + version "6.0.2" + resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.0.2.tgz#8d32452d51c5e115374a218fb5475803dc17f4c0" + integrity sha512-KSQjJG8yzSWC1IT+UtFQglefABU37hpJ7uAz39K1/iWtoaJaI9ydGIaxxpJBT/PmYv4kS6lCSjXq13DELeJocw== + "@types/babel__core@^7.1.0", "@types/babel__core@^7.1.2": version "7.1.3" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.3.tgz#e441ea7df63cd080dfcd02ab199e6d16a735fc30" @@ -8766,11 +8771,6 @@ railroad-diagrams@^1.0.0: resolved "https://registry.yarnpkg.com/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz#eb7e6267548ddedfb899c1b90e57374559cddb7e" integrity sha1-635iZ1SN3t+4mcG5Dlc3RVnN234= -rails-ujs@^5.2.4: - version "5.2.4" - resolved "https://registry.yarnpkg.com/rails-ujs/-/rails-ujs-5.2.4.tgz#31056ccd62d868f7d044395f31d77a4440550ceb" - integrity sha512-Mzu6bnTBKn4IuJvP7BDJRy4lzvR1zMWVDeTdPwDubXBfxpFEKqwOi5Nb6tfE2SYtTd+bb3PRETf40I94jgKw3w== - randexp@0.4.6: version "0.4.6" resolved "https://registry.yarnpkg.com/randexp/-/randexp-0.4.6.tgz#e986ad5e5e31dae13ddd6f7b3019aa7c87f60ca3" -- cgit From 5a1fb6efc217056d3ea91f156c69684df88a8a37 Mon Sep 17 00:00:00 2001 From: Takeshi Umeda Date: Sun, 22 Mar 2020 10:40:03 +0900 Subject: Fix bookmarks also searchable (#13293) --- app/chewy/statuses_index.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app') diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb index f5735421c..bec9ed88b 100644 --- a/app/chewy/statuses_index.rb +++ b/app/chewy/statuses_index.rb @@ -47,6 +47,11 @@ class StatusesIndex < Chewy::Index data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } end + crutch :bookmarks do |collection| + data = ::Bookmark.where(status_id: collection.map(&:id)).where(account: Account.local).pluck(:status_id, :account_id) + data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } + end + root date_detection: false do field :id, type: 'long' field :account_id, type: 'long' -- cgit From 295dadc9f0d03d0dbb8b75f330162473807e7380 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 8 Mar 2020 23:56:18 +0100 Subject: [Glitch] Change local media attachments to perform heavy processing asynchronously Port front-end part of 9660aa4543deff41c60d131e081137f84e771499 to glitch-soc [API] This makes use of a new media posting API (/api/v2/media), supporting background processing of uploaded files. For Pleroma's purposes, this could be handled the same as /api/v1/media since afaik Pleroma doesn't do any transcoding. Signed-off-by: Thibaut Girka --- app/javascript/flavours/glitch/actions/compose.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 0be746048..966d605d1 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -259,12 +259,31 @@ export function uploadCompose(files) { // Account for disparity in size of original image and resized data total += file.size - f.size; - return api(getState).post('/api/v1/media', data, { + return api(getState).post('/api/v2/media', data, { onUploadProgress: function({ loaded }){ progress[i] = loaded; dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total)); }, - }).then(({ data }) => dispatch(uploadComposeSuccess(data, f))); + }).then(({ status, data }) => { + // If server-side processing of the media attachment has not completed yet, + // poll the server until it is, before showing the media attachment as uploaded + + if (status === 200) { + dispatch(uploadComposeSuccess(data, f)); + } else if (status === 202) { + const poll = () => { + api(getState).get(`/api/v1/media/${data.id}`).then(response => { + if (response.status === 200) { + dispatch(uploadComposeSuccess(data, f)); + } else if (response.status === 206) { + setTimeout(() => poll(), 1000); + } + }).catch(error => dispatch(uploadComposeFail(error))); + }; + + poll(); + } + }); }).catch(error => dispatch(uploadComposeFail(error))); }; }; -- cgit From 912f4a2eba33532a29f3085a0df776a0e6fa1012 Mon Sep 17 00:00:00 2001 From: mayaeh Date: Mon, 9 Mar 2020 17:13:21 +0900 Subject: [Glitch] Change the string "hidden" to "blocked" in WebUI Port 310d729745ad34b1b039f2ec611b9bda5b73f252 to glitch-soc Signed-off-by: Thibaut Girka --- app/javascript/flavours/glitch/components/domain.js | 2 +- app/javascript/flavours/glitch/containers/domain_container.js | 2 +- .../flavours/glitch/features/account/components/header.js | 4 ++-- app/javascript/flavours/glitch/features/domain_blocks/index.js | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/javascript/flavours/glitch/components/domain.js b/app/javascript/flavours/glitch/components/domain.js index 85729ca94..697065d87 100644 --- a/app/javascript/flavours/glitch/components/domain.js +++ b/app/javascript/flavours/glitch/components/domain.js @@ -5,7 +5,7 @@ import { defineMessages, injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; const messages = defineMessages({ - unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' }, + unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unblock domain {domain}' }, }); export default @injectIntl diff --git a/app/javascript/flavours/glitch/containers/domain_container.js b/app/javascript/flavours/glitch/containers/domain_container.js index 52d5c1613..e92e102ab 100644 --- a/app/javascript/flavours/glitch/containers/domain_container.js +++ b/app/javascript/flavours/glitch/containers/domain_container.js @@ -6,7 +6,7 @@ import Domain from '../components/domain'; import { openModal } from '../actions/modal'; const messages = defineMessages({ - blockDomainConfirm: { id: 'confirmations.domain_block.confirm', defaultMessage: 'Hide entire domain' }, + blockDomainConfirm: { id: 'confirmations.domain_block.confirm', defaultMessage: 'Block entire domain' }, }); const makeMapStateToProps = () => { diff --git a/app/javascript/flavours/glitch/features/account/components/header.js b/app/javascript/flavours/glitch/features/account/components/header.js index efcb243ba..fb0f165ff 100644 --- a/app/javascript/flavours/glitch/features/account/components/header.js +++ b/app/javascript/flavours/glitch/features/account/components/header.js @@ -40,7 +40,7 @@ const messages = defineMessages({ favourites: { id: 'navigation_bar.favourites', defaultMessage: 'Favourites' }, lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' }, blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' }, - domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' }, + domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Blocked domains' }, mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' }, endorse: { id: 'account.endorse', defaultMessage: 'Feature on profile' }, unendorse: { id: 'account.unendorse', defaultMessage: 'Don\'t feature on profile' }, @@ -136,7 +136,7 @@ class Header extends ImmutablePureComponent { if (me !== account.get('id') && account.getIn(['relationship', 'muting'])) { info.push(); } else if (me !== account.get('id') && account.getIn(['relationship', 'domain_blocking'])) { - info.push(); + info.push(); } if (me !== account.get('id')) { diff --git a/app/javascript/flavours/glitch/features/domain_blocks/index.js b/app/javascript/flavours/glitch/features/domain_blocks/index.js index c53d32ebb..acce87d5a 100644 --- a/app/javascript/flavours/glitch/features/domain_blocks/index.js +++ b/app/javascript/flavours/glitch/features/domain_blocks/index.js @@ -13,8 +13,8 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; import ScrollableList from 'flavours/glitch/components/scrollable_list'; const messages = defineMessages({ - heading: { id: 'column.domain_blocks', defaultMessage: 'Hidden domains' }, - unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' }, + heading: { id: 'column.domain_blocks', defaultMessage: 'Blocked domains' }, + unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unblock domain {domain}' }, }); const mapStateToProps = state => ({ @@ -54,7 +54,7 @@ class Blocks extends ImmutablePureComponent { ); } - const emptyMessage = ; + const emptyMessage = ; return ( -- cgit From 0ff78befc6a067f4157648f229b4f2242d5a8082 Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 10 Mar 2020 11:59:44 +0100 Subject: [Glitch] Fix regression in “Edit media” modal in web UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Port 90f3a0006243250ced6e7e192f81513d6b731b33 to glitch-soc Signed-off-by: Thibaut Girka --- app/javascript/flavours/glitch/actions/compose.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 966d605d1..f98cb7bf8 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -274,7 +274,7 @@ export function uploadCompose(files) { const poll = () => { api(getState).get(`/api/v1/media/${data.id}`).then(response => { if (response.status === 200) { - dispatch(uploadComposeSuccess(data, f)); + dispatch(uploadComposeSuccess(response.data, f)); } else if (response.status === 206) { setTimeout(() => poll(), 1000); } -- cgit From 9da4bd098cac88c3e44157765adcff01445ba31a Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Fri, 20 Mar 2020 22:10:42 -0400 Subject: [Glitch] Fix frontend crash when deleting announcements Port 8758221e7344645bc1357578ec1789aa7d46da08 to glitch-soc Signed-off-by: Thibaut Girka --- .../glitch/features/getting_started/components/announcements.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/javascript/flavours/glitch/features/getting_started/components/announcements.js b/app/javascript/flavours/glitch/features/getting_started/components/announcements.js index 48e1766e2..5f6e6d84c 100644 --- a/app/javascript/flavours/glitch/features/getting_started/components/announcements.js +++ b/app/javascript/flavours/glitch/features/getting_started/components/announcements.js @@ -389,7 +389,7 @@ class Announcements extends ImmutablePureComponent { _markAnnouncementAsRead () { const { dismissAnnouncement, announcements } = this.props; const { index } = this.state; - const announcement = announcements.get(index); + const announcement = announcements.get(index) || announcements.get(index - 1); if (!announcement.get('read')) dismissAnnouncement(announcement.get('id')); } @@ -407,7 +407,7 @@ class Announcements extends ImmutablePureComponent { render () { const { announcements, intl } = this.props; - const { index } = this.state; + const index = this.state.index < announcements.size ? this.state.index : announcements.size - 1; if (announcements.isEmpty()) { return null; -- cgit