mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Compare commits
8 commits
5fba778531
...
b57249a641
Author | SHA1 | Date | |
---|---|---|---|
|
b57249a641 | ||
|
a50c8e951f | ||
|
2c1e75727d | ||
|
7060867bb2 | ||
|
c6047b2f1e | ||
|
8d471cb3c3 | ||
|
597e957c22 | ||
|
0744e4afa3 |
14 changed files with 97 additions and 48 deletions
|
@ -60,7 +60,7 @@ export interface BaseNotificationGroupJSON {
|
|||
|
||||
interface NotificationGroupWithStatusJSON extends BaseNotificationGroupJSON {
|
||||
type: NotificationWithStatusType;
|
||||
status: ApiStatusJSON;
|
||||
status_id: string;
|
||||
}
|
||||
|
||||
interface NotificationWithStatusJSON extends BaseNotificationJSON {
|
||||
|
|
|
@ -49,22 +49,15 @@ export const FilteredNotificationsBanner: React.FC = () => {
|
|||
<span>
|
||||
<FormattedMessage
|
||||
id='filtered_notifications_banner.pending_requests'
|
||||
defaultMessage='Notifications from {count, plural, =0 {no one} one {one person} other {# people}} you may know'
|
||||
defaultMessage='From {count, plural, =0 {no one} one {one person} other {# people}} you may know'
|
||||
values={{ count: policy.summary.pending_requests_count }}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className='filtered-notifications-banner__badge'>
|
||||
<div className='filtered-notifications-banner__badge__badge'>
|
||||
{toCappedNumber(policy.summary.pending_notifications_count)}
|
||||
</div>
|
||||
<FormattedMessage
|
||||
id='filtered_notifications_banner.mentions'
|
||||
defaultMessage='{count, plural, one {mention} other {mentions}}'
|
||||
values={{ count: policy.summary.pending_notifications_count }}
|
||||
/>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -300,8 +300,7 @@
|
|||
"filter_modal.select_filter.subtitle": "Use an existing category or create a new one",
|
||||
"filter_modal.select_filter.title": "Filter this post",
|
||||
"filter_modal.title.status": "Filter a post",
|
||||
"filtered_notifications_banner.mentions": "{count, plural, one {mention} other {mentions}}",
|
||||
"filtered_notifications_banner.pending_requests": "Notifications from {count, plural, =0 {no one} one {one person} other {# people}} you may know",
|
||||
"filtered_notifications_banner.pending_requests": "From {count, plural, =0 {no one} one {one person} other {# people}} you may know",
|
||||
"filtered_notifications_banner.title": "Filtered notifications",
|
||||
"firehose.all": "All",
|
||||
"firehose.local": "This server",
|
||||
|
|
|
@ -124,9 +124,9 @@ export function createNotificationGroupFromJSON(
|
|||
case 'mention':
|
||||
case 'poll':
|
||||
case 'update': {
|
||||
const { status, ...groupWithoutStatus } = group;
|
||||
const { status_id: statusId, ...groupWithoutStatus } = group;
|
||||
return {
|
||||
statusId: status.id,
|
||||
statusId,
|
||||
sampleAccountIds,
|
||||
...groupWithoutStatus,
|
||||
};
|
||||
|
|
|
@ -10170,20 +10170,6 @@ noscript {
|
|||
}
|
||||
}
|
||||
|
||||
&__badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 999px;
|
||||
background: var(--background-border-color);
|
||||
color: $darker-text-color;
|
||||
padding: 4px;
|
||||
padding-inline-end: 8px;
|
||||
gap: 6px;
|
||||
font-weight: 500;
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
word-break: keep-all;
|
||||
|
||||
&__badge {
|
||||
background: $ui-button-background-color;
|
||||
color: $white;
|
||||
|
@ -10191,7 +10177,6 @@ noscript {
|
|||
padding: 2px 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.notification-request {
|
||||
display: flex;
|
||||
|
|
|
@ -98,7 +98,7 @@ class User < ApplicationRecord
|
|||
accepts_nested_attributes_for :invite_request, reject_if: ->(attributes) { attributes['text'].blank? && !Setting.require_invite_text }
|
||||
validates :invite_request, presence: true, on: :create, if: :invite_text_required?
|
||||
|
||||
validates :email, presence: true, email_address: true
|
||||
validates :email, presence: true, email_address: true, disposable_email: true
|
||||
|
||||
validates_with BlacklistedEmailValidator, if: -> { ENV['EMAIL_DOMAIN_LISTS_APPLY_AFTER_CONFIRMATION'] == 'true' || !confirmed? }
|
||||
validates_with EmailMxValidator, if: :validate_email_dns?
|
||||
|
|
36
app/validators/disposable_email_validator.rb
Normal file
36
app/validators/disposable_email_validator.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DisposableEmailValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
return if value.blank?
|
||||
|
||||
return unless disposable_email?(value)
|
||||
|
||||
record.errors.add(
|
||||
attribute,
|
||||
(options[:message] || I18n.t('disposable_email_validator.invalid'))
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def disposable_email?(email)
|
||||
email_address = begin
|
||||
Mail::Address.new(email.downcase)
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
return false unless email_address
|
||||
|
||||
disposable_email_domains.include?(email_address.domain)
|
||||
end
|
||||
|
||||
def disposable_email_domains
|
||||
file_path = Rails.root.join('data', 'disposable_email_domains.txt')
|
||||
return [] unless File.exist? file_path
|
||||
|
||||
data = File.read(file_path)
|
||||
JSON.parse(data)
|
||||
end
|
||||
end
|
|
@ -1174,6 +1174,8 @@ en-GB:
|
|||
more_details_html: For more details, see the <a href="%{terms_path}">privacy policy</a>.
|
||||
username_available: Your username will become available again
|
||||
username_unavailable: Your username will remain unavailable
|
||||
disposable_email_validator:
|
||||
invalid: emails with this domain are not allowed
|
||||
disputes:
|
||||
strikes:
|
||||
action_taken: Action taken
|
||||
|
|
|
@ -1190,6 +1190,8 @@ en:
|
|||
more_details_html: For more details, see the <a href="%{terms_path}">privacy policy</a>.
|
||||
username_available: Your username will become available again
|
||||
username_unavailable: Your username will remain unavailable
|
||||
disposable_email_validator:
|
||||
invalid: emails with this domain are not allowed
|
||||
disputes:
|
||||
strikes:
|
||||
action_taken: Action taken
|
||||
|
|
1
data/disposable_email_domains.txt
Normal file
1
data/disposable_email_domains.txt
Normal file
File diff suppressed because one or more lines are too long
13
lib/tasks/disposable_email_domains.rake
Normal file
13
lib/tasks/disposable_email_domains.rake
Normal file
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
namespace :disposable_email_domains do
|
||||
desc 'Download latest list of disposable email domains'
|
||||
task download: :environment do
|
||||
data = HTTP.get('https://disposable.github.io/disposable-email-domains/domains.json').to_s
|
||||
|
||||
dir = Rails.root.join('data')
|
||||
FileUtils.mkdir_p(dir)
|
||||
|
||||
File.write("#{dir}/disposable_email_domains.txt", data, mode: 'w')
|
||||
end
|
||||
end
|
|
@ -246,8 +246,8 @@ describe Mastodon::CLI::Accounts do
|
|||
end
|
||||
|
||||
context 'with --email option' do
|
||||
let(:user) { Fabricate(:user, email: 'old_email@email.com') }
|
||||
let(:options) { { email: 'new_email@email.com' } }
|
||||
let(:user) { Fabricate(:user, email: 'old_email@example.com') }
|
||||
let(:options) { { email: 'new_email@example.com' } }
|
||||
|
||||
it "sets the user's unconfirmed email to the provided email address" do
|
||||
expect { subject }
|
||||
|
@ -260,12 +260,12 @@ describe Mastodon::CLI::Accounts do
|
|||
expect { subject }
|
||||
.to output_results('OK')
|
||||
|
||||
expect(user.reload.email).to eq('old_email@email.com')
|
||||
expect(user.reload.email).to eq('old_email@example.com')
|
||||
end
|
||||
|
||||
context 'with --confirm option' do
|
||||
let(:user) { Fabricate(:user, email: 'old_email@email.com', confirmed_at: nil) }
|
||||
let(:options) { { email: 'new_email@email.com', confirm: true } }
|
||||
let(:user) { Fabricate(:user, email: 'old_email@example.com', confirmed_at: nil) }
|
||||
let(:options) { { email: 'new_email@example.com', confirm: true } }
|
||||
|
||||
it "updates the user's email address to the provided email" do
|
||||
expect { subject }
|
||||
|
|
|
@ -6,7 +6,7 @@ RSpec.describe AppSignUpService do
|
|||
subject { described_class.new }
|
||||
|
||||
let(:app) { Fabricate(:application, scopes: 'read write') }
|
||||
let(:good_params) { { username: 'alice', password: '12345678', email: 'good@email.com', agreement: true } }
|
||||
let(:good_params) { { username: 'alice', password: '12345678', email: 'good@example.com', agreement: true } }
|
||||
let(:remote_ip) { IPAddr.new('198.0.2.1') }
|
||||
|
||||
describe '#call' do
|
||||
|
@ -30,7 +30,7 @@ RSpec.describe AppSignUpService do
|
|||
context 'when the email address requires approval' do
|
||||
before do
|
||||
Setting.registrations_mode = 'open'
|
||||
Fabricate(:email_domain_block, allow_with_approval: true, domain: 'email.com')
|
||||
Fabricate(:email_domain_block, allow_with_approval: true, domain: 'example.com')
|
||||
end
|
||||
|
||||
it 'creates an unapproved user', :aggregate_failures do
|
||||
|
@ -51,18 +51,18 @@ RSpec.describe AppSignUpService do
|
|||
context 'when the email address requires approval through MX records' do
|
||||
before do
|
||||
Setting.registrations_mode = 'open'
|
||||
Fabricate(:email_domain_block, allow_with_approval: true, domain: 'smtp.email.com')
|
||||
Fabricate(:email_domain_block, allow_with_approval: true, domain: 'smtp.example.com')
|
||||
allow(User).to receive(:skip_mx_check?).and_return(false)
|
||||
|
||||
resolver = instance_double(Resolv::DNS, :timeouts= => nil)
|
||||
|
||||
allow(resolver).to receive(:getresources)
|
||||
.with('email.com', Resolv::DNS::Resource::IN::MX)
|
||||
.and_return([instance_double(Resolv::DNS::Resource::MX, exchange: 'smtp.email.com')])
|
||||
allow(resolver).to receive(:getresources).with('email.com', Resolv::DNS::Resource::IN::A).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('email.com', Resolv::DNS::Resource::IN::AAAA).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('smtp.email.com', Resolv::DNS::Resource::IN::A).and_return([instance_double(Resolv::DNS::Resource::IN::A, address: '2.3.4.5')])
|
||||
allow(resolver).to receive(:getresources).with('smtp.email.com', Resolv::DNS::Resource::IN::AAAA).and_return([instance_double(Resolv::DNS::Resource::IN::AAAA, address: 'fd00::2')])
|
||||
.with('example.com', Resolv::DNS::Resource::IN::MX)
|
||||
.and_return([instance_double(Resolv::DNS::Resource::MX, exchange: 'smtp.example.com')])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::AAAA).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('smtp.example.com', Resolv::DNS::Resource::IN::A).and_return([instance_double(Resolv::DNS::Resource::IN::A, address: '2.3.4.5')])
|
||||
allow(resolver).to receive(:getresources).with('smtp.example.com', Resolv::DNS::Resource::IN::AAAA).and_return([instance_double(Resolv::DNS::Resource::IN::AAAA, address: 'fd00::2')])
|
||||
allow(Resolv::DNS).to receive(:open).and_yield(resolver)
|
||||
end
|
||||
|
||||
|
|
18
spec/validators/disposable_email_validator_spec.rb
Normal file
18
spec/validators/disposable_email_validator_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DisposableEmailValidator do
|
||||
describe '#validate' do
|
||||
it 'does not allow disposable email domains' do
|
||||
user = Fabricate.build(:user, email: 'user@1994gmail.com')
|
||||
expect(user).to_not be_valid
|
||||
expect(user.errors.first.type).to eq I18n.t('disposable_email_validator.invalid')
|
||||
end
|
||||
|
||||
it 'allows valid email domain' do
|
||||
user = Fabricate.build(:user, email: 'user@gmail.com')
|
||||
expect(user).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue