Fix Lint/DuplicateBranch cop (#24766)
This commit is contained in:
parent
f50105779b
commit
88d33f361f
|
@ -119,15 +119,6 @@ Lint/ConstantDefinitionInBlock:
|
||||||
- 'spec/lib/connection_pool/shared_timed_stack_spec.rb'
|
- 'spec/lib/connection_pool/shared_timed_stack_spec.rb'
|
||||||
- 'spec/models/concerns/remotable_spec.rb'
|
- 'spec/models/concerns/remotable_spec.rb'
|
||||||
|
|
||||||
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
|
|
||||||
Lint/DuplicateBranch:
|
|
||||||
Exclude:
|
|
||||||
- 'app/lib/permalink_redirector.rb'
|
|
||||||
- 'app/models/account_statuses_filter.rb'
|
|
||||||
- 'app/validators/email_mx_validator.rb'
|
|
||||||
- 'app/validators/vote_validator.rb'
|
|
||||||
- 'lib/mastodon/maintenance_cli.rb'
|
|
||||||
|
|
||||||
# Configuration parameters: AllowComments, AllowEmptyLambdas.
|
# Configuration parameters: AllowComments, AllowEmptyLambdas.
|
||||||
Lint/EmptyBlock:
|
Lint/EmptyBlock:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|
|
@ -8,19 +8,49 @@ class PermalinkRedirector
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_path
|
def redirect_path
|
||||||
if path_segments[0].present? && path_segments[0].start_with?('@') && path_segments[1] =~ /\d/
|
if at_username_status_request? || statuses_status_request?
|
||||||
find_status_url_by_id(path_segments[1])
|
find_status_url_by_id(second_segment)
|
||||||
elsif path_segments[0].present? && path_segments[0].start_with?('@')
|
elsif at_username_request?
|
||||||
find_account_url_by_name(path_segments[0])
|
find_account_url_by_name(first_segment)
|
||||||
elsif path_segments[0] == 'statuses' && path_segments[1] =~ /\d/
|
elsif accounts_request? && record_integer_id_request?
|
||||||
find_status_url_by_id(path_segments[1])
|
find_account_url_by_id(second_segment)
|
||||||
elsif path_segments[0] == 'accounts' && path_segments[1] =~ /\d/
|
|
||||||
find_account_url_by_id(path_segments[1])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def at_username_status_request?
|
||||||
|
at_username_request? && record_integer_id_request?
|
||||||
|
end
|
||||||
|
|
||||||
|
def statuses_status_request?
|
||||||
|
statuses_request? && record_integer_id_request?
|
||||||
|
end
|
||||||
|
|
||||||
|
def at_username_request?
|
||||||
|
first_segment.present? && first_segment.start_with?('@')
|
||||||
|
end
|
||||||
|
|
||||||
|
def statuses_request?
|
||||||
|
first_segment == 'statuses'
|
||||||
|
end
|
||||||
|
|
||||||
|
def accounts_request?
|
||||||
|
first_segment == 'accounts'
|
||||||
|
end
|
||||||
|
|
||||||
|
def record_integer_id_request?
|
||||||
|
second_segment =~ /\d/
|
||||||
|
end
|
||||||
|
|
||||||
|
def first_segment
|
||||||
|
path_segments.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def second_segment
|
||||||
|
path_segments.second
|
||||||
|
end
|
||||||
|
|
||||||
def path_segments
|
def path_segments
|
||||||
@path_segments ||= @path.gsub(/\A\//, '').split('/')
|
@path_segments ||= @path.gsub(/\A\//, '').split('/')
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,9 +32,9 @@ class AccountStatusesFilter
|
||||||
private
|
private
|
||||||
|
|
||||||
def initial_scope
|
def initial_scope
|
||||||
if suspended?
|
return Status.none if suspended?
|
||||||
Status.none
|
|
||||||
elsif anonymous?
|
if anonymous?
|
||||||
account.statuses.where(visibility: %i(public unlisted))
|
account.statuses.where(visibility: %i(public unlisted))
|
||||||
elsif author?
|
elsif author?
|
||||||
account.statuses.all # NOTE: #merge! does not work without the #all
|
account.statuses.all # NOTE: #merge! does not work without the #all
|
||||||
|
|
|
@ -8,9 +8,7 @@ class EmailMxValidator < ActiveModel::Validator
|
||||||
|
|
||||||
domain = get_domain(user.email)
|
domain = get_domain(user.email)
|
||||||
|
|
||||||
if domain.blank?
|
if domain.blank? || domain.include?('..')
|
||||||
user.errors.add(:email, :invalid)
|
|
||||||
elsif domain.include?('..')
|
|
||||||
user.errors.add(:email, :invalid)
|
user.errors.add(:email, :invalid)
|
||||||
elsif !on_allowlist?(domain)
|
elsif !on_allowlist?(domain)
|
||||||
resolved_ips, resolved_domains = resolve_mx(domain)
|
resolved_ips, resolved_domains = resolve_mx(domain)
|
||||||
|
|
|
@ -6,15 +6,23 @@ class VoteValidator < ActiveModel::Validator
|
||||||
|
|
||||||
vote.errors.add(:base, I18n.t('polls.errors.invalid_choice')) if invalid_choice?(vote)
|
vote.errors.add(:base, I18n.t('polls.errors.invalid_choice')) if invalid_choice?(vote)
|
||||||
|
|
||||||
if vote.poll_multiple? && already_voted_for_same_choice_on_multiple_poll?(vote)
|
vote.errors.add(:base, I18n.t('polls.errors.already_voted')) if additional_voting_not_allowed?(vote)
|
||||||
vote.errors.add(:base, I18n.t('polls.errors.already_voted'))
|
|
||||||
elsif !vote.poll_multiple? && already_voted_on_non_multiple_poll?(vote)
|
|
||||||
vote.errors.add(:base, I18n.t('polls.errors.already_voted'))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def additional_voting_not_allowed?(vote)
|
||||||
|
poll_multiple_and_already_voted?(vote) || poll_non_multiple_and_already_voted?(vote)
|
||||||
|
end
|
||||||
|
|
||||||
|
def poll_multiple_and_already_voted?(vote)
|
||||||
|
vote.poll_multiple? && already_voted_for_same_choice_on_multiple_poll?(vote)
|
||||||
|
end
|
||||||
|
|
||||||
|
def poll_non_multiple_and_already_voted?(vote)
|
||||||
|
!vote.poll_multiple? && already_voted_on_non_multiple_poll?(vote)
|
||||||
|
end
|
||||||
|
|
||||||
def invalid_choice?(vote)
|
def invalid_choice?(vote)
|
||||||
vote.choice.negative? || vote.choice >= vote.poll.options.size
|
vote.choice.negative? || vote.choice >= vote.poll.options.size
|
||||||
end
|
end
|
||||||
|
|
|
@ -664,9 +664,7 @@ module Mastodon
|
||||||
|
|
||||||
def remove_index_if_exists!(table, name)
|
def remove_index_if_exists!(table, name)
|
||||||
ActiveRecord::Base.connection.remove_index(table, name: name)
|
ActiveRecord::Base.connection.remove_index(table, name: name)
|
||||||
rescue ArgumentError
|
rescue ArgumentError, ActiveRecord::StatementInvalid
|
||||||
nil
|
|
||||||
rescue ActiveRecord::StatementInvalid
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue