forked from fedi/mastodon
Conditional validations no longer accept strings for if/unless (#3124)
This commit is contained in:
parent
d2542dcec0
commit
6e4c7d6211
|
@ -4,7 +4,7 @@ class RemoteFollowController < ApplicationController
|
||||||
layout 'public'
|
layout 'public'
|
||||||
|
|
||||||
before_action :set_account
|
before_action :set_account
|
||||||
before_action :gone, if: -> { @account.suspended? }
|
before_action :gone, if: :suspended_account?
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@remote_follow = RemoteFollow.new(session_params)
|
@remote_follow = RemoteFollow.new(session_params)
|
||||||
|
@ -34,4 +34,8 @@ class RemoteFollowController < ApplicationController
|
||||||
def set_account
|
def set_account
|
||||||
@account = Account.find_local!(params[:account_username])
|
@account = Account.find_local!(params[:account_username])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def suspended_account?
|
||||||
|
@account.suspended?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,6 @@ module ApplicationExtension
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
validates :website, url: true, unless: 'website.blank?'
|
validates :website, url: true, if: :website?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,10 +52,10 @@ class Account < ApplicationRecord
|
||||||
has_one :user, inverse_of: :account
|
has_one :user, inverse_of: :account
|
||||||
|
|
||||||
validates :username, presence: true
|
validates :username, presence: true
|
||||||
validates :username, uniqueness: { scope: :domain, case_sensitive: true }, unless: 'local?'
|
validates :username, uniqueness: { scope: :domain, case_sensitive: true }, unless: :local?
|
||||||
|
|
||||||
# Local user validations
|
# Local user validations
|
||||||
with_options if: 'local?' do
|
with_options if: :local? do
|
||||||
validates :username, format: { with: /\A[a-z0-9_]+\z/i }, uniqueness: { scope: :domain, case_sensitive: false }, length: { maximum: 30 }
|
validates :username, format: { with: /\A[a-z0-9_]+\z/i }, uniqueness: { scope: :domain, case_sensitive: false }, length: { maximum: 30 }
|
||||||
validates :display_name, length: { maximum: 30 }
|
validates :display_name, length: { maximum: 30 }
|
||||||
validates :note, length: { maximum: 160 }
|
validates :note, length: { maximum: 160 }
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class Conversation < ApplicationRecord
|
class Conversation < ApplicationRecord
|
||||||
validates :uri, uniqueness: true, if: :uri
|
validates :uri, uniqueness: true, if: :uri?
|
||||||
|
|
||||||
has_many :statuses
|
has_many :statuses
|
||||||
|
|
||||||
|
|
|
@ -50,10 +50,10 @@ class Status < ApplicationRecord
|
||||||
has_one :notification, as: :activity, dependent: :destroy
|
has_one :notification, as: :activity, dependent: :destroy
|
||||||
has_one :preview_card, dependent: :destroy
|
has_one :preview_card, dependent: :destroy
|
||||||
|
|
||||||
validates :uri, uniqueness: true, unless: 'local?'
|
validates :uri, uniqueness: true, unless: :local?
|
||||||
validates :text, presence: true, unless: 'reblog?'
|
validates :text, presence: true, unless: :reblog?
|
||||||
validates_with StatusLengthValidator
|
validates_with StatusLengthValidator
|
||||||
validates :reblog, uniqueness: { scope: :account }, if: 'reblog?'
|
validates :reblog, uniqueness: { scope: :account }, if: :reblog?
|
||||||
|
|
||||||
default_scope { order(id: :desc) }
|
default_scope { order(id: :desc) }
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ class User < ApplicationRecord
|
||||||
belongs_to :account, inverse_of: :user, required: true
|
belongs_to :account, inverse_of: :user, required: true
|
||||||
accepts_nested_attributes_for :account
|
accepts_nested_attributes_for :account
|
||||||
|
|
||||||
validates :locale, inclusion: I18n.available_locales.map(&:to_s), unless: 'locale.nil?'
|
validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
|
||||||
validates :email, email: true
|
validates :email, email: true
|
||||||
|
|
||||||
scope :recent, -> { order(id: :desc) }
|
scope :recent, -> { order(id: :desc) }
|
||||||
|
|
Loading…
Reference in a new issue