1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Compare commits

...

8 commits

Author SHA1 Message Date
Fawaz Farid
b57249a641
Merge 7060867bb2 into a50c8e951f 2024-07-31 14:07:08 +00:00
Claire
a50c8e951f
Fix issue with grouped notifications UI due to recent API change (#31224) 2024-07-31 13:23:08 +00:00
Claire
2c1e75727d
Change filtered notification banner design to take up less space (#31222) 2024-07-31 12:36:08 +00:00
Fawaz Farid
7060867bb2 Update tests 2024-04-17 17:48:18 +03:00
Fawaz Farid
c6047b2f1e update error message 2024-04-17 17:12:43 +03:00
Fawaz Farid
8d471cb3c3 Add disposable email validations 2024-04-17 16:43:23 +03:00
Fawaz Farid
597e957c22 Add latest list of disposable-email-domains 2024-04-17 16:33:35 +03:00
Fawaz Farid
0744e4afa3 Add rake task to download disposable email domains 2024-04-17 16:31:32 +03:00
14 changed files with 97 additions and 48 deletions

View file

@ -60,7 +60,7 @@ export interface BaseNotificationGroupJSON {
interface NotificationGroupWithStatusJSON extends BaseNotificationGroupJSON {
type: NotificationWithStatusType;
status: ApiStatusJSON;
status_id: string;
}
interface NotificationWithStatusJSON extends BaseNotificationJSON {

View file

@ -49,21 +49,14 @@ 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 }}
/>
{toCappedNumber(policy.summary.pending_notifications_count)}
</div>
</Link>
);

View file

@ -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",

View file

@ -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,
};

View file

@ -10171,25 +10171,10 @@ 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;
border-radius: 100px;
padding: 2px 8px;
}
background: $ui-button-background-color;
color: $white;
border-radius: 100px;
padding: 2px 8px;
}
}

View file

@ -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?

View 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

View file

@ -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

View file

@ -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

File diff suppressed because one or more lines are too long

View 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

View file

@ -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 }

View file

@ -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

View 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