1
0
Fork 0
forked from fedi/mastodon

Autofix Rubocop remaining Layout rules (#23679)

This commit is contained in:
Nick Schonning 2023-02-20 00:58:28 -05:00 committed by GitHub
parent d2dcb6c45a
commit 717683d1c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
117 changed files with 265 additions and 261 deletions

View file

@ -14,154 +14,6 @@ Bundler/OrderedGems:
Exclude:
- 'Gemfile'
# Offense count: 81
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'app/controllers/api/v1/tags_controller.rb'
- 'app/controllers/application_controller.rb'
- 'app/controllers/concerns/session_tracking_concern.rb'
- 'app/controllers/concerns/signature_verification.rb'
- 'app/helpers/application_helper.rb'
- 'app/lib/activitypub/activity.rb'
- 'app/lib/activitypub/tag_manager.rb'
- 'app/lib/request.rb'
- 'app/lib/settings/scoped_settings.rb'
- 'app/lib/status_filter.rb'
- 'app/lib/tag_manager.rb'
- 'app/lib/webfinger.rb'
- 'app/models/account.rb'
- 'app/models/account_conversation.rb'
- 'app/models/admin/import.rb'
- 'app/models/custom_filter.rb'
- 'app/models/favourite.rb'
- 'app/models/form/admin_settings.rb'
- 'app/models/poll.rb'
- 'app/models/session_activation.rb'
- 'app/models/setting.rb'
- 'app/models/status_edit.rb'
- 'app/models/user.rb'
- 'app/models/user_role.rb'
- 'app/services/activitypub/fetch_remote_actor_service.rb'
- 'app/services/activitypub/fetch_remote_status_service.rb'
- 'app/services/activitypub/fetch_replies_service.rb'
- 'app/services/activitypub/process_account_service.rb'
- 'app/services/favourite_service.rb'
- 'app/services/notify_service.rb'
- 'app/services/post_status_service.rb'
- 'app/services/vote_service.rb'
- 'app/validators/follow_limit_validator.rb'
- 'app/validators/unreserved_username_validator.rb'
- 'app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb'
- 'db/migrate/20190314181829_migrate_open_registrations_setting.rb'
- 'db/migrate/20190529143559_preserve_old_layout_for_existing_users.rb'
- 'db/migrate/20210421121431_add_case_insensitive_btree_index_to_tags.rb'
- 'db/post_migrate/20221101190723_backfill_admin_action_logs.rb'
- 'db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb'
- 'lib/mastodon/domains_cli.rb'
# Offense count: 71
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterMagicComment:
Exclude:
- 'Capfile'
- 'app/helpers/languages_helper.rb'
- 'app/models/account.rb'
- 'app/models/account_conversation.rb'
- 'app/models/account_domain_block.rb'
- 'app/models/account_moderation_note.rb'
- 'app/models/account_note.rb'
- 'app/models/account_pin.rb'
- 'app/models/account_stat.rb'
- 'app/models/account_summary.rb'
- 'app/models/account_warning.rb'
- 'app/models/backup.rb'
- 'app/models/block.rb'
- 'app/models/bookmark.rb'
- 'app/models/canonical_email_block.rb'
- 'app/models/conversation.rb'
- 'app/models/conversation_mute.rb'
- 'app/models/custom_emoji.rb'
- 'app/models/custom_filter.rb'
- 'app/models/custom_filter_keyword.rb'
- 'app/models/custom_filter_status.rb'
- 'app/models/device.rb'
- 'app/models/domain_block.rb'
- 'app/models/email_domain_block.rb'
- 'app/models/encrypted_message.rb'
- 'app/models/favourite.rb'
- 'app/models/featured_tag.rb'
- 'app/models/follow.rb'
- 'app/models/follow_recommendation.rb'
- 'app/models/follow_recommendation_suppression.rb'
- 'app/models/follow_request.rb'
- 'app/models/identity.rb'
- 'app/models/import.rb'
- 'app/models/instance.rb'
- 'app/models/invite.rb'
- 'app/models/ip_block.rb'
- 'app/models/list.rb'
- 'app/models/list_account.rb'
- 'app/models/login_activity.rb'
- 'app/models/media_attachment.rb'
- 'app/models/mention.rb'
- 'app/models/mute.rb'
- 'app/models/notification.rb'
- 'app/models/one_time_key.rb'
- 'app/models/poll.rb'
- 'app/models/poll_vote.rb'
- 'app/models/preview_card.rb'
- 'app/models/preview_card_provider.rb'
- 'app/models/relay.rb'
- 'app/models/report.rb'
- 'app/models/report_note.rb'
- 'app/models/session_activation.rb'
- 'app/models/setting.rb'
- 'app/models/site_upload.rb'
- 'app/models/status.rb'
- 'app/models/status_edit.rb'
- 'app/models/status_pin.rb'
- 'app/models/status_stat.rb'
- 'app/models/tag.rb'
- 'app/models/unavailable_domain.rb'
- 'app/models/user.rb'
- 'app/models/user_ip.rb'
- 'app/models/web/push_subscription.rb'
- 'app/models/web/setting.rb'
- 'app/models/webauthn_credential.rb'
- 'config.ru'
- 'db/migrate/20220613110834_add_action_to_custom_filters.rb'
- 'db/post_migrate/20220613110802_remove_whole_word_from_custom_filters.rb'
- 'db/post_migrate/20220613110903_remove_irreversible_from_custom_filters.rb'
- 'spec/controllers/api/v1/accounts/statuses_controller_spec.rb'
- 'spec/models/tag_spec.rb'
# Offense count: 113
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table
# SupportedColonStyles: key, separator, table
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Layout/HashAlignment:
Exclude:
- 'app/lib/activitypub/linked_data_signature.rb'
- 'app/lib/ostatus/tag_manager.rb'
- 'app/models/account/field.rb'
- 'app/models/account_warning.rb'
- 'app/models/media_attachment.rb'
- 'app/models/notification.rb'
- 'app/models/poll.rb'
- 'app/presenters/account_relationships_presenter.rb'
- 'app/services/keys/claim_service.rb'
- 'app/services/keys/query_service.rb'
- 'app/workers/web/push_notification_worker.rb'
- 'db/post_migrate/20200917193528_migrate_notifications_type.rb'
- 'lib/sanitize_ext/sanitize_config.rb'
- 'lib/tasks/auto_annotate_models.rake'
- 'lib/tasks/mastodon.rake'
- 'spec/models/admin/account_action_spec.rb'
- 'spec/models/concerns/account_interactions_spec.rb'
# Offense count: 581
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/scm/git'

View file

@ -25,6 +25,7 @@ class Api::V1::TagsController < Api::BaseController
def set_or_create_tag
return not_found unless Tag::HASHTAG_NAME_RE.match?(params[:id])
@tag = Tag.find_normalized(params[:id]) || Tag.new(name: Tag.normalize(params[:id]), display_name: params[:id])
end
end

View file

@ -128,6 +128,7 @@ class ApplicationController < ActionController::Base
def current_theme
return Setting.theme unless Themes.instance.names.include? current_user&.setting_theme
current_user.setting_theme
end

View file

@ -13,6 +13,7 @@ module SessionTrackingConcern
def set_session_activity
return unless session_needs_update?
current_session.touch
end

View file

@ -165,6 +165,7 @@ module SignatureVerification
end
raise SignatureVerificationError, "Invalid Digest value. The provided Digest value is not a SHA-256 digest. Given digest: #{sha256[1]}" if digest_size != 32
raise SignatureVerificationError, "Invalid Digest value. Computed SHA-256 digest: #{body_digest}; given: #{sha256[1]}"
end

View file

@ -105,6 +105,7 @@ module ApplicationHelper
def can?(action, record)
return false if record.nil?
policy(record).public_send("#{action}?")
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# rubocop:disable Metrics/ModuleLength, Style/WordArray
module LanguagesHelper

View file

@ -153,6 +153,7 @@ class ActivityPub::Activity
def fetch_remote_original_status
if object_uri.start_with?('http')
return if ActivityPub::TagManager.instance.local_uri?(object_uri)
ActivityPub::FetchRemoteStatusService.new.call(object_uri, id: true, on_behalf_of: @account.followers.local.first, request_id: @options[:request_id])
elsif @object['url'].present?
::FetchRemoteStatusService.new.call(@object['url'], request_id: @options[:request_id])

View file

@ -32,7 +32,7 @@ class ActivityPub::LinkedDataSignature
def sign!(creator, sign_with: nil)
options = {
'type' => 'RsaSignature2017',
'type' => 'RsaSignature2017',
'creator' => ActivityPub::TagManager.instance.key_uri_for(creator),
'created' => Time.now.utc.iso8601,
}

View file

@ -26,6 +26,7 @@ class ActivityPub::TagManager
target.instance_actor? ? about_more_url(instance_actor: true) : short_account_url(target)
when :note, :comment, :activity
return activity_account_status_url(target.account, target) if target.reblog?
short_account_status_url(target.account, target)
end
end
@ -38,6 +39,7 @@ class ActivityPub::TagManager
target.instance_actor? ? instance_actor_url : account_url(target)
when :note, :comment, :activity
return activity_account_status_url(target.account, target) if target.reblog?
account_status_url(target.account, target)
when :emoji
emoji_url(target)

View file

@ -5,27 +5,27 @@ class OStatus::TagManager
include RoutingHelper
VERBS = {
post: 'http://activitystrea.ms/schema/1.0/post',
share: 'http://activitystrea.ms/schema/1.0/share',
favorite: 'http://activitystrea.ms/schema/1.0/favorite',
unfavorite: 'http://activitystrea.ms/schema/1.0/unfavorite',
delete: 'http://activitystrea.ms/schema/1.0/delete',
follow: 'http://activitystrea.ms/schema/1.0/follow',
post: 'http://activitystrea.ms/schema/1.0/post',
share: 'http://activitystrea.ms/schema/1.0/share',
favorite: 'http://activitystrea.ms/schema/1.0/favorite',
unfavorite: 'http://activitystrea.ms/schema/1.0/unfavorite',
delete: 'http://activitystrea.ms/schema/1.0/delete',
follow: 'http://activitystrea.ms/schema/1.0/follow',
request_friend: 'http://activitystrea.ms/schema/1.0/request-friend',
authorize: 'http://activitystrea.ms/schema/1.0/authorize',
reject: 'http://activitystrea.ms/schema/1.0/reject',
unfollow: 'http://ostatus.org/schema/1.0/unfollow',
block: 'http://mastodon.social/schema/1.0/block',
unblock: 'http://mastodon.social/schema/1.0/unblock',
authorize: 'http://activitystrea.ms/schema/1.0/authorize',
reject: 'http://activitystrea.ms/schema/1.0/reject',
unfollow: 'http://ostatus.org/schema/1.0/unfollow',
block: 'http://mastodon.social/schema/1.0/block',
unblock: 'http://mastodon.social/schema/1.0/unblock',
}.freeze
TYPES = {
activity: 'http://activitystrea.ms/schema/1.0/activity',
note: 'http://activitystrea.ms/schema/1.0/note',
comment: 'http://activitystrea.ms/schema/1.0/comment',
person: 'http://activitystrea.ms/schema/1.0/person',
activity: 'http://activitystrea.ms/schema/1.0/activity',
note: 'http://activitystrea.ms/schema/1.0/note',
comment: 'http://activitystrea.ms/schema/1.0/comment',
person: 'http://activitystrea.ms/schema/1.0/person',
collection: 'http://activitystrea.ms/schema/1.0/collection',
group: 'http://activitystrea.ms/schema/1.0/group',
group: 'http://activitystrea.ms/schema/1.0/group',
}.freeze
COLLECTIONS = {

View file

@ -182,6 +182,7 @@ class Request
contents = truncated_body(limit)
raise Mastodon::LengthValidationError if contents.bytesize > limit
contents
end
end

View file

@ -34,6 +34,7 @@ module Settings
Setting.default_settings.each do |key, default_value|
next if records.key?(key) || default_value.is_a?(Hash)
records[key] = Setting.new(var: key, value: default_value)
end
@ -54,6 +55,7 @@ module Settings
if db_val
default_value = ScopedSettings.default_settings[key]
return default_value.with_indifferent_access.merge!(db_val.value) if default_value.is_a?(Hash)
db_val.value
else
ScopedSettings.default_settings[key]

View file

@ -11,6 +11,7 @@ class StatusFilter
def filtered?
return false if !account.nil? && account.id == status.account_id
blocked_by_policy? || (account_present? && filtered_status?) || silenced_account?
end

View file

@ -25,6 +25,7 @@ class TagManager
def local_url?(url)
uri = Addressable::URI.parse(url).normalize
return false unless uri.host
domain = uri.host + (uri.port ? ":#{uri.port}" : '')
TagManager.instance.web_domain?(domain)

View file

@ -57,6 +57,7 @@ class Webfinger
if res.code == 200
body = res.body_with_limit
raise Webfinger::Error, "Request for #{@uri} returned empty response" if body.empty?
body
elsif res.code == 404 && use_fallback
body_from_host_meta

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: accounts
@ -539,6 +540,7 @@ class Account < ApplicationRecord
def ensure_keys!
return unless local? && private_key.blank? && public_key.blank?
generate_keys
save!
end

View file

@ -14,8 +14,8 @@ class Account::Field < ActiveModelSerializers::Model
@account = account
super(
name: sanitize(attributes['name']),
value: sanitize(attributes['value']),
name: sanitize(attributes['name']),
value: sanitize(attributes['value']),
verified_at: attributes['verified_at']&.to_datetime,
)
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: account_conversations
@ -107,6 +108,7 @@ class AccountConversation < ApplicationRecord
def push_to_streaming_api
return if destroyed? || !subscribed_to_timeline?
PushConversationWorker.perform_async(id)
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: account_domain_blocks

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: account_moderation_notes

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: account_notes

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: account_pins

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: account_stats

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: account_summaries

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: account_warnings
@ -17,13 +18,13 @@
class AccountWarning < ApplicationRecord
enum action: {
none: 0,
disable: 1_000,
none: 0,
disable: 1_000,
mark_statuses_as_sensitive: 1_250,
delete_statuses: 1_500,
sensitive: 2_000,
silence: 3_000,
suspend: 4_000,
delete_statuses: 1_500,
sensitive: 2_000,
silence: 3_000,
suspend: 4_000,
}, _suffix: :action
before_validation :before_validate

View file

@ -56,6 +56,7 @@ class Admin::Import
def validate_data
return if data.nil?
errors.add(:data, I18n.t('imports.errors.over_rows_processing_limit', count: ROWS_PROCESSING_LIMIT)) if csv_row_count > ROWS_PROCESSING_LIMIT
rescue CSV::MalformedCSVError => e
errors.add(:data, I18n.t('imports.errors.invalid_csv_file', error: e.message))

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: backups

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: blocks

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: bookmarks

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: canonical_email_blocks

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: conversations

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: conversation_mutes

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: custom_emojis

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: custom_filters
@ -101,6 +102,7 @@ class CustomFilter < ApplicationRecord
status_matches = [status.id, status.reblog_of_id].compact & rules[:status_ids] if rules[:status_ids].present?
next if keyword_matches.blank? && status_matches.blank?
FilterResultPresenter.new(filter: filter, keyword_matches: keyword_matches, status_matches: status_matches)
end
end
@ -111,6 +113,7 @@ class CustomFilter < ApplicationRecord
def invalidate_cache!
return unless @should_invalidate_cache
@should_invalidate_cache = false
Rails.cache.delete("filters:v3:#{account_id}")

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: custom_filter_keywords

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: custom_filter_statuses

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: devices

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: domain_blocks

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: email_domain_blocks

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: encrypted_messages

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: favourites
@ -38,6 +39,7 @@ class Favourite < ApplicationRecord
def decrement_cache_counters
return if association(:status).loaded? && status.marked_for_destruction?
status&.decrement_count!(:favourites_count)
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: featured_tags

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: follows

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: follow_recommendations

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: follow_recommendation_suppressions

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: follow_requests

View file

@ -128,6 +128,7 @@ class Form::AdminSettings
def validate_site_uploads
UPLOAD_KEYS.each do |key|
next unless instance_variable_defined?("@#{key}")
upload = instance_variable_get("@#{key}")
next if upload.valid?

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: identities

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: imports

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: instances

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: invites

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: ip_blocks

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: lists

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: list_accounts

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: login_activities

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: media_attachments
@ -372,7 +373,7 @@ class MediaAttachment < ApplicationRecord
return {} if width.nil?
{
width: width,
width: width,
height: height,
size: "#{width}x#{height}",
aspect: width.to_f / height,

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: mentions

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: mutes

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: notifications
@ -19,12 +20,12 @@ class Notification < ApplicationRecord
include Paginable
LEGACY_TYPE_CLASS_MAP = {
'Mention' => :mention,
'Status' => :reblog,
'Follow' => :follow,
'Mention' => :mention,
'Status' => :reblog,
'Follow' => :follow,
'FollowRequest' => :follow_request,
'Favourite' => :favourite,
'Poll' => :poll,
'Favourite' => :favourite,
'Poll' => :poll,
}.freeze
TYPES = %i(

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: one_time_keys

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: polls
@ -74,9 +75,9 @@ class Poll < ApplicationRecord
def initialize(poll, id, title, votes_count)
super(
poll: poll,
id: id,
title: title,
poll: poll,
id: id,
title: title,
votes_count: votes_count,
)
end
@ -105,6 +106,7 @@ class Poll < ApplicationRecord
def reset_parent_cache
return if status_id.nil?
Rails.cache.delete("statuses/#{status_id}")
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: poll_votes

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: preview_cards

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: preview_card_providers

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: relays

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: reports

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: report_notes

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: session_activations
@ -51,6 +52,7 @@ class SessionActivation < ApplicationRecord
def deactivate(id)
return unless id
where(session_id: id).destroy_all
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: settings
@ -30,6 +31,7 @@ class Setting < RailsSettings::Base
default_value = default_settings[key]
return default_value.with_indifferent_access.merge!(db_val.value) if default_value.is_a?(Hash)
db_val.value
else
default_settings[key]
@ -43,6 +45,7 @@ class Setting < RailsSettings::Base
default_settings.each do |key, default_value|
next if records.key?(key) || default_value.is_a?(Hash)
records[key] = Setting.new(var: key, value: default_value)
end
@ -51,6 +54,7 @@ class Setting < RailsSettings::Base
def default_settings
return {} unless RailsSettings::Default.enabled?
RailsSettings::Default.instance
end
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: site_uploads

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: statuses

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: status_edits
@ -45,6 +46,7 @@ class StatusEdit < ApplicationRecord
def emojis
return @emojis if defined?(@emojis)
@emojis = CustomEmoji.from_text([spoiler_text, text].join(' '), status.account.domain)
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: status_pins

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: status_stats

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: tags

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: unavailable_domains

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: users
@ -492,12 +493,14 @@ class User < ApplicationRecord
def sanitize_languages
return if chosen_languages.nil?
chosen_languages.reject!(&:blank?)
self.chosen_languages = nil if chosen_languages.empty?
end
def sanitize_role
return if role.nil?
self.role = nil if role.everyone?
end
@ -516,6 +519,7 @@ class User < ApplicationRecord
def notify_staff_about_pending_account!
User.those_who_can(:manage_users).includes(:account).find_each do |u|
next unless u.allows_pending_account_emails?
AdminMailer.new_pending_account(u.account, self).deliver_later
end
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: user_ips

View file

@ -163,6 +163,7 @@ class UserRole < ApplicationRecord
def in_permissions?(privilege)
raise ArgumentError, "Unknown privilege: #{privilege}" unless FLAGS.key?(privilege)
computed_permissions & FLAGS[privilege] == FLAGS[privilege]
end
@ -172,6 +173,7 @@ class UserRole < ApplicationRecord
def validate_own_role_edition
return unless defined?(@current_account) && @current_account.user_role.id == id
errors.add(:permissions_as_keys, :own_role) if permissions_changed?
errors.add(:position, :own_role) if position_changed?
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: web_push_subscriptions

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: web_settings

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: webauthn_credentials

View file

@ -70,16 +70,16 @@ class AccountRelationshipsPresenter
def cache_uncached!
@uncached_account_ids.each do |account_id|
maps_for_account = {
following: { account_id => following[account_id] },
followed_by: { account_id => followed_by[account_id] },
blocking: { account_id => blocking[account_id] },
blocked_by: { account_id => blocked_by[account_id] },
muting: { account_id => muting[account_id] },
requested: { account_id => requested[account_id] },
requested_by: { account_id => requested_by[account_id] },
following: { account_id => following[account_id] },
followed_by: { account_id => followed_by[account_id] },
blocking: { account_id => blocking[account_id] },
blocked_by: { account_id => blocked_by[account_id] },
muting: { account_id => muting[account_id] },
requested: { account_id => requested[account_id] },
requested_by: { account_id => requested_by[account_id] },
domain_blocking: { account_id => domain_blocking[account_id] },
endorsed: { account_id => endorsed[account_id] },
account_note: { account_id => account_note[account_id] },
endorsed: { account_id => endorsed[account_id] },
account_note: { account_id => account_note[account_id] },
}
Rails.cache.write("relationship:#{@current_account_id}:#{account_id}", maps_for_account, expires_in: 1.day)

View file

@ -50,6 +50,7 @@ class ActivityPub::FetchRemoteActorService < BaseService
if @username.casecmp(confirmed_username).zero? && @domain.casecmp(confirmed_domain).zero?
raise Error, "Webfinger response for #{@username}@#{@domain} does not loop back to #{@uri}" if webfinger.link('self', 'href') != @uri
return
end

View file

@ -56,6 +56,7 @@ class ActivityPub::FetchRemoteStatusService < BaseService
def trustworthy_attribution?(uri, attributed_to)
return false if uri.nil? || attributed_to.nil?
Addressable::URI.parse(uri).normalized_host.casecmp(Addressable::URI.parse(attributed_to).normalized_host).zero?
end

View file

@ -36,6 +36,7 @@ class ActivityPub::FetchRepliesService < BaseService
return collection_or_uri if collection_or_uri.is_a?(Hash)
return unless @allow_synchronous_requests
return if invalid_origin?(collection_or_uri)
fetch_resource_without_id_validation(collection_or_uri, nil, true)
end

View file

@ -226,6 +226,7 @@ class ActivityPub::ProcessAccountService < BaseService
def property_values
return unless @json['attachment'].is_a?(Array)
as_array(@json['attachment']).select { |attachment| attachment['type'] == 'PropertyValue' }.map { |attachment| attachment.slice('name', 'value') }
end
@ -289,6 +290,7 @@ class ActivityPub::ProcessAccountService < BaseService
def domain_block
return @domain_block if defined?(@domain_block)
@domain_block = DomainBlock.rule_for(@domain)
end

View file

@ -40,6 +40,7 @@ class FavouriteService < BaseService
def bump_potential_friendship(account, status)
ActivityTracker.increment('activity:interactions')
return if account.following?(status.account_id)
PotentialFriendshipTracker.record(account.id, status.account_id, :favourite)
end

View file

@ -9,10 +9,10 @@ class Keys::ClaimService < BaseService
def initialize(account, device_id, key_attributes = {})
super(
account: account,
account: account,
device_id: device_id,
key_id: key_attributes[:key_id],
key: key_attributes[:key],
key_id: key_attributes[:key_id],
key: key_attributes[:key],
signature: key_attributes[:signature],
)
end

View file

@ -23,9 +23,9 @@ class Keys::QueryService < BaseService
def initialize(attributes = {})
super(
device_id: attributes[:device_id],
name: attributes[:name],
identity_key: attributes[:identity_key],
device_id: attributes[:device_id],
name: attributes[:name],
identity_key: attributes[:identity_key],
fingerprint_key: attributes[:fingerprint_key],
)
@claim_url = attributes[:claim_url]

View file

@ -31,6 +31,7 @@ class NotifyService < BaseService
def following_sender?
return @following_sender if defined?(@following_sender)
@following_sender = @recipient.following?(@notification.from_account) || @recipient.requested?(@notification.from_account)
end

View file

@ -86,6 +86,7 @@ class PostStatusService < BaseService
def safeguard_mentions!(status)
return if @options[:allowed_mentions].nil?
expected_account_ids = @options[:allowed_mentions].map(&:to_i)
unexpected_accounts = status.mentions.map(&:account).to_a.reject { |mentioned_account| expected_account_ids.include?(mentioned_account.id) }
@ -175,8 +176,10 @@ class PostStatusService < BaseService
def bump_potential_friendship!
return if !@status.reply? || @account.id == @status.in_reply_to_account_id
ActivityTracker.increment('activity:interactions')
return if @account.following?(@status.in_reply_to_account_id)
PotentialFriendshipTracker.record(@account.id, @status.in_reply_to_account_id, :reply)
end

View file

@ -44,11 +44,13 @@ class VoteService < BaseService
def distribute_poll!
return if @poll.hide_totals?
ActivityPub::DistributePollUpdateWorker.perform_in(3.minutes, @poll.status.id)
end
def queue_final_poll_check!
return unless @poll.expires?
PollExpirationNotifyWorker.perform_at(@poll.expires_at + 5.minutes, @poll.id)
end

View file

@ -6,6 +6,7 @@ class FollowLimitValidator < ActiveModel::Validator
def validate(follow)
return if follow.account.nil? || !follow.account.local?
follow.errors.add(:base, I18n.t('users.follow_limit_reached', limit: self.class.limit_for_account(follow.account))) if limit_reached?(follow.account)
end

View file

@ -13,12 +13,14 @@ class UnreservedUsernameValidator < ActiveModel::Validator
def pam_controlled?
return false unless Devise.pam_authentication && Devise.pam_controlled_service
Rpam2.account(Devise.pam_controlled_service, @username).present?
end
def reserved_username?
return true if pam_controlled?
return false unless Setting.reserved_usernames
Setting.reserved_usernames.include?(@username.downcase)
end
end

View file

@ -62,6 +62,7 @@ class Scheduler::AccountsStatusesCleanupScheduler
# The idea here is to loop through all policies at least once until the budget is exhausted
# and start back after the last processed account otherwise
break if budget.zero? || (num_processed_accounts.zero? && first_policy_id.nil?)
first_policy_id = nil
end
end
@ -73,6 +74,7 @@ class Scheduler::AccountsStatusesCleanupScheduler
def under_load?
return true if Sidekiq::Stats.new.retry_size > MAX_RETRY_SIZE
queue_under_load?('default', MAX_DEFAULT_SIZE, MAX_DEFAULT_LATENCY) || queue_under_load?('push', MAX_PUSH_SIZE, MAX_PUSH_LATENCY) || queue_under_load?('pull', MAX_PULL_SIZE, MAX_PULL_LATENCY)
end

View file

@ -22,13 +22,13 @@ class Web::PushNotificationWorker
request = Request.new(:post, @subscription.endpoint, body: payload.fetch(:ciphertext), http_client: http_client)
request.add_headers(
'Content-Type' => 'application/octet-stream',
'Ttl' => TTL,
'Urgency' => URGENCY,
'Content-Type' => 'application/octet-stream',
'Ttl' => TTL,
'Urgency' => URGENCY,
'Content-Encoding' => 'aesgcm',
'Encryption' => "salt=#{Webpush.encode64(payload.fetch(:salt)).delete('=')}",
'Crypto-Key' => "dh=#{Webpush.encode64(payload.fetch(:server_public_key)).delete('=')};#{@subscription.crypto_key_header}",
'Authorization' => @subscription.authorization_header
'Encryption' => "salt=#{Webpush.encode64(payload.fetch(:salt)).delete('=')}",
'Crypto-Key' => "dh=#{Webpush.encode64(payload.fetch(:server_public_key)).delete('=')};#{@subscription.crypto_key_header}",
'Authorization' => @subscription.authorization_header
)
request.perform do |response|

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
# This file is used by Rack-based servers to start the application.
require File.expand_path('config/environment', __dir__)

Some files were not shown because too many files have changed in this diff Show more