1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00
This commit is contained in:
Nick Schonning 2024-07-31 14:07:09 +00:00 committed by GitHub
commit 88232bc88c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 116 additions and 151 deletions

View file

@ -57,11 +57,6 @@ Style/FormatStringToken:
- 'config/initializers/devise.rb'
- 'lib/paperclip/color_extractor.rb'
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
Style/GuardClause:
Enabled: false
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/HashTransformValues:
Exclude:

View file

@ -15,9 +15,9 @@ class ActivityPub::Activity::Block < ActivityPub::Activity
UnfollowService.new.call(target_account, @account) if target_account.following?(@account)
RejectFollowService.new.call(target_account, @account) if target_account.requested?(@account)
unless delete_arrived_first?(@json['id'])
BlockWorker.perform_async(@account.id, target_account.id)
@account.block!(target_account, uri: @json['id'])
end
return if delete_arrived_first?(@json['id'])
BlockWorker.perform_async(@account.id, target_account.id)
@account.block!(target_account, uri: @json['id'])
end
end

View file

@ -318,11 +318,9 @@ class Request
end
end
if outer_e
raise outer_e
else
raise SocketError, "No address for #{host}"
end
raise outer_e if outer_e
raise SocketError, "No address for #{host}"
end
alias new open

View file

@ -58,13 +58,11 @@ class RequestPool
close
if @fresh || retries.positive?
raise
else
@http_client = http_client
retries += 1
retry
end
raise if @fresh || retries.positive?
@http_client = http_client
retries += 1
retry
rescue
# If this connection raises errors of any kind, it's
# better if it gets reaped as soon as possible

View file

@ -84,22 +84,18 @@ class Webfinger
def body_from_host_meta
host_meta_request.perform do |res|
if res.code == 200
body_from_webfinger(url_from_template(res.body_with_limit), false)
else
raise Webfinger::Error, "Request for #{@uri} returned HTTP #{res.code}"
end
raise Webfinger::Error, "Request for #{@uri} returned HTTP #{res.code}" unless res.code == 200
body_from_webfinger(url_from_template(res.body_with_limit), false)
end
end
def url_from_template(str)
link = Nokogiri::XML(str).at_xpath('//xmlns:Link[@rel="lrdd"]')
if link.present?
link['template'].gsub('{uri}', @uri)
else
raise Webfinger::Error, "Request for #{@uri} returned host-meta without link to Webfinger"
end
raise Webfinger::Error, "Request for #{@uri} returned host-meta without link to Webfinger" if link.blank?
link['template'].gsub('{uri}', @uri)
rescue Nokogiri::XML::XPath::SyntaxError
raise Webfinger::Error, "Invalid XML encountered in host-meta for #{@uri}"
end

View file

@ -54,11 +54,9 @@ class WebfingerResource
end
def username_from_acct
if domain_matches_local?
local_username
else
raise ActiveRecord::RecordNotFound
end
raise ActiveRecord::RecordNotFound unless domain_matches_local?
local_username
end
def split_acct

View file

@ -38,10 +38,10 @@ module Account::Counters
result = updated_account_stat(key, value.to_i)
# Reload account_stat if it was loaded, taking into account newly-created unsaved records
if association(:account_stat).loaded?
account_stat.id = result.first['id'] if account_stat.new_record?
account_stat.reload
end
return unless association(:account_stat).loaded?
account_stat.id = result.first['id'] if account_stat.new_record?
account_stat.reload
end
def account_stat

View file

@ -8,9 +8,9 @@ module User::LdapAuthenticable
ldap = Net::LDAP.new(ldap_options)
filter = format(Devise.ldap_search_filter, uid: Devise.ldap_uid, mail: Devise.ldap_mail, email: Net::LDAP::Filter.escape(params[:email]))
if (user_info = ldap.bind_as(base: Devise.ldap_base, filter: filter, password: params[:password]))
ldap_get_user(user_info.first)
end
return unless (user_info = ldap.bind_as(base: Devise.ldap_base, filter: filter, password: params[:password]))
ldap_get_user(user_info.first)
end
def ldap_get_user(attributes = {})

View file

@ -178,9 +178,9 @@ class Tag < ApplicationRecord
end
def validate_display_name_change
unless HashtagNormalizer.new.normalize(display_name).casecmp(name.mb_chars).zero?
errors.add(:display_name,
I18n.t('tags.does_not_match_previous_name'))
end
return if HashtagNormalizer.new.normalize(display_name).casecmp(name.mb_chars).zero?
errors.add(:display_name,
I18n.t('tags.does_not_match_previous_name'))
end
end

View file

@ -433,16 +433,16 @@ class User < ApplicationRecord
yield
if new_user
# Avoid extremely unlikely race condition when approving and confirming
# the user at the same time
reload unless approved?
return unless new_user
if approved?
prepare_new_user!
else
notify_staff_about_pending_account!
end
# Avoid extremely unlikely race condition when approving and confirming
# the user at the same time
reload unless approved?
if approved?
prepare_new_user!
else
notify_staff_about_pending_account!
end
end

View file

@ -139,10 +139,10 @@ class FanOutOnWriteService < BaseService
redis.publish('timeline:public', anonymous_payload)
redis.publish(@status.local? ? 'timeline:public:local' : 'timeline:public:remote', anonymous_payload)
if @status.with_media?
redis.publish('timeline:public:media', anonymous_payload)
redis.publish(@status.local? ? 'timeline:public:local:media' : 'timeline:public:remote:media', anonymous_payload)
end
return unless @status.with_media?
redis.publish('timeline:public:media', anonymous_payload)
redis.publish(@status.local? ? 'timeline:public:local:media' : 'timeline:public:remote:media', anonymous_payload)
end
def deliver_to_conversation!

View file

@ -98,20 +98,18 @@ class PostStatusService < BaseService
def schedule_status!
status_for_validation = @account.statuses.build(status_attributes)
if status_for_validation.valid?
# Marking the status as destroyed is necessary to prevent the status from being
# persisted when the associated media attachments get updated when creating the
# scheduled status.
status_for_validation.destroy
raise ActiveRecord::RecordInvalid unless status_for_validation.valid?
# The following transaction block is needed to wrap the UPDATEs to
# the media attachments when the scheduled status is created
# Marking the status as destroyed is necessary to prevent the status from being
# persisted when the associated media attachments get updated when creating the
# scheduled status.
status_for_validation.destroy
ApplicationRecord.transaction do
@status = @account.scheduled_statuses.create!(scheduled_status_attributes)
end
else
raise ActiveRecord::RecordInvalid
# The following transaction block is needed to wrap the UPDATEs to
# the media attachments when the scheduled status is created
ApplicationRecord.transaction do
@status = @account.scheduled_statuses.create!(scheduled_status_attributes)
end
end

View file

@ -31,10 +31,10 @@ class ProcessHashtagsService < BaseService
removed_tags = @previous_tags - @current_tags
unless removed_tags.empty?
@account.featured_tags.where(tag_id: removed_tags.map(&:id)).find_each do |featured_tag|
featured_tag.decrement(@status.id)
end
return if removed_tags.empty?
@account.featured_tags.where(tag_id: removed_tags.map(&:id)).find_each do |featured_tag|
featured_tag.decrement(@status.id)
end
end
end

View file

@ -123,11 +123,11 @@ class MoveWorker
end
def add_account_note_if_needed!(account, id)
unless AccountNote.exists?(account: account, target_account: @target_account)
text = I18n.with_locale(account.user&.locale.presence || I18n.default_locale) do
I18n.t(id, acct: @source_account.acct)
end
AccountNote.create!(account: account, target_account: @target_account, comment: text)
return if AccountNote.exists?(account: account, target_account: @target_account)
text = I18n.with_locale(account.user&.locale.presence || I18n.default_locale) do
I18n.t(id, acct: @source_account.acct)
end
AccountNote.create!(account: account, target_account: @target_account, comment: text)
end
end

View file

@ -20,10 +20,7 @@ class RedownloadAvatarWorker
rescue Mastodon::UnexpectedResponseError => e
response = e.response
if response_error_unsalvageable?(response)
# Give up
else
raise e
end
raise e unless response_error_unsalvageable?(response)
# Give up
end
end

View file

@ -20,10 +20,7 @@ class RedownloadHeaderWorker
rescue Mastodon::UnexpectedResponseError => e
response = e.response
if response_error_unsalvageable?(response)
# Give up
else
raise e
end
raise e unless response_error_unsalvageable?(response)
# Give up
end
end

View file

@ -20,10 +20,7 @@ class RedownloadMediaWorker
rescue Mastodon::UnexpectedResponseError => e
response = e.response
if response_error_unsalvageable?(response)
# Give up
else
raise e
end
raise e unless response_error_unsalvageable?(response)
# Give up
end
end

View file

@ -15,10 +15,7 @@ class RemoteAccountRefreshWorker
rescue Mastodon::UnexpectedResponseError => e
response = e.response
if response_error_unsalvageable?(response)
# Give up
else
raise e
end
raise e unless response_error_unsalvageable?(response)
# Give up
end
end

View file

@ -13,11 +13,9 @@ module Devise
def authenticate!
resource = mapping.to.authenticate_with_ldap(params[scope])
if resource && !resource.otp_required_for_login?
success!(resource)
else
fail(:invalid) # rubocop:disable Style/SignalException -- method is from Warden::Strategies::Base
end
fail(:invalid) unless resource && !resource.otp_required_for_login? # rubocop:disable Style/SignalException -- method is from Warden::Strategies::Base
success!(resource)
end
protected

View file

@ -12,11 +12,9 @@ module Devise
def authenticate!
resource = mapping.to.authenticate_with_pam(params[scope])
if resource && !resource.otp_required_for_login?
success!(resource)
else
fail(:invalid) # rubocop:disable Style/SignalException -- method is from Warden::Strategies::Base
end
fail(:invalid) unless resource && !resource.otp_required_for_login? # rubocop:disable Style/SignalException -- method is from Warden::Strategies::Base
success!(resource)
end
protected

View file

@ -320,10 +320,10 @@ module Mastodon::CLI
say("Visited #{processed} accounts, removed #{culled}#{dry_run_mode_suffix}", :green)
unless skip_domains.empty?
say('The following domains were not available during the check:', :yellow)
skip_domains.each { |domain| say(" #{domain}") }
end
return if skip_domains.empty?
say('The following domains were not available during the check:', :yellow)
skip_domains.each { |domain| say(" #{domain}") }
end
option :all, type: :boolean

View file

@ -146,18 +146,18 @@ module Mastodon::CLI
end
end
if db_table_exists?(:severed_relationships)
SeveredRelationship.where(local_account_id: other_account.id).reorder(nil).find_each do |record|
record.update_attribute(:local_account_id, id)
rescue ActiveRecord::RecordNotUnique
next
end
return unless db_table_exists?(:severed_relationships)
SeveredRelationship.where(remote_account_id: other_account.id).reorder(nil).find_each do |record|
record.update_attribute(:remote_account_id, id)
rescue ActiveRecord::RecordNotUnique
next
end
SeveredRelationship.where(local_account_id: other_account.id).reorder(nil).find_each do |record|
record.update_attribute(:local_account_id, id)
rescue ActiveRecord::RecordNotUnique
next
end
SeveredRelationship.where(remote_account_id: other_account.id).reorder(nil).find_each do |record|
record.update_attribute(:remote_account_id, id)
rescue ActiveRecord::RecordNotUnique
next
end
end
end
@ -331,14 +331,14 @@ module Mastodon::CLI
end
def deduplicate_users_process_remember_token
if migrator_version < 2022_01_18_183010
duplicate_record_ids_without_nulls(:users, 'remember_token').each do |row|
users = User.where(id: row['ids'].split(',')).order(updated_at: :desc).to_a.drop(1)
say "Unsetting remember token for those accounts: #{users.map { |user| user.account.acct }.join(', ')}", :yellow
return unless migrator_version < 2022_01_18_183010
users.each do |user|
user.update!(remember_token: nil)
end
duplicate_record_ids_without_nulls(:users, 'remember_token').each do |row|
users = User.where(id: row['ids'].split(',')).order(updated_at: :desc).to_a.drop(1)
say "Unsetting remember token for those accounts: #{users.map { |user| user.account.acct }.join(', ')}", :yellow
users.each do |user|
user.update!(remember_token: nil)
end
end
end

View file

@ -58,23 +58,23 @@ module Mastodon::CLI
say("Visited #{processed} accounts and removed profile media totaling #{number_to_human_size(aggregate)}#{dry_run_mode_suffix}", :green, true)
end
unless options[:prune_profiles] || options[:remove_headers]
processed, aggregate = parallelize_with_progress(MediaAttachment.cached.remote.where(created_at: ..time_ago)) do |media_attachment|
next if media_attachment.file.blank?
return if options[:prune_profiles] || options[:remove_headers]
size = (media_attachment.file_file_size || 0) + (media_attachment.thumbnail_file_size || 0)
processed, aggregate = parallelize_with_progress(MediaAttachment.cached.remote.where(created_at: ..time_ago)) do |media_attachment|
next if media_attachment.file.blank?
unless dry_run?
media_attachment.file.destroy
media_attachment.thumbnail.destroy
media_attachment.save
end
size = (media_attachment.file_file_size || 0) + (media_attachment.thumbnail_file_size || 0)
size
unless dry_run?
media_attachment.file.destroy
media_attachment.thumbnail.destroy
media_attachment.save
end
say("Removed #{processed} media attachments (approx. #{number_to_human_size(aggregate)})#{dry_run_mode_suffix}", :green, true)
size
end
say("Removed #{processed} media attachments (approx. #{number_to_human_size(aggregate)})#{dry_run_mode_suffix}", :green, true)
end
option :start_after

View file

@ -56,13 +56,11 @@ namespace :repo do
loop do
response = HTTP.headers('Authorization' => "token #{ENV['GITHUB_API_TOKEN']}").get("https://api.github.com/repos/#{REPOSITORY_NAME}/pulls/#{pull_request_number}")
if response.code == 403
sleep_for = (response.headers['X-RateLimit-Reset'].to_i - Time.now.to_i).abs
puts "Sleeping for #{sleep_for} seconds to get over rate limit"
sleep sleep_for
else
break
end
break unless response.code == 403
sleep_for = (response.headers['X-RateLimit-Reset'].to_i - Time.now.to_i).abs
puts "Sleeping for #{sleep_for} seconds to get over rate limit"
sleep sleep_for
end
pull_request = Oj.load(response.to_s)