From 58e452beb891da7fcb54d78f6f482f39607a833d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Jan 2021 14:06:15 +0900 Subject: [PATCH 01/12] Bump webpack-assets-manifest from 3.1.1 to 4.0.0 (#15288) Bumps [webpack-assets-manifest](https://github.com/webdeveric/webpack-assets-manifest) from 3.1.1 to 4.0.0. - [Release notes](https://github.com/webdeveric/webpack-assets-manifest/releases) - [Commits](https://github.com/webdeveric/webpack-assets-manifest/compare/v3.1.1...v4.0.0) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 47 +++++++++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 30926b651dbec..24cc953e2314f 100644 --- a/package.json +++ b/package.json @@ -164,7 +164,7 @@ "tiny-queue": "^0.2.1", "uuid": "^8.3.1", "webpack": "^4.44.2", - "webpack-assets-manifest": "^3.1.1", + "webpack-assets-manifest": "^4.0.0", "webpack-bundle-analyzer": "^4.3.0", "webpack-cli": "^3.3.12", "webpack-merge": "^5.7.3", diff --git a/yarn.lock b/yarn.lock index 450363e3046b3..59199e93dbecf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2793,7 +2793,7 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0, chalk@^2.0.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2: +chalk@^2.0.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -2810,7 +2810,7 @@ chalk@^3.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chalk@^4.0.0, chalk@^4.1.0: +chalk@^4.0, chalk@^4.0.0, chalk@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a" integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A== @@ -6821,6 +6821,13 @@ locate-path@^5.0.0: dependencies: p-locate "^4.1.0" +lockfile@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/lockfile/-/lockfile-1.0.4.tgz#07f819d25ae48f87e538e6578b6964a4981a5609" + integrity sha512-cvbTwETRfsFh4nHsL1eGWapU1XFi5Ot9E85sWAwia7Y7EgB7vfqcZhTKZ+l7hCGxSPoushMv5GKhT5PdLv03WA== + dependencies: + signal-exit "^3.0.2" + lodash.capitalize@^4.1.0: version "4.2.1" resolved "https://registry.yarnpkg.com/lodash.capitalize/-/lodash.capitalize-4.2.1.tgz#f826c9b4e2a8511d84e3aca29db05e1a4f3b72a9" @@ -6831,6 +6838,11 @@ lodash.defaults@^4.0.1: resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c" integrity sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw= +lodash.escaperegexp@^4.0: + version "4.1.2" + resolved "https://registry.yarnpkg.com/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz#64762c48618082518ac3df4ccf5d5886dae20347" + integrity sha1-ZHYsSGGAglGKw99Mz11YhtriA0c= + lodash.get@^4.0: version "4.4.2" resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" @@ -7189,14 +7201,14 @@ mixin-deep@^1.2.0: for-in "^1.0.2" is-extendable "^1.0.1" -mkdirp@^0.5, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@^0.5.3, mkdirp@^0.5.5, mkdirp@~0.5.1: +mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@^0.5.3, mkdirp@^0.5.5, mkdirp@~0.5.1: version "0.5.5" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def" integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ== dependencies: minimist "^1.2.5" -mkdirp@^1.0.3, mkdirp@^1.0.4: +mkdirp@^1.0, mkdirp@^1.0.3, mkdirp@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== @@ -9551,7 +9563,7 @@ schema-utils@^2.2.0, schema-utils@^2.6.5: ajv "^6.12.4" ajv-keywords "^3.5.2" -schema-utils@^3.0.0: +schema-utils@^3.0, schema-utils@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.0.0.tgz#67502f6aa2b66a2d4032b4279a2944978a0913ef" integrity sha512-6D82/xSzO094ajanoOSbe4YvXWMfn2A//8Y1+MUqFAJul5Bs+yn36xbK9OtNDcRVSBJ9jjeoXftM6CfztsjOAA== @@ -10367,7 +10379,7 @@ table@^6.0.4: slice-ansi "^4.0.0" string-width "^4.2.0" -tapable@^1.0.0, tapable@^1.1.3: +tapable@^1.0, tapable@^1.0.0, tapable@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2" integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA== @@ -11041,18 +11053,21 @@ webidl-conversions@^6.1.0: resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514" integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w== -webpack-assets-manifest@^3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/webpack-assets-manifest/-/webpack-assets-manifest-3.1.1.tgz#39bbc3bf2ee57fcd8ba07cda51c9ba4a3c6ae1de" - integrity sha512-JV9V2QKc5wEWQptdIjvXDUL1ucbPLH2f27toAY3SNdGZp+xSaStAgpoMcvMZmqtFrBc9a5pTS1058vxyMPOzRQ== +webpack-assets-manifest@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/webpack-assets-manifest/-/webpack-assets-manifest-4.0.0.tgz#6c906f6a77945aa326822e158f22d172ccc59f0f" + integrity sha512-zbozd1Cr6gS5XMWWHfISusocOO2bO05ktpJXWdoYtv12/FSXsNqyVjNwLE9ehBXDsEOwRtqd3kPDdTZKFjjD/w== dependencies: - chalk "^2.0" + chalk "^4.0" + deepmerge "^4.2.2" + lockfile "^1.0.4" + lodash.escaperegexp "^4.0" lodash.get "^4.0" lodash.has "^4.0" - mkdirp "^0.5" - schema-utils "^1.0.0" - tapable "^1.0.0" - webpack-sources "^1.0.0" + mkdirp "^1.0" + schema-utils "^3.0" + tapable "^1.0" + webpack-sources "^1.0" webpack-bundle-analyzer@^4.3.0: version "4.3.0" @@ -11152,7 +11167,7 @@ webpack-merge@^5.7.3: clone-deep "^4.0.1" wildcard "^2.0.0" -webpack-sources@^1.0.0, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-sources@^1.4.1, webpack-sources@^1.4.3: +webpack-sources@^1.0, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-sources@^1.4.1, webpack-sources@^1.4.3: version "1.4.3" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.4.3.tgz#eedd8ec0b928fbf1cbfe994e22d2d890f330a933" integrity sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ== From 32df8950ae8aad25d33c379f1f2fb2ea302053ef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Jan 2021 14:10:49 +0900 Subject: [PATCH 02/12] Bump binding_of_caller from 0.8.0 to 1.0.0 (#15489) Bumps [binding_of_caller](https://github.com/banister/binding_of_caller) from 0.8.0 to 1.0.0. - [Release notes](https://github.com/banister/binding_of_caller/releases) - [Commits](https://github.com/banister/binding_of_caller/compare/v0.8.0...v1.0.0) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 8bab6e2e7071f..75ecbda04b92b 100644 --- a/Gemfile +++ b/Gemfile @@ -133,7 +133,7 @@ group :development do gem 'active_record_query_trace', '~> 1.8' gem 'annotate', '~> 3.1' gem 'better_errors', '~> 2.9' - gem 'binding_of_caller', '~> 0.7' + gem 'binding_of_caller', '~> 1.0' gem 'bullet', '~> 6.1' gem 'letter_opener', '~> 1.7' gem 'letter_opener_web', '~> 1.4' diff --git a/Gemfile.lock b/Gemfile.lock index 25c035ae1be87..24954ebe97b4d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,7 +100,7 @@ GEM erubi (>= 1.0.0) rack (>= 0.9.0) bindata (2.4.8) - binding_of_caller (0.8.0) + binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) blurhash (0.1.4) ffi (~> 1.10.0) @@ -165,7 +165,7 @@ GEM crass (1.0.6) css_parser (1.7.1) addressable - debug_inspector (0.0.3) + debug_inspector (1.0.0) devise (4.7.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -690,7 +690,7 @@ DEPENDENCIES annotate (~> 3.1) aws-sdk-s3 (~> 1.87) better_errors (~> 2.9) - binding_of_caller (~> 0.7) + binding_of_caller (~> 1.0) blurhash (~> 0.1) bootsnap (~> 1.5) brakeman (~> 4.10) From 7cb72956a672a54ba5e308c0dec25ed5c8a25bfe Mon Sep 17 00:00:00 2001 From: abcang Date: Thu, 7 Jan 2021 17:30:12 +0900 Subject: [PATCH 03/12] Set RAILS_ENV in Procfile.dev (#15502) * Set RAILS_ENV in Procfile.dev * Also set on sidekiq --- Procfile.dev | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Procfile.dev b/Procfile.dev index e589bbf6305fc..ba04fb661b344 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,4 +1,4 @@ -web: env PORT=3000 bundle exec puma -C config/puma.rb -sidekiq: env PORT=3000 bundle exec sidekiq +web: env PORT=3000 RAILS_ENV=development bundle exec puma -C config/puma.rb +sidekiq: env PORT=3000 RAILS_ENV=development bundle exec sidekiq stream: env PORT=4000 yarn run start webpack: ./bin/webpack-dev-server --listen-host 0.0.0.0 From 066dbe1e699775f59f02298c369225277aac234b Mon Sep 17 00:00:00 2001 From: Asier Iturralde Sarasola Date: Thu, 7 Jan 2021 09:32:16 +0100 Subject: [PATCH 04/12] Fix typo: you -> your (#15476) --- config/locales/devise.en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index a3f2c5796a02f..cc4140d145199 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -68,7 +68,7 @@ en: deleted: explanation: The following security key has been deleted from your account subject: 'Mastodon: Security key deleted' - title: One of you security keys has been deleted + title: One of your security keys has been deleted webauthn_disabled: explanation: Authentication with security keys has been disabled for your account. Login is now possible using only the token generated by the paired TOTP app. subject: 'Mastodon: Authentication with security keys disabled' From efffdd3778fc960280c7677906ed43dae5a952b0 Mon Sep 17 00:00:00 2001 From: abcang Date: Thu, 7 Jan 2021 17:40:55 +0900 Subject: [PATCH 05/12] Fix rubocop config and warnings (#15503) * disable NewCops * update TargetRubyVersion * Fix Lint/MissingSuper for ActiveModelSerializers::Model * Fix Lint/MissingSuper for feed * Fix Lint/FloatComparison * Do not use instance variables --- .rubocop.yml | 3 ++- app/models/account.rb | 32 +++++++++++------------------- app/models/home_feed.rb | 5 ++--- app/models/list_feed.rb | 3 +-- app/models/poll.rb | 10 ++++++---- app/models/public_feed.rb | 22 ++++++++++---------- app/models/tag_feed.rb | 11 +++++----- app/services/keys/claim_service.rb | 12 ++++++----- app/services/keys/query_service.rb | 18 ++++++++++------- lib/paperclip/color_extractor.rb | 2 +- 10 files changed, 59 insertions(+), 59 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 14728bf0e9417..2af0f59bbe0c7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,8 @@ require: - rubocop-rails AllCops: - TargetRubyVersion: 2.4 + TargetRubyVersion: 2.5 + NewCops: disable Exclude: - 'spec/**/*' - 'db/**/*' diff --git a/app/models/account.rb b/app/models/account.rb index e6cf03fa84e9c..1f723e20648d1 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -385,15 +385,17 @@ class Account < ApplicationRecord end class Field < ActiveModelSerializers::Model - attributes :name, :value, :verified_at, :account, :errors + attributes :name, :value, :verified_at, :account def initialize(account, attributes) - @account = account - @attributes = attributes - @name = attributes['name'].strip[0, string_limit] - @value = attributes['value'].strip[0, string_limit] - @verified_at = attributes['verified_at']&.to_datetime - @errors = {} + @original_field = attributes + string_limit = account.local? ? 255 : 2047 + super( + account: account, + name: attributes['name'].strip[0, string_limit], + value: attributes['value'].strip[0, string_limit], + verified_at: attributes['verified_at']&.to_datetime, + ) end def verified? @@ -415,22 +417,12 @@ class Account < ApplicationRecord end def mark_verified! - @verified_at = Time.now.utc - @attributes['verified_at'] = @verified_at + self.verified_at = Time.now.utc + @original_field['verified_at'] = verified_at end def to_h - { name: @name, value: @value, verified_at: @verified_at } - end - - private - - def string_limit - if account.local? - 255 - else - 2047 - end + { name: name, value: value, verified_at: verified_at } end end diff --git a/app/models/home_feed.rb b/app/models/home_feed.rb index 0fe9dae464164..d6ebb5fa6bc47 100644 --- a/app/models/home_feed.rb +++ b/app/models/home_feed.rb @@ -2,12 +2,11 @@ class HomeFeed < Feed def initialize(account) - @type = :home - @id = account.id @account = account + super(:home, account.id) end def regenerating? - redis.exists?("account:#{@id}:regeneration") + redis.exists?("account:#{@account.id}:regeneration") end end diff --git a/app/models/list_feed.rb b/app/models/list_feed.rb index f371e4ed908c3..47b9281b8c297 100644 --- a/app/models/list_feed.rb +++ b/app/models/list_feed.rb @@ -2,7 +2,6 @@ class ListFeed < Feed def initialize(list) - @type = :list - @id = list.id + super(:list, list.id) end end diff --git a/app/models/poll.rb b/app/models/poll.rb index e1ca5525219e4..d2a17277b2b1e 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -73,10 +73,12 @@ class Poll < ApplicationRecord attributes :id, :title, :votes_count, :poll def initialize(poll, id, title, votes_count) - @poll = poll - @id = id - @title = title - @votes_count = votes_count + super( + poll: poll, + id: id, + title: title, + votes_count: votes_count, + ) end end diff --git a/app/models/public_feed.rb b/app/models/public_feed.rb index c8ce1a1403bb0..5e4c3e1cee98b 100644 --- a/app/models/public_feed.rb +++ b/app/models/public_feed.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class PublicFeed < Feed +class PublicFeed # @param [Account] account # @param [Hash] options # @option [Boolean] :with_replies @@ -33,28 +33,30 @@ class PublicFeed < Feed private + attr_reader :account, :options + def with_reblogs? - @options[:with_reblogs] + options[:with_reblogs] end def with_replies? - @options[:with_replies] + options[:with_replies] end def local_only? - @options[:local] + options[:local] end def remote_only? - @options[:remote] + options[:remote] end def account? - @account.present? + account.present? end def media_only? - @options[:only_media] + options[:only_media] end def public_scope @@ -82,9 +84,9 @@ class PublicFeed < Feed end def account_filters_scope - Status.not_excluded_by_account(@account).tap do |scope| - scope.merge!(Status.not_domain_blocked_by_account(@account)) unless local_only? - scope.merge!(Status.in_chosen_languages(@account)) if @account.chosen_languages.present? + Status.not_excluded_by_account(account).tap do |scope| + scope.merge!(Status.not_domain_blocked_by_account(account)) unless local_only? + scope.merge!(Status.in_chosen_languages(account)) if account.chosen_languages.present? end end end diff --git a/app/models/tag_feed.rb b/app/models/tag_feed.rb index 9a16ffc82b312..b8cd63557e56f 100644 --- a/app/models/tag_feed.rb +++ b/app/models/tag_feed.rb @@ -13,9 +13,8 @@ class TagFeed < PublicFeed # @option [Boolean] :remote # @option [Boolean] :only_media def initialize(tag, account, options = {}) - @tag = tag - @account = account - @options = options + @tag = tag + super(account, options) end # @param [Integer] limit @@ -40,15 +39,15 @@ class TagFeed < PublicFeed private def tagged_with_any_scope - Status.group(:id).tagged_with(tags_for(Array(@tag.name) | Array(@options[:any]))) + Status.group(:id).tagged_with(tags_for(Array(@tag.name) | Array(options[:any]))) end def tagged_with_all_scope - Status.group(:id).tagged_with_all(tags_for(@options[:all])) + Status.group(:id).tagged_with_all(tags_for(options[:all])) end def tagged_with_none_scope - Status.group(:id).tagged_with_none(tags_for(@options[:none])) + Status.group(:id).tagged_with_none(tags_for(options[:none])) end def tags_for(names) diff --git a/app/services/keys/claim_service.rb b/app/services/keys/claim_service.rb index 67211913086bc..69568a0d19b84 100644 --- a/app/services/keys/claim_service.rb +++ b/app/services/keys/claim_service.rb @@ -8,11 +8,13 @@ class Keys::ClaimService < BaseService :key, :signature def initialize(account, device_id, key_attributes = {}) - @account = account - @device_id = device_id - @key_id = key_attributes[:key_id] - @key = key_attributes[:key] - @signature = key_attributes[:signature] + super( + account: account, + device_id: device_id, + key_id: key_attributes[:key_id], + key: key_attributes[:key], + signature: key_attributes[:signature], + ) end end diff --git a/app/services/keys/query_service.rb b/app/services/keys/query_service.rb index 286fbd8347b9d..ac3388bdc0a2b 100644 --- a/app/services/keys/query_service.rb +++ b/app/services/keys/query_service.rb @@ -7,8 +7,10 @@ class Keys::QueryService < BaseService attributes :account, :devices def initialize(account, devices) - @account = account - @devices = devices || [] + super( + account: account, + devices: devices || [], + ) end def find(device_id) @@ -20,11 +22,13 @@ class Keys::QueryService < BaseService attributes :device_id, :name, :identity_key, :fingerprint_key def initialize(attributes = {}) - @device_id = attributes[:device_id] - @name = attributes[:name] - @identity_key = attributes[:identity_key] - @fingerprint_key = attributes[:fingerprint_key] - @claim_url = attributes[:claim_url] + super( + device_id: attributes[:device_id], + name: attributes[:name], + identity_key: attributes[:identity_key], + fingerprint_key: attributes[:fingerprint_key], + ) + @claim_url = attributes[:claim_url] end def valid_claim_url? diff --git a/lib/paperclip/color_extractor.rb b/lib/paperclip/color_extractor.rb index f850dc067c68c..a70a3d21f212d 100644 --- a/lib/paperclip/color_extractor.rb +++ b/lib/paperclip/color_extractor.rb @@ -142,7 +142,7 @@ module Paperclip g = 0.0 b = 0.0 - if s == 0.0 + if s.zero? r = l.to_f g = l.to_f b = l.to_f # achromatic From f47c177eb741a99fef5708175a0a3d4dfcc02639 Mon Sep 17 00:00:00 2001 From: kaiyou Date: Fri, 8 Jan 2021 07:07:08 +0100 Subject: [PATCH 06/12] Support clock drift in Omniauth SAML provider (#15511) The setting is not well documented by the provider, but allows for clock skew between SP and IDP, see: https://github.com/omniauth/omniauth-saml/blob/master/spec/omniauth/strategies/saml_spec.rb Co-authored-by: kaiyou --- config/initializers/omniauth.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index e8d7697a1145a..9e037f421fcc9 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -60,6 +60,7 @@ Devise.setup do |config| saml_options[:attribute_statements][:verified] = [ENV['SAML_ATTRIBUTES_STATEMENTS_VERIFIED']] if ENV['SAML_ATTRIBUTES_STATEMENTS_VERIFIED'] saml_options[:attribute_statements][:verified_email] = [ENV['SAML_ATTRIBUTES_STATEMENTS_VERIFIED_EMAIL']] if ENV['SAML_ATTRIBUTES_STATEMENTS_VERIFIED_EMAIL'] saml_options[:uid_attribute] = ENV['SAML_UID_ATTRIBUTE'] if ENV['SAML_UID_ATTRIBUTE'] + saml_options[:allowed_clock_drift] = ENV['SAML_ALLOWED_CLOCK_DRIFT'] if ENV['SAML_ALLOWED_CLOCK_DRIFT'] config.omniauth :saml, saml_options end end From 1817f96578a31cbc719817433e9f7c592295094a Mon Sep 17 00:00:00 2001 From: kaiyou Date: Fri, 8 Jan 2021 07:13:26 +0100 Subject: [PATCH 07/12] Fix the Dockerfile in case of Kaniko build (#15510) Kaniko does not support looking up binaries from $PATH, so we specify the full path to the bash binary. Co-authored-by: kaiyou --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 95d45bab42700..136b2a35ae6b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:20.04 as build-dep # Use bash for the shell -SHELL ["bash", "-c"] +SHELL ["/usr/bin/bash", "-c"] # Install Node v12 (LTS) ENV NODE_VER="12.20.0" From a1a8aa4a08ee457b62f505cea929a0a319655c83 Mon Sep 17 00:00:00 2001 From: ThibG Date: Fri, 8 Jan 2021 12:26:29 +0100 Subject: [PATCH 08/12] Skip processing Update activities on unknown accounts (#15514) This also skips fetching the actor completely. This will be useful if we end up distributing Update activities linked to account suspensions more widely (they are currently only delivered to the suspended account's followers), as currently, instances not knowing about the suspended account would fetch it to then process the suspension. Co-authored-by: Claire --- app/controllers/activitypub/inboxes_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/activitypub/inboxes_controller.rb b/app/controllers/activitypub/inboxes_controller.rb index d3044f180f819..92dcb5ac77570 100644 --- a/app/controllers/activitypub/inboxes_controller.rb +++ b/app/controllers/activitypub/inboxes_controller.rb @@ -5,7 +5,7 @@ class ActivityPub::InboxesController < ActivityPub::BaseController include JsonLdHelper include AccountOwnedConcern - before_action :skip_unknown_actor_delete + before_action :skip_unknown_actor_activity before_action :require_signature! skip_before_action :authenticate_user! @@ -18,13 +18,13 @@ class ActivityPub::InboxesController < ActivityPub::BaseController private - def skip_unknown_actor_delete - head 202 if unknown_deleted_account? + def skip_unknown_actor_activity + head 202 if unknown_affected_account? end - def unknown_deleted_account? + def unknown_affected_account? json = Oj.load(body, mode: :strict) - json.is_a?(Hash) && json['type'] == 'Delete' && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.where(uri: json['actor']).exists? + json.is_a?(Hash) && %w(Delete Update).include?(json['type']) && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.where(uri: json['actor']).exists? rescue Oj::ParseError false end From 73ddb60c32090c9685f3b74e0bbb4a06b34a7083 Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 9 Jan 2021 03:48:50 +0100 Subject: [PATCH 09/12] Fix OCR lang data failing to load (#15519) Fixes #15472 Co-authored-by: Claire --- .../mastodon/features/ui/components/focal_point_modal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/mastodon/features/ui/components/focal_point_modal.js b/app/javascript/mastodon/features/ui/components/focal_point_modal.js index 578375a7f4929..ffa783e3b0ab1 100644 --- a/app/javascript/mastodon/features/ui/components/focal_point_modal.js +++ b/app/javascript/mastodon/features/ui/components/focal_point_modal.js @@ -227,7 +227,7 @@ class FocalPointModal extends ImmutablePureComponent { const worker = createWorker({ workerPath: tesseractWorkerPath, corePath: tesseractCorePath, - langPath: assetHost, + langPath: `${assetHost}/ocr/lang-data/`, logger: ({ status, progress }) => { if (status === 'recognizing text') { this.setState({ ocrStatus: 'detecting', progress }); From 93951431269403201550e914dee508a522becf8b Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 9 Jan 2021 03:51:32 +0100 Subject: [PATCH 10/12] Fix maintenance script not re-indexing some indexes on textual values (#15515) * Fix maintenance script not re-indexing some indexes on textual values Fixes #15475 * Refresh instance view at the end of the maintenance script run Co-authored-by: Claire --- lib/mastodon/maintenance_cli.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/mastodon/maintenance_cli.rb b/lib/mastodon/maintenance_cli.rb index 822051ceb8798..029d42a05a63c 100644 --- a/lib/mastodon/maintenance_cli.rb +++ b/lib/mastodon/maintenance_cli.rb @@ -160,6 +160,7 @@ module Mastodon deduplicate_tags! deduplicate_webauthn_credentials! + Scenic.database.refresh_materialized_view('instances', concurrently: true, cascade: false) if ActiveRecord::Migrator.current_version >= 2020_12_06_004238 Rails.cache.clear @prompt.say 'Finished!' @@ -188,6 +189,11 @@ module Mastodon else ActiveRecord::Base.connection.add_index :accounts, "lower (username), COALESCE(lower(domain), '')", name: 'index_accounts_on_username_and_domain_lower', unique: true end + + @prompt.say 'Reindexing textual indexes on accounts…' + ActiveRecord::Base.connection.execute('REINDEX INDEX search_index;') + ActiveRecord::Base.connection.execute('REINDEX INDEX index_accounts_on_uri;') + ActiveRecord::Base.connection.execute('REINDEX INDEX index_accounts_on_url;') end def deduplicate_users! From 087ed84367537ac168ed3e00bb7eb4bd582dc3d0 Mon Sep 17 00:00:00 2001 From: luigi <007.lva@gmail.com> Date: Sat, 9 Jan 2021 18:32:01 -0500 Subject: [PATCH 11/12] Optimize map { ... }.compact calls (#15513) * Optimize map { ... }.compact using Enumerable#filter_map, supported since Ruby 2.7 * Add poyfill for Enumerable#filter_map --- .../api/v1/crypto/keys/claims_controller.rb | 2 +- .../api/v1/crypto/keys/queries_controller.rb | 2 +- app/controllers/concerns/cache_concern.rb | 2 +- app/lib/activitypub/activity/flag.rb | 4 +-- app/lib/entity_cache.rb | 2 +- app/lib/spam_check.rb | 4 +-- app/models/account.rb | 4 +-- .../concerns/status_threading_concern.rb | 2 +- app/models/custom_filter.rb | 2 +- app/models/notification.rb | 2 +- app/models/status.rb | 4 +-- .../status_relationships_presenter.rb | 2 +- .../fetch_featured_collection_service.rb | 3 +-- .../activitypub/process_collection_service.rb | 2 +- .../activitypub/process_poll_service.rb | 2 +- .../synchronize_followers_service.rb | 2 +- app/services/fetch_link_card_service.rb | 2 +- app/services/import_service.rb | 4 +-- app/validators/existing_username_validator.rb | 2 +- config/application.rb | 1 + lib/enumerable.rb | 26 +++++++++++++++++++ lib/paperclip/attachment_extensions.rb | 2 +- 22 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 lib/enumerable.rb diff --git a/app/controllers/api/v1/crypto/keys/claims_controller.rb b/app/controllers/api/v1/crypto/keys/claims_controller.rb index 34b21a38096a9..f9d202d67b8ed 100644 --- a/app/controllers/api/v1/crypto/keys/claims_controller.rb +++ b/app/controllers/api/v1/crypto/keys/claims_controller.rb @@ -12,7 +12,7 @@ class Api::V1::Crypto::Keys::ClaimsController < Api::BaseController private def set_claim_results - @claim_results = devices.map { |device_params| ::Keys::ClaimService.new.call(current_account, device_params[:account_id], device_params[:device_id]) }.compact + @claim_results = devices.filter_map { |device_params| ::Keys::ClaimService.new.call(current_account, device_params[:account_id], device_params[:device_id]) } end def resource_params diff --git a/app/controllers/api/v1/crypto/keys/queries_controller.rb b/app/controllers/api/v1/crypto/keys/queries_controller.rb index 0851d797d33b8..e6ce9f9192ac8 100644 --- a/app/controllers/api/v1/crypto/keys/queries_controller.rb +++ b/app/controllers/api/v1/crypto/keys/queries_controller.rb @@ -17,7 +17,7 @@ class Api::V1::Crypto::Keys::QueriesController < Api::BaseController end def set_query_results - @query_results = @accounts.map { |account| ::Keys::QueryService.new.call(account) }.compact + @query_results = @accounts.filter_map { |account| ::Keys::QueryService.new.call(account) } end def account_ids diff --git a/app/controllers/concerns/cache_concern.rb b/app/controllers/concerns/cache_concern.rb index abbdb410a59fb..8d82eda5c19d1 100644 --- a/app/controllers/concerns/cache_concern.rb +++ b/app/controllers/concerns/cache_concern.rb @@ -45,7 +45,7 @@ module CacheConcern end end - raw.map { |item| cached_keys_with_value[item.id] || uncached[item.id] }.compact + raw.filter_map { |item| cached_keys_with_value[item.id] || uncached[item.id] } end def cache_collection_paginated_by_id(raw, klass, limit, options) diff --git a/app/lib/activitypub/activity/flag.rb b/app/lib/activitypub/activity/flag.rb index 1659bc61fe526..8dfc76f0a6b29 100644 --- a/app/lib/activitypub/activity/flag.rb +++ b/app/lib/activitypub/activity/flag.rb @@ -4,8 +4,8 @@ class ActivityPub::Activity::Flag < ActivityPub::Activity def perform return if skip_reports? - target_accounts = object_uris.map { |uri| account_from_uri(uri) }.compact.select(&:local?) - target_statuses_by_account = object_uris.map { |uri| status_from_uri(uri) }.compact.select(&:local?).group_by(&:account_id) + target_accounts = object_uris.filter_map { |uri| account_from_uri(uri) }.select(&:local?) + target_statuses_by_account = object_uris.filter_map { |uri| status_from_uri(uri) }.select(&:local?).group_by(&:account_id) target_accounts.each do |target_account| target_statuses = target_statuses_by_account[target_account.id] diff --git a/app/lib/entity_cache.rb b/app/lib/entity_cache.rb index 89cbf8d2c47bc..e38a3adcdcb59 100644 --- a/app/lib/entity_cache.rb +++ b/app/lib/entity_cache.rb @@ -29,7 +29,7 @@ class EntityCache uncached.each_value { |item| Rails.cache.write(to_key(:emoji, item.shortcode, domain), item, expires_in: MAX_EXPIRATION) } end - shortcodes.map { |shortcode| cached[to_key(:emoji, shortcode, domain)] || uncached[shortcode] }.compact + shortcodes.filter_map { |shortcode| cached[to_key(:emoji, shortcode, domain)] || uncached[shortcode] } end def to_key(type, *ids) diff --git a/app/lib/spam_check.rb b/app/lib/spam_check.rb index 652d036150f7e..68e586d00bd73 100644 --- a/app/lib/spam_check.rb +++ b/app/lib/spam_check.rb @@ -186,9 +186,9 @@ class SpamCheck def matching_status_ids if nilsimsa? - other_digests.select { |record| record.start_with?('nilsimsa') && nilsimsa_compare_value(digest, record.split(':')[1]) >= NILSIMSA_COMPARE_THRESHOLD }.map { |record| record.split(':')[2] }.compact + other_digests.select { |record| record.start_with?('nilsimsa') && nilsimsa_compare_value(digest, record.split(':')[1]) >= NILSIMSA_COMPARE_THRESHOLD }.filter_map { |record| record.split(':')[2] } else - other_digests.select { |record| record.start_with?('md5') && record.split(':')[1] == digest }.map { |record| record.split(':')[2] }.compact + other_digests.select { |record| record.start_with?('md5') && record.split(':')[1] == digest }.filter_map { |record| record.split(':')[2] } end end diff --git a/app/models/account.rb b/app/models/account.rb index 1f723e20648d1..75ebfb2f336d1 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -508,7 +508,7 @@ class Account < ApplicationRecord def from_text(text) return [] if text.blank? - text.scan(MENTION_RE).map { |match| match.first.split('@', 2) }.uniq.map do |(username, domain)| + text.scan(MENTION_RE).map { |match| match.first.split('@', 2) }.uniq.filter_map do |(username, domain)| domain = begin if TagManager.instance.local_domain?(domain) nil @@ -517,7 +517,7 @@ class Account < ApplicationRecord end end EntityCache.instance.mention(username, domain) - end.compact + end end private diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status_threading_concern.rb index a0ead1995af34..5c04108e4ca1c 100644 --- a/app/models/concerns/status_threading_concern.rb +++ b/app/models/concerns/status_threading_concern.rb @@ -83,7 +83,7 @@ module StatusThreadingConcern def find_statuses_from_tree_path(ids, account, promote: false) statuses = Status.with_accounts(ids).to_a account_ids = statuses.map(&:account_id).uniq - domains = statuses.map(&:account_domain).compact.uniq + domains = statuses.filter_map(&:account_domain).uniq relations = relations_map_for_account(account, account_ids, domains) statuses.reject! { |status| StatusFilter.new(status, account, relations).filtered? } diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index 8df8a4fbf3bd1..9d0f3729b3405 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -46,7 +46,7 @@ class CustomFilter < ApplicationRecord private def clean_up_contexts - self.context = Array(context).map(&:strip).map(&:presence).compact + self.context = Array(context).map(&:strip).filter_map(&:presence) end def remove_cache diff --git a/app/models/notification.rb b/app/models/notification.rb index e83123c973184..b6db37d6dcda4 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -92,7 +92,7 @@ class Notification < ApplicationRecord end def reload_stale_associations!(cached_items) - account_ids = (cached_items.map(&:from_account_id) + cached_items.map { |item| item.target_status&.account_id }.compact).uniq + account_ids = (cached_items.map(&:from_account_id) + cached_items.filter_map { |item| item.target_status&.account_id }).uniq return if account_ids.empty? diff --git a/app/models/status.rb b/app/models/status.rb index b426f9d5bcc10..558a37f99a373 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -334,7 +334,7 @@ class Status < ApplicationRecord def from_text(text) return [] if text.blank? - text.scan(FetchLinkCardService::URL_PATTERN).map(&:first).uniq.map do |url| + text.scan(FetchLinkCardService::URL_PATTERN).map(&:first).uniq.filter_map do |url| status = begin if TagManager.instance.local_url?(url) ActivityPub::TagManager.instance.uri_to_resource(url, Status) @@ -343,7 +343,7 @@ class Status < ApplicationRecord end end status&.distributable? ? status : nil - end.compact + end end end diff --git a/app/presenters/status_relationships_presenter.rb b/app/presenters/status_relationships_presenter.rb index 3cc905a75eeb5..f4849d245b60f 100644 --- a/app/presenters/status_relationships_presenter.rb +++ b/app/presenters/status_relationships_presenter.rb @@ -14,7 +14,7 @@ class StatusRelationshipsPresenter else statuses = statuses.compact status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact - conversation_ids = statuses.map(&:conversation_id).compact.uniq + conversation_ids = statuses.filter_map(&:conversation_id).uniq pinnable_status_ids = statuses.map(&:proper).select { |s| s.account_id == current_account_id && %w(public unlisted).include?(s.visibility) }.map(&:id) @reblogs_map = Status.reblogs_map(status_ids, current_account_id).merge(options[:reblogs_map] || {}) diff --git a/app/services/activitypub/fetch_featured_collection_service.rb b/app/services/activitypub/fetch_featured_collection_service.rb index 2c27704661c94..82c861f5b85fa 100644 --- a/app/services/activitypub/fetch_featured_collection_service.rb +++ b/app/services/activitypub/fetch_featured_collection_service.rb @@ -24,8 +24,7 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService def process_items(items) status_ids = items.map { |item| value_or_id(item) } .reject { |uri| ActivityPub::TagManager.instance.local_uri?(uri) } - .map { |uri| ActivityPub::FetchRemoteStatusService.new.call(uri) } - .compact + .filter_map { |uri| ActivityPub::FetchRemoteStatusService.new.call(uri) } .select { |status| status.account_id == @account.id } .map(&:id) diff --git a/app/services/activitypub/process_collection_service.rb b/app/services/activitypub/process_collection_service.rb index f1d175dacc199..170e6709cdd7e 100644 --- a/app/services/activitypub/process_collection_service.rb +++ b/app/services/activitypub/process_collection_service.rb @@ -37,7 +37,7 @@ class ActivityPub::ProcessCollectionService < BaseService end def process_items(items) - items.reverse_each.map { |item| process_item(item) }.compact + items.reverse_each.filter_map { |item| process_item(item) } end def supported_context? diff --git a/app/services/activitypub/process_poll_service.rb b/app/services/activitypub/process_poll_service.rb index 903b6a78adf53..d83e614d883cb 100644 --- a/app/services/activitypub/process_poll_service.rb +++ b/app/services/activitypub/process_poll_service.rb @@ -30,7 +30,7 @@ class ActivityPub::ProcessPollService < BaseService voters_count = @json['votersCount'] - latest_options = items.map { |item| item['name'].presence || item['content'] }.compact + latest_options = items.filter_map { |item| item['name'].presence || item['content'] } # If for some reasons the options were changed, it invalidates all previous # votes, so we need to remove them diff --git a/app/services/activitypub/synchronize_followers_service.rb b/app/services/activitypub/synchronize_followers_service.rb index d83fcf55e665c..93cd60253353c 100644 --- a/app/services/activitypub/synchronize_followers_service.rb +++ b/app/services/activitypub/synchronize_followers_service.rb @@ -14,7 +14,7 @@ class ActivityPub::SynchronizeFollowersService < BaseService # should never happen in practice, since in almost all cases we keep an # Account record, and should we not do that, we should have sent a Delete. # In any case there is not much we can do if that occurs. - @expected_followers = items.map { |uri| ActivityPub::TagManager.instance.uri_to_resource(uri, Account) }.compact + @expected_followers = items.filter_map { |uri| ActivityPub::TagManager.instance.uri_to_resource(uri, Account) } remove_unexpected_local_followers! handle_unexpected_outgoing_follows! diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb index 7efa310547efc..255490d5cdd98 100644 --- a/app/services/fetch_link_card_service.rb +++ b/app/services/fetch_link_card_service.rb @@ -67,7 +67,7 @@ class FetchLinkCardService < BaseService else html = Nokogiri::HTML(@status.text) links = html.css('a') - urls = links.map { |a| Addressable::URI.parse(a['href']) unless skip_link?(a) }.compact.map(&:normalize).compact + urls = links.filter_map { |a| Addressable::URI.parse(a['href']) unless skip_link?(a) }.filter_map(&:normalize) end urls.reject { |uri| bad_url?(uri) }.first diff --git a/app/services/import_service.rb b/app/services/import_service.rb index 0c6ef2238e94a..b115322831b9d 100644 --- a/app/services/import_service.rb +++ b/app/services/import_service.rb @@ -107,12 +107,12 @@ class ImportService < BaseService end end - statuses = items.map do |uri| + statuses = items.filter_map do |uri| status = ActivityPub::TagManager.instance.uri_to_resource(uri, Status) next if status.nil? && ActivityPub::TagManager.instance.local_uri?(uri) status || ActivityPub::FetchRemoteStatusService.new.call(uri) - end.compact + end account_ids = statuses.map(&:account_id) preloaded_relations = relations_map_for_account(@account, account_ids) diff --git a/app/validators/existing_username_validator.rb b/app/validators/existing_username_validator.rb index b31d098273a7e..723302ec9bd06 100644 --- a/app/validators/existing_username_validator.rb +++ b/app/validators/existing_username_validator.rb @@ -5,7 +5,7 @@ class ExistingUsernameValidator < ActiveModel::EachValidator return if value.blank? if options[:multiple] - missing_usernames = value.split(',').map { |username| username.strip.gsub(/\A@/, '') }.map { |username| username unless Account.find_local(username) }.compact + missing_usernames = value.split(',').map { |username| username.strip.gsub(/\A@/, '') }.filter_map { |username| username unless Account.find_local(username) } record.errors.add(attribute, I18n.t('existing_username_validator.not_found_multiple', usernames: missing_usernames.join(', '))) if missing_usernames.any? else record.errors.add(attribute, I18n.t('existing_username_validator.not_found')) unless Account.find_local(value.strip.gsub(/\A@/, '')) diff --git a/config/application.rb b/config/application.rb index af77352212ff9..696dc17e661ce 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,6 +7,7 @@ require 'rails/all' Bundler.require(*Rails.groups) require_relative '../app/lib/exceptions' +require_relative '../lib/enumerable' require_relative '../lib/redis/namespace_extensions' require_relative '../lib/paperclip/url_generator_extensions' require_relative '../lib/paperclip/attachment_extensions' diff --git a/lib/enumerable.rb b/lib/enumerable.rb new file mode 100644 index 0000000000000..66918f65e8b13 --- /dev/null +++ b/lib/enumerable.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Enumerable + # TODO: Remove this once stop to support Ruby 2.6 + if RUBY_VERSION < '2.7.0' + def filter_map + if block_given? + result = [] + each do |element| + res = yield element + result << res if res + end + result + else + Enumerator.new do |yielder| + result = [] + each do |element| + res = yielder.yield element + result << res if res + end + result + end + end + end + end +end diff --git a/lib/paperclip/attachment_extensions.rb b/lib/paperclip/attachment_extensions.rb index 94f7769b65b57..e25a34213b31c 100644 --- a/lib/paperclip/attachment_extensions.rb +++ b/lib/paperclip/attachment_extensions.rb @@ -27,7 +27,7 @@ module Paperclip return true if original_filename == other_filename return false if original_filename.nil? - formats = styles.values.map(&:format).compact + formats = styles.values.filter_map(&:format) return false if formats.empty? From 11d603101a7b3389c679b8c155a3cb06203ca31a Mon Sep 17 00:00:00 2001 From: Levi Bard Date: Sun, 10 Jan 2021 12:47:21 +0100 Subject: [PATCH 12/12] Fix muting users with duration via the REST api (#15516) --- app/controllers/api/v1/accounts_controller.rb | 2 +- .../api/v1/accounts_controller_spec.rb | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 3e66ff212eba9..953874e1abef0 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -42,7 +42,7 @@ class Api::V1::AccountsController < Api::BaseController end def mute - MuteService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications), duration: (params[:duration] || 0)) + MuteService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications), duration: (params[:duration]&.to_i || 0)) render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships end diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb index 1e656503fbccb..d9ee37ffa24b9 100644 --- a/spec/controllers/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts_controller_spec.rb @@ -268,6 +268,34 @@ RSpec.describe Api::V1::AccountsController, type: :controller do it_behaves_like 'forbidden for wrong scope', 'read:accounts' end + describe 'POST #mute with nonzero duration set' do + let(:scopes) { 'write:mutes' } + let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account } + + before do + user.account.follow!(other_account) + post :mute, params: { id: other_account.id, duration: 300 } + end + + it 'returns http success' do + expect(response).to have_http_status(200) + end + + it 'does not remove the following relation between user and target user' do + expect(user.account.following?(other_account)).to be true + end + + it 'creates a muting relation' do + expect(user.account.muting?(other_account)).to be true + end + + it 'mutes notifications' do + expect(user.account.muting_notifications?(other_account)).to be true + end + + it_behaves_like 'forbidden for wrong scope', 'read:accounts' + end + describe 'POST #unmute' do let(:scopes) { 'write:mutes' } let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }