Skip to content

Commit

Permalink
Merge remote-tracking branch 'parent/main' into upstream-20240218
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Feb 18, 2024
2 parents c8c8c87 + 96ddf1d commit a1f88f6
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 170 deletions.
6 changes: 0 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ Rails/FilePath:
Rails/HttpStatus:
EnforcedStyle: numeric

# Reason: Allowed in boot ENV checker
# https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsexit
Rails/Exit:
Exclude:
- 'config/boot.rb'

# Reason: Conflicts with `Lint/UselessMethodDefinition` for inherited controller actions
# https://docs.rubocop.org/rubocop-rails/cops_rails.html#railslexicallyscopedactionfilter
Rails/LexicallyScopedActionFilter:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ GEM
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
doorkeeper (5.6.8)
doorkeeper (5.6.9)
railties (>= 5)
dotenv (2.8.1)
dotenv-rails (2.8.1)
Expand Down Expand Up @@ -813,7 +813,7 @@ GEM
xorcist (1.1.3)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.12)
zeitwerk (2.6.13)

PLATFORMS
ruby
Expand Down
6 changes: 3 additions & 3 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class Account < ApplicationRecord
include DomainNormalizable
include Paginable

enum protocol: { ostatus: 0, activitypub: 1 }
enum suspension_origin: { local: 0, remote: 1 }, _prefix: true
enum searchability: { public: 0, private: 1, direct: 2, limited: 3, unsupported: 4, public_unlisted: 10 }, _suffix: :searchability
enum :protocol, { ostatus: 0, activitypub: 1 }
enum :suspension_origin, { local: 0, remote: 1 }, prefix: true
enum :searchability, { public: 0, private: 1, direct: 2, limited: 3, unsupported: 4, public_unlisted: 10 }, suffix: :searchability

validates :username, presence: true
validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? }
Expand Down
4 changes: 2 additions & 2 deletions app/models/account_warning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#

class AccountWarning < ApplicationRecord
enum action: {
enum :action, {
none: 0,
disable: 1_000,
force_cw: 1_200,
Expand All @@ -26,7 +26,7 @@ class AccountWarning < ApplicationRecord
sensitive: 2_000,
silence: 3_000,
suspend: 4_000,
}, _suffix: :action
}, suffix: :action

normalizes :text, with: ->(text) { text.to_s }, apply_to_nil: true

Expand Down
4 changes: 2 additions & 2 deletions app/models/bulk_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BulkImport < ApplicationRecord
belongs_to :account
has_many :rows, class_name: 'BulkImportRow', inverse_of: :bulk_import, dependent: :delete_all

enum type: {
enum :type, {
following: 0,
blocking: 1,
muting: 2,
Expand All @@ -33,7 +33,7 @@ class BulkImport < ApplicationRecord
lists: 5,
}

enum state: {
enum :state, {
unconfirmed: 0,
scheduled: 1,
in_progress: 2,
Expand Down
2 changes: 1 addition & 1 deletion app/models/custom_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CustomFilter < ApplicationRecord
include Expireable
include Redisable

enum action: { warn: 0, hide: 1, half_warn: 2 }, _suffix: :action
enum :action, { warn: 0, hide: 1, half_warn: 2 }, suffix: :action

belongs_to :account
has_many :keywords, class_name: 'CustomFilterKeyword', inverse_of: :custom_filter, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/models/domain_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DomainBlock < ApplicationRecord
include DomainNormalizable
include DomainMaterializable

enum severity: { silence: 0, suspend: 1, noop: 2 }
enum :severity, { silence: 0, suspend: 1, noop: 2 }

validates :domain, presence: true, uniqueness: true, domain: true

Expand Down
4 changes: 2 additions & 2 deletions app/models/friend_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class FriendDomain < ApplicationRecord
validates :domain, presence: true, uniqueness: true, if: :will_save_change_to_domain?
validates :inbox_url, presence: true, uniqueness: true, if: :will_save_change_to_inbox_url?

enum active_state: { idle: 0, pending: 1, accepted: 2, rejected: 3 }, _prefix: :i_am
enum passive_state: { idle: 0, pending: 1, accepted: 2, rejected: 3 }, _prefix: :they_are
enum :active_state, { idle: 0, pending: 1, accepted: 2, rejected: 3 }, prefix: :i_am
enum :passive_state, { idle: 0, pending: 1, accepted: 2, rejected: 3 }, prefix: :they_are

scope :by_domain_and_subdomains, ->(domain) { where(domain: Instance.by_domain_and_subdomains(domain).select(:domain)) }
scope :enabled, -> { where(active_state: :accepted).or(FriendDomain.where(passive_state: :accepted)).where(available: true) }
Expand Down
2 changes: 1 addition & 1 deletion app/models/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Import < ApplicationRecord

belongs_to :account

enum type: { following: 0, blocking: 1, muting: 2, domain_blocking: 3, bookmarks: 4 }
enum :type, { following: 0, blocking: 1, muting: 2, domain_blocking: 3, bookmarks: 4 }

validates :type, presence: true

Expand Down
2 changes: 1 addition & 1 deletion app/models/ip_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IpBlock < ApplicationRecord
include Expireable
include Paginable

enum severity: {
enum :severity, {
sign_up_requires_approval: 5000,
sign_up_block: 5500,
no_access: 9999,
Expand Down
2 changes: 1 addition & 1 deletion app/models/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class List < ApplicationRecord

PER_ACCOUNT_LIMIT = 50

enum replies_policy: { list: 0, followed: 1, none: 2 }, _prefix: :show
enum :replies_policy, { list: 0, followed: 1, none: 2 }, prefix: :show

belongs_to :account, optional: true

Expand Down
2 changes: 1 addition & 1 deletion app/models/login_activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

class LoginActivity < ApplicationRecord
enum authentication_method: { password: 'password', otp: 'otp', webauthn: 'webauthn', sign_in_token: 'sign_in_token', omniauth: 'omniauth' }
enum :authentication_method, { password: 'password', otp: 'otp', webauthn: 'webauthn', sign_in_token: 'sign_in_token', omniauth: 'omniauth' }

belongs_to :user

Expand Down
4 changes: 2 additions & 2 deletions app/models/media_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class MediaAttachment < ApplicationRecord
LOCAL_STATUS_ATTACHMENT_MAX_WITH_POLL = 4
ACTIVITYPUB_STATUS_ATTACHMENT_MAX = 16

enum type: { image: 0, gifv: 1, video: 2, unknown: 3, audio: 4 }
enum processing: { queued: 0, in_progress: 1, complete: 2, failed: 3 }, _prefix: true
enum :type, { image: 0, gifv: 1, video: 2, unknown: 3, audio: 4 }
enum :processing, { queued: 0, in_progress: 1, complete: 2, failed: 3 }, prefix: true

MAX_DESCRIPTION_LENGTH = 1_500

Expand Down
4 changes: 2 additions & 2 deletions app/models/ngword_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
class NgwordHistory < ApplicationRecord
include Paginable

enum target_type: { status: 0, account_note: 1, account_name: 2 }, _suffix: :blocked
enum reason: { ng_words: 0, ng_words_for_stranger_mention: 1, hashtag_count: 2, mention_count: 3, stranger_mention_count: 4 }, _prefix: :within
enum :target_type, { status: 0, account_note: 1, account_name: 2 }, suffix: :blocked
enum :reason, { ng_words: 0, ng_words_for_stranger_mention: 1, hashtag_count: 2, mention_count: 3, stranger_mention_count: 4 }, prefix: :within
end
4 changes: 2 additions & 2 deletions app/models/preview_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class PreviewCard < ApplicationRecord

self.inheritance_column = false

enum type: { link: 0, photo: 1, video: 2, rich: 3 }
enum link_type: { unknown: 0, article: 1 }
enum :type, { link: 0, photo: 1, video: 2, rich: 3 }
enum :link_type, { unknown: 0, article: 1 }

has_many :preview_cards_statuses, dependent: :delete_all, inverse_of: :preview_card
has_many :statuses, through: :preview_cards_statuses
Expand Down
2 changes: 1 addition & 1 deletion app/models/relay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Relay < ApplicationRecord
validates :inbox_url, presence: true, uniqueness: true, url: true, if: :will_save_change_to_inbox_url?

enum state: { idle: 0, pending: 1, accepted: 2, rejected: 3 }
enum :state, { idle: 0, pending: 1, accepted: 2, rejected: 3 }

scope :enabled, -> { accepted }

Expand Down
2 changes: 1 addition & 1 deletion app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Report < ApplicationRecord
# - app/javascript/mastodon/features/notifications/components/report.jsx
# - app/javascript/mastodon/features/report/category.jsx
# - app/javascript/mastodon/components/admin/ReportReasonSelector.jsx
enum category: {
enum :category, {
other: 0,
spam: 1_000,
legal: 1_500,
Expand Down
2 changes: 1 addition & 1 deletion app/models/software_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class SoftwareUpdate < ApplicationRecord
self.inheritance_column = nil

enum type: { patch: 0, minor: 1, major: 2 }, _suffix: :type
enum :type, { patch: 0, minor: 1, major: 2 }, suffix: :type

def gem_version
Gem::Version.new(version)
Expand Down
6 changes: 3 additions & 3 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class Status < ApplicationRecord
update_index('statuses', :proper)
update_index('public_statuses', :proper)

enum visibility: { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4, public_unlisted: 10, login: 11 }, _suffix: :visibility
enum searchability: { public: 0, private: 1, direct: 2, limited: 3, unsupported: 4, public_unlisted: 10 }, _suffix: :searchability
enum limited_scope: { none: 0, mutual: 1, circle: 2, personal: 3, reply: 4 }, _suffix: :limited
enum :visibility, { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4, public_unlisted: 10, login: 11 }, suffix: :visibility
enum :searchability, { public: 0, private: 1, direct: 2, limited: 3, unsupported: 4, public_unlisted: 10 }, suffix: :searchability
enum :limited_scope, { none: 0, mutual: 1, circle: 2, personal: 3, reply: 4 }, suffix: :limited

belongs_to :application, class_name: 'Doorkeeper::Application', optional: true

Expand Down
11 changes: 9 additions & 2 deletions config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# frozen_string_literal: true

unless ENV.key?('RAILS_ENV')
warn 'ERROR: Missing RAILS_ENV environment variable, please set it to "production", "development", or "test".'
exit 1
abort <<~ERROR
The RAILS_ENV environment variable is not set.
Please set it correctly depending on context:
- Use "production" for a live deployment of the application
- Use "development" for local feature work
- Use "test" when running the automated spec suite
ERROR
end

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
Expand Down
31 changes: 14 additions & 17 deletions spec/controllers/admin/disputes/appeals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,36 @@
end

describe 'POST #approve' do
subject { post :approve, params: { id: appeal.id } }

let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }

before do
post :approve, params: { id: appeal.id }
end
it 'redirects back to the strike page and notifies target account about approved appeal', :sidekiq_inline do
subject

it 'unsuspends a suspended account' do
expect(target_account.reload.suspended?).to be false
end
expect(response)
.to redirect_to(disputes_strike_path(appeal.strike))

it 'redirects back to the strike page' do
expect(response).to redirect_to(disputes_strike_path(appeal.strike))
end
expect(target_account.reload)
.to_not be_suspended

it 'notifies target account about approved appeal', :sidekiq_inline do
expect(UserMailer.deliveries.size).to eq(1)
expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email)
expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at)))
end
end

describe 'POST #reject' do
subject { post :reject, params: { id: appeal.id } }

let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }

before do
post :reject, params: { id: appeal.id }
end
it 'redirects back to the strike page and notifies target account about rejected appeal', :sidekiq_inline do
subject

it 'redirects back to the strike page' do
expect(response).to redirect_to(disputes_strike_path(appeal.strike))
end
expect(response)
.to redirect_to(disputes_strike_path(appeal.strike))

it 'notifies target account about rejected appeal', :sidekiq_inline do
expect(UserMailer.deliveries.size).to eq(1)
expect(UserMailer.deliveries.first.to.first).to eq(target_account.user.email)
expect(UserMailer.deliveries.first.subject).to eq(I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at)))
Expand Down
Loading

0 comments on commit a1f88f6

Please sign in to comment.