Skip to content

Commit

Permalink
Merge remote-tracking branch 'parent/main' into upstream-20240408
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Apr 7, 2024
2 parents d694c85 + e73cf35 commit 45c5c7b
Show file tree
Hide file tree
Showing 27 changed files with 324 additions and 119 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,5 @@ gem 'net-http', '~> 0.4.0'
gem 'rubyzip', '~> 2.3'

gem 'hcaptcha', '~> 7.1'

gem 'mail', '~> 2.8'
9 changes: 5 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ GEM
rdoc
reline (>= 0.4.2)
jmespath (1.6.2)
json (2.7.1)
json (2.7.2)
json-canonicalization (1.0.0)
json-jwt (1.15.3.1)
activesupport (>= 4.2)
Expand Down Expand Up @@ -607,7 +607,7 @@ GEM
redlock (1.3.2)
redis (>= 3.0.0, < 6.0)
regexp_parser (2.9.0)
reline (0.4.3)
reline (0.5.0)
io-console (~> 0.5)
request_store (1.5.1)
rack (>= 1.4)
Expand Down Expand Up @@ -673,7 +673,7 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (2.28.0)
rubocop-rspec (2.29.1)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
Expand All @@ -694,7 +694,7 @@ GEM
sanitize (6.1.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
scenic (1.7.0)
scenic (1.8.0)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
selenium-webdriver (4.19.0)
Expand Down Expand Up @@ -882,6 +882,7 @@ DEPENDENCIES
letter_opener_web (~> 2.0)
link_header (~> 0.0)
lograge (~> 0.12)
mail (~> 2.8)
mario-redis-lock (~> 1.2)
md-paperclip-azure (~> 2.2)
memory_profiler
Expand Down
1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# Otherwise, you can access the site at http://localhost:3000 and http://localhost:4000 , http://localhost:8080
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.network :forwarded_port, guest: 3035, host: 3035
config.vm.network :forwarded_port, guest: 4000, host: 4000
config.vm.network :forwarded_port, guest: 8080, host: 8080
config.vm.network :forwarded_port, guest: 9200, host: 9200
Expand Down
12 changes: 0 additions & 12 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,6 @@ def body_classes
output.compact_blank.join(' ')
end

def theme_style_tags(theme)
if theme == 'system'
concat stylesheet_pack_tag('mastodon-light', media: 'not all and (prefers-color-scheme: dark)', crossorigin: 'anonymous')
concat stylesheet_pack_tag('default', media: '(prefers-color-scheme: dark)', crossorigin: 'anonymous')
concat tag.meta name: 'theme-color', content: Themes::MASTODON_DARK_THEME_COLOR, media: '(prefers-color-scheme: dark)'
concat tag.meta name: 'theme-color', content: Themes::MASTODON_LIGHT_THEME_COLOR, media: '(prefers-color-scheme: light)'
else
concat stylesheet_pack_tag theme, media: 'all', crossorigin: 'anonymous'
concat tag.meta name: 'theme-color', content: theme == 'mastodon-light' ? Themes::MASTODON_LIGHT_THEME_COLOR : Themes::MASTODON_DARK_THEME_COLOR
end
end

def cdn_host
Rails.configuration.action_controller.asset_host
end
Expand Down
27 changes: 27 additions & 0 deletions app/helpers/theme_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module ThemeHelper
def theme_style_tags(theme)
if theme == 'system'
concat stylesheet_pack_tag('mastodon-light', media: 'not all and (prefers-color-scheme: dark)', crossorigin: 'anonymous')
concat stylesheet_pack_tag('default', media: '(prefers-color-scheme: dark)', crossorigin: 'anonymous')
else
stylesheet_pack_tag theme, media: 'all', crossorigin: 'anonymous'
end
end

def theme_color_tags(theme)
if theme == 'system'
concat tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:dark], media: '(prefers-color-scheme: dark)')
concat tag.meta(name: 'theme-color', content: Themes::THEME_COLORS[:light], media: '(prefers-color-scheme: light)')
else
tag.meta name: 'theme-color', content: theme_color_for(theme)
end
end

private

def theme_color_for(theme)
theme == 'mastodon-light' ? Themes::THEME_COLORS[:light] : Themes::THEME_COLORS[:dark]
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import * as html from '../html';
describe('html', () => {
describe('unescapeHTML', () => {
it('returns unescaped HTML', () => {
const output = html.unescapeHTML('<p>lorem</p><p>ipsum</p><br>&lt;br&gt;');
const output = html.unescapeHTML(
'<p>lorem</p><p>ipsum</p><br>&lt;br&gt;',
);
expect(output).toEqual('lorem\n\nipsum\n<br>');
});
});
Expand Down
24 changes: 24 additions & 0 deletions app/javascript/mastodon/utils/__tests__/numbers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { DECIMAL_UNITS, toShortNumber } from '../numbers';

interface TableRow {
input: number;
base: number;
unit: number;
digits: number;
}

describe.each`
input | base | unit | digits
${10_000_000} | ${10} | ${DECIMAL_UNITS.MILLION} | ${0}
${2_789_123} | ${2.789123} | ${DECIMAL_UNITS.MILLION} | ${1}
${12_345_789} | ${12.345789} | ${DECIMAL_UNITS.MILLION} | ${0}
${10_000_000_000} | ${10} | ${DECIMAL_UNITS.BILLION} | ${0}
${12} | ${12} | ${DECIMAL_UNITS.ONE} | ${0}
${123} | ${123} | ${DECIMAL_UNITS.ONE} | ${0}
${1234} | ${1.234} | ${DECIMAL_UNITS.THOUSAND} | ${1}
${6666} | ${6.666} | ${DECIMAL_UNITS.THOUSAND} | ${1}
`('toShortNumber', ({ input, base, unit, digits }: TableRow) => {
test(`correctly formats ${input}`, () => {
expect(toShortNumber(input)).toEqual([base, unit, digits]);
});
});
6 changes: 4 additions & 2 deletions app/javascript/styles/mastodon/emoji_picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@
border: 0;
}

&:focus,
&:active {
&:active,
&:focus {
outline: none !important;
border-width: 1px !important;
border-color: $ui-button-background-color;
}

&::-webkit-search-cancel-button {
Expand Down
4 changes: 2 additions & 2 deletions app/lib/admin/metrics/measure/tag_servers_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def sql_query_string
end

def earliest_status_id
Mastodon::Snowflake.id_at(@start_at, with_random: false)
Mastodon::Snowflake.id_at(@start_at.beginning_of_day, with_random: false)
end

def latest_status_id
Mastodon::Snowflake.id_at(@end_at, with_random: false)
Mastodon::Snowflake.id_at(@end_at.end_of_day, with_random: false)
end

def tag
Expand Down
2 changes: 1 addition & 1 deletion app/lib/annual_report/top_statuses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def generate
end

def base_scope
@account.statuses.with_public_visibility.joins(:status_stat).where(id: year_as_snowflake_range).reorder(nil)
@account.statuses.public_visibility.joins(:status_stat).where(id: year_as_snowflake_range).reorder(nil)
end
end
6 changes: 4 additions & 2 deletions app/lib/themes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
class Themes
include Singleton

MASTODON_DARK_THEME_COLOR = '#191b22'
MASTODON_LIGHT_THEME_COLOR = '#f3f5f7'
THEME_COLORS = {
dark: '#191b22',
light: '#f3f5f7',
}.freeze

def initialize
@conf = YAML.load_file(Rails.root.join('config', 'themes.yml'))
Expand Down
17 changes: 17 additions & 0 deletions app/models/concerns/custom_filter_cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module CustomFilterCache
extend ActiveSupport::Concern

included do
after_commit :invalidate_cache!
before_destroy :prepare_cache_invalidation!
before_save :prepare_cache_invalidation!

delegate(
:invalidate_cache!,
:prepare_cache_invalidation!,
to: :custom_filter
)
end
end
14 changes: 2 additions & 12 deletions app/models/custom_filter_keyword.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
#

class CustomFilterKeyword < ApplicationRecord
include CustomFilterCache

belongs_to :custom_filter

validates :keyword, presence: true

alias_attribute :phrase, :keyword

before_save :prepare_cache_invalidation!
before_destroy :prepare_cache_invalidation!
after_commit :invalidate_cache!

def to_regex
if whole_word?
/(?mix:#{to_regex_sb}#{Regexp.escape(keyword)}#{to_regex_eb})/
Expand All @@ -40,12 +38,4 @@ def to_regex_sb
def to_regex_eb
/[[:word:]]\z/.match?(keyword) ? '\b' : ''
end

def prepare_cache_invalidation!
custom_filter.prepare_cache_invalidation!
end

def invalidate_cache!
custom_filter.invalidate_cache!
end
end
14 changes: 2 additions & 12 deletions app/models/custom_filter_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,17 @@
#

class CustomFilterStatus < ApplicationRecord
include CustomFilterCache

belongs_to :custom_filter
belongs_to :status

validates :status, uniqueness: { scope: :custom_filter }
validate :validate_status_access

before_save :prepare_cache_invalidation!
before_destroy :prepare_cache_invalidation!
after_commit :invalidate_cache!

private

def validate_status_access
errors.add(:status_id, :invalid) unless StatusPolicy.new(custom_filter.account, status).show?
end

def prepare_cache_invalidation!
custom_filter.prepare_cache_invalidation!
end

def invalidate_cache!
custom_filter.invalidate_cache!
end
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ 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_with BlacklistedEmailValidator, if: -> { ENV['EMAIL_DOMAIN_LISTS_APPLY_AFTER_CONFIRMATION'] == 'true' || !confirmed? }
validates_with EmailMxValidator, if: :validate_email_dns?
validates :agreement, acceptance: { allow_nil: false, accept: [true, 'true', '1'] }, on: :create
Expand Down
18 changes: 18 additions & 0 deletions app/validators/email_address_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# NOTE: I initially wrote this as `EmailValidator` but it ended up clashing
# with an indirect dependency of ours, `validate_email`, which, turns out,
# has the same approach as we do, but with an extra check disallowing
# single-label domains. Decided to not switch to `validate_email` because
# we do want to allow at least `localhost`.

class EmailAddressValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
value = value.strip

address = Mail::Address.new(value)
record.errors.add(attribute, :invalid) if address.address != value
rescue Mail::Field::FieldError
record.errors.add(attribute, :invalid)
end
end
4 changes: 2 additions & 2 deletions app/views/application/mailer/_feature.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%table.email-w-full{ cellspacing: 0, cellpadding: 0, border: 0, role: 'presentation' }
%tr
%td.email-feature-td
.email-desktop-flex{ class: ('email-dir-rtl' if defined?(text_first_on_desktop) && !text_first_on_desktop) }
.email-desktop-flex{ class: ('email-dir-rtl' if feature_iteration.index.odd?) }
/[if mso]
<table border="0" cellpadding="0" cellspacing="0" align="center" style="width:100%;" role="presentation"><tr><td style="width:50%; vertical-align:top;">
.email-desktop-column
Expand All @@ -24,7 +24,7 @@
%tr
%td.email-column-td
- if defined?(feature)
%p{ class: ('email-desktop-text-right' if defined?(text_first_on_desktop) && text_first_on_desktop) }
%p{ class: ('email-desktop-text-right' if feature_iteration.index.even?) }
= image_tag frontend_asset_url("images/mailer-new/welcome/feature_#{feature}.png"), alt: '', width: 240, height: 230
/[if mso]
</td></tr></table>
2 changes: 1 addition & 1 deletion app/views/application/mailer/_hashtag.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- accounts = hashtag.statuses.with_public_visibility.joins(:account).merge(Account.without_suspended.without_silenced).includes(:account).limit(3).map(&:account)
- accounts = hashtag.statuses.public_visibility.joins(:account).merge(Account.without_suspended.without_silenced).includes(:account).limit(3).map(&:account)

%table.email-w-full{ cellspacing: 0, cellpadding: 0, border: 0, role: 'presentation' }
%tr
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

%link{ rel: 'mask-icon', href: frontend_asset_path('images/logo-symbol-icon.svg'), color: '#6364FF' }/
%link{ rel: 'manifest', href: manifest_path(format: :json) }/
= theme_color_tags current_theme
%meta{ name: 'apple-mobile-web-app-capable', content: 'yes' }/

%title= html_title
Expand Down
5 changes: 1 addition & 4 deletions app/views/user_mailer/welcome.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,4 @@
%table.email-w-full{ cellspacing: 0, cellpadding: 0, border: 0, role: 'presentation' }
%tr
%td.email-extra-td
= render 'application/mailer/feature', feature: 'control', text_first_on_desktop: true
= render 'application/mailer/feature', feature: 'audience', text_first_on_desktop: false
= render 'application/mailer/feature', feature: 'moderation', text_first_on_desktop: true
= render 'application/mailer/feature', feature: 'creativity', text_first_on_desktop: false
= render partial: 'application/mailer/feature', collection: %w(control audience moderation creativity)
Loading

0 comments on commit 45c5c7b

Please sign in to comment.