Skip to content

Commit

Permalink
Merge pull request #2742 from ClearlyClaire/glitch-soc/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream changes up to d818ddd
  • Loading branch information
ClearlyClaire authored Jun 17, 2024
2 parents 6922536 + f214813 commit 68c9fa8
Show file tree
Hide file tree
Showing 35 changed files with 153 additions and 78 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/test-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ jobs:
env:
RAILS_ENV: ${{ matrix.mode }}
BUNDLE_WITH: ${{ matrix.mode }}
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY: precompile_placeholder
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT: precompile_placeholder
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY: precompile_placeholder
OTP_SECRET: precompile_placeholder
SECRET_KEY_BASE: precompile_placeholder
SECRET_KEY_BASE_DUMMY: 1

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 1 addition & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,7 @@ ARG TARGETPLATFORM

RUN \
# Use Ruby on Rails to create Mastodon assets
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=precompile_placeholder \
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=precompile_placeholder \
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=precompile_placeholder \
OTP_SECRET=precompile_placeholder \
SECRET_KEY_BASE=precompile_placeholder \
SECRET_KEY_BASE_DUMMY=1 \
bundle exec rails assets:precompile; \
# Cleanup temporary files
rm -fr /opt/mastodon/tmp;
Expand Down
9 changes: 7 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ GEM
aws-sdk-kms (1.83.0)
aws-sdk-core (~> 3, >= 3.197.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.152.0)
aws-sdk-s3 (1.152.1)
aws-sdk-core (~> 3, >= 3.197.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.8)
Expand Down Expand Up @@ -498,6 +498,10 @@ GEM
opentelemetry-semantic_conventions
opentelemetry-helpers-sql-obfuscation (0.1.0)
opentelemetry-common (~> 0.20)
opentelemetry-instrumentation-action_mailer (0.1.0)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-active_support (~> 0.1)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-action_pack (0.9.0)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
Expand Down Expand Up @@ -551,8 +555,9 @@ GEM
opentelemetry-api (~> 1.0)
opentelemetry-common (~> 0.20.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-rails (0.30.1)
opentelemetry-instrumentation-rails (0.30.2)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-action_mailer (~> 0.1.0)
opentelemetry-instrumentation-action_pack (~> 0.9.0)
opentelemetry-instrumentation-action_view (~> 0.7.0)
opentelemetry-instrumentation-active_job (~> 0.7.0)
Expand Down
22 changes: 20 additions & 2 deletions app/controllers/admin/domain_blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ module Admin
class DomainBlocksController < BaseController
before_action :set_domain_block, only: [:destroy, :edit, :update]

PERMITTED_PARAMS = %i(
domain
obfuscate
private_comment
public_comment
reject_media
reject_reports
severity
).freeze

PERMITTED_UPDATE_PARAMS = PERMITTED_PARAMS.without(:domain).freeze

def batch
authorize :domain_block, :create?
@form = Form::DomainBlockBatch.new(form_domain_block_batch_params.merge(current_account: current_account, action: action_from_button))
Expand Down Expand Up @@ -88,11 +100,17 @@ def set_domain_block
end

def update_params
params.require(:domain_block).permit(:severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
params
.require(:domain_block)
.slice(*PERMITTED_UPDATE_PARAMS)
.permit(*PERMITTED_UPDATE_PARAMS)
end

def resource_params
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
params
.require(:domain_block)
.slice(*PERMITTED_PARAMS)
.permit(*PERMITTED_PARAMS)
end

def form_domain_block_batch_params
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/api/v1/admin/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class Api::V1::Admin::TagsController < Api::BaseController

LIMIT = 100

PERMITTED_PARAMS = %i(
display_name
listable
trendable
usable
).freeze

def index
authorize :tag, :index?
render json: @tags, each_serializer: REST::Admin::TagSerializer
Expand Down Expand Up @@ -40,7 +47,9 @@ def set_tags
end

def tag_params
params.permit(:display_name, :trendable, :usable, :listable)
params
.slice(*PERMITTED_PARAMS)
.permit(*PERMITTED_PARAMS)
end

def next_path
Expand Down
13 changes: 13 additions & 0 deletions app/javascript/mastodon/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@
"domain_pill.their_username": "مُعرّفُهم الفريد على الخادم. من الممكن العثور على مستخدمين بنفس اسم المستخدم على خوادم مختلفة.",
"domain_pill.username": "اسم المستخدم",
"domain_pill.whats_in_a_handle": "ما المقصود بالمُعرِّف؟",
"domain_pill.who_they_are": "بما أن المعالجات تقول من هو الشخص ومكان وجوده، يمكنك التفاعل مع الناس عبر الشبكة الاجتماعية لـ <button>ActivityPub-Power منصات</button>.",
"domain_pill.who_you_are": "لأن معالجتك تقول من أنت ومكان وجودك، يمكن الناس التفاعل معك عبر الشبكة الاجتماعية لـ <button>ActivityPub-Power منصات</button>.",
"domain_pill.your_handle": "عنوانك الكامل:",
"domain_pill.your_server": "منزلك الرقمي، حيث تعيش جميع مشاركاتك. لا تحب هذا؟ إنقل الخوادم في أي وقت واخضر متابعينك أيضًا.",
"domain_pill.your_username": "معرفك الفريد على هذا الخادم. من الممكن العثور على مستخدمين بنفس إسم المستخدم على خوادم مختلفة.",
"embed.instructions": "يمكنكم إدماج هذا المنشور على موقعكم الإلكتروني عن طريق نسخ الشفرة أدناه.",
"embed.preview": "إليك ما سيبدو عليه:",
"emoji_button.activity": "الأنشطة",
Expand Down Expand Up @@ -262,6 +266,7 @@
"empty_column.list": "هذه القائمة فارغة مؤقتا و لكن سوف تمتلئ تدريجيا عندما يبدأ الأعضاء المُنتَمين إليها بنشر منشورات.",
"empty_column.lists": "ليس عندك أية قائمة بعد. سوف تظهر قوائمك هنا إن قمت بإنشاء واحدة.",
"empty_column.mutes": "لم تقم بكتم أي مستخدم بعد.",
"empty_column.notification_requests": "لا يوجد شيء هنا. عندما تتلقى إشعارات جديدة، سوف تظهر هنا وفقًا لإعداداتك.",
"empty_column.notifications": "لم تتلق أي إشعار بعدُ. تفاعل مع المستخدمين الآخرين لإنشاء محادثة.",
"empty_column.public": "لا يوجد أي شيء هنا! قم بنشر شيء ما للعامة، أو اتبع المستخدمين الآخرين المتواجدين على الخوادم الأخرى لملء خيط المحادثات",
"error.unexpected_crash.explanation": "نظرا لوجود خطأ في التعليمات البرمجية أو مشكلة توافق مع المتصفّح، تعذر عرض هذه الصفحة بشكل صحيح.",
Expand Down Expand Up @@ -292,6 +297,8 @@
"filter_modal.select_filter.subtitle": "استخدم فئة موجودة أو قم بإنشاء فئة جديدة",
"filter_modal.select_filter.title": "تصفية هذا المنشور",
"filter_modal.title.status": "تصفية منشور",
"filtered_notifications_banner.mentions": "{count, plural, one {إشارة} two {إشارتين} few {# إشارات} other {# إشارة}}",
"filtered_notifications_banner.pending_requests": "إشعارات من {count, plural, zero {}=0 {لا أحد} one {شخص واحد قد تعرفه} two {شخصين قد تعرفهما} few {# أشخاص قد تعرفهم} many {# شخص قد تعرفهم} other {# شخص قد تعرفهم}}",
"filtered_notifications_banner.title": "الإشعارات المصفاة",
"firehose.all": "الكل",
"firehose.local": "هذا الخادم",
Expand All @@ -301,6 +308,8 @@
"follow_requests.unlocked_explanation": "حتى وإن كان حسابك غير مقفل، يعتقد فريق {domain} أنك قد ترغب في مراجعة طلبات المتابعة من هذه الحسابات يدوياً.",
"follow_suggestions.curated_suggestion": "اختيار الموظفين",
"follow_suggestions.dismiss": "لا تُظهرها مجدّدًا",
"follow_suggestions.featured_longer": "مختار يدوياً من قِبل فريق {domain}",
"follow_suggestions.friends_of_friends_longer": "مشهور بين الأشخاص الذين تتابعهم",
"follow_suggestions.hints.featured": "تم اختيار هذا الملف الشخصي يدوياً من قبل فريق {domain}.",
"follow_suggestions.hints.friends_of_friends": "هذا الملف الشخصي مشهور بين الأشخاص الذين تتابعهم.",
"follow_suggestions.hints.most_followed": "هذا الملف الشخصي هو واحد من الأكثر متابعة على {domain}.",
Expand Down Expand Up @@ -405,6 +414,7 @@
"limited_account_hint.action": "إظهار الملف التعريفي على أي حال",
"limited_account_hint.title": "تم إخفاء هذا الملف الشخصي من قبل مشرفي {domain}.",
"link_preview.author": "مِن {name}",
"link_preview.more_from_author": "المزيد من {name}",
"lists.account.add": "أضف إلى القائمة",
"lists.account.remove": "احذف من القائمة",
"lists.delete": "احذف القائمة",
Expand Down Expand Up @@ -465,10 +475,13 @@
"notification.follow_request": "لقد طلب {name} متابعتك",
"notification.mention": "{name} ذكرك",
"notification.moderation-warning.learn_more": "اعرف المزيد",
"notification.moderation_warning": "لقد تلقيت تحذيرًا بالإشراف",
"notification.moderation_warning.action_delete_statuses": "تم إزالة بعض مشاركاتك.",
"notification.moderation_warning.action_disable": "تم تعطيل حسابك.",
"notification.moderation_warning.action_mark_statuses_as_sensitive": "بعض من منشوراتك تم تصنيفها على أنها حساسة.",
"notification.moderation_warning.action_none": "لقد تلقى حسابك تحذيرا بالإشراف.",
"notification.moderation_warning.action_sensitive": "سيتم وضع علامة على منشوراتك على أنها حساسة من الآن فصاعدا.",
"notification.moderation_warning.action_silence": "لقد تم تقييد حسابك.",
"notification.moderation_warning.action_suspend": "لقد تم تعليق حسابك.",
"notification.own_poll": "انتهى استطلاعك للرأي",
"notification.poll": "لقد انتهى استطلاع رأي شاركتَ فيه",
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/styles/mastodon/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,10 @@ code {
font-family: inherit;
pointer-events: none;
cursor: default;
max-width: 140px;
max-width: 50%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

&::after {
content: '';
Expand Down
10 changes: 10 additions & 0 deletions app/lib/access_grant_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module AccessGrantExtension
extend ActiveSupport::Concern

included do
scope :expired, -> { where.not(expires_in: nil).where('created_at + MAKE_INTERVAL(secs => expires_in) < NOW()') }
scope :revoked, -> { where.not(revoked_at: nil).where(revoked_at: ...Time.now.utc) }
end
end
4 changes: 4 additions & 0 deletions app/lib/access_token_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module AccessTokenExtension
has_many :web_push_subscriptions, class_name: 'Web::PushSubscription', inverse_of: :access_token

after_commit :push_to_streaming_api

scope :expired, -> { where.not(expires_in: nil).where('created_at + MAKE_INTERVAL(secs => expires_in) < NOW()') }
scope :not_revoked, -> { where(revoked_at: nil) }
scope :revoked, -> { where.not(revoked_at: nil).where(revoked_at: ...Time.now.utc) }
end

def revoke(clock = Time)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/metrics/measure/instance_accounts_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def sql_query_string
SELECT count(*) FROM new_accounts
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) AS axis
SQL
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def sql_query_string
SELECT count(*) FROM new_followers
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) AS axis
SQL
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/metrics/measure/instance_follows_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def sql_query_string
SELECT count(*) FROM new_follows
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) AS axis
SQL
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def sql_query_string
SELECT COALESCE(SUM(size), 0) FROM new_media_attachments
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) AS axis
SQL
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/metrics/measure/instance_reports_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def sql_query_string
SELECT count(*) FROM new_reports
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) AS axis
SQL
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/metrics/measure/instance_statuses_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def sql_query_string
SELECT count(*) FROM new_statuses
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) AS axis
SQL
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/metrics/measure/new_users_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def sql_query_string
SELECT count(*) FROM new_users
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) AS axis
SQL
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/metrics/measure/opened_reports_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def sql_query_string
SELECT count(*) FROM new_reports
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) AS axis
SQL
end
Expand Down
8 changes: 8 additions & 0 deletions app/lib/admin/metrics/measure/query_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ def sanitized_sql_string
ActiveRecord::Base.sanitize_sql_array(sql_array)
end

def generated_series_days
Arel.sql(
<<~SQL.squish
SELECT generate_series(timestamp :start_at, :end_at, '1 day')::date AS period
SQL
)
end

def account_domain_sql(include_subdomains)
if include_subdomains
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))"
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/metrics/measure/resolved_reports_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def sql_query_string
SELECT count(*) FROM resolved_reports
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) AS axis
SQL
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/admin/metrics/measure/tag_servers_measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def sql_query_string
SELECT COUNT(*) FROM tag_servers
) AS value
FROM (
SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period
#{generated_series_days}
) as axis
SQL
end
Expand Down
8 changes: 4 additions & 4 deletions app/lib/vacuum/access_tokens_vacuum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def perform
private

def vacuum_revoked_access_tokens!
Doorkeeper::AccessToken.where.not(expires_in: nil).where('created_at + make_interval(secs => expires_in) < NOW()').in_batches.delete_all
Doorkeeper::AccessToken.where.not(revoked_at: nil).where('revoked_at < NOW()').in_batches.delete_all
Doorkeeper::AccessToken.expired.in_batches.delete_all
Doorkeeper::AccessToken.revoked.in_batches.delete_all
end

def vacuum_revoked_access_grants!
Doorkeeper::AccessGrant.where.not(expires_in: nil).where('created_at + make_interval(secs => expires_in) < NOW()').in_batches.delete_all
Doorkeeper::AccessGrant.where.not(revoked_at: nil).where('revoked_at < NOW()').in_batches.delete_all
Doorkeeper::AccessGrant.expired.in_batches.delete_all
Doorkeeper::AccessGrant.revoked.in_batches.delete_all
end
end
2 changes: 1 addition & 1 deletion app/models/web/push_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def associated_access_token

class << self
def unsubscribe_for(application_id, resource_owner)
access_token_ids = Doorkeeper::AccessToken.where(application_id: application_id, resource_owner_id: resource_owner.id, revoked_at: nil).pluck(:id)
access_token_ids = Doorkeeper::AccessToken.where(application_id: application_id, resource_owner_id: resource_owner.id).not_revoked.pluck(:id)
where(access_token_id: access_token_ids).delete_all
end
end
Expand Down
4 changes: 3 additions & 1 deletion app/models/webauthn_credential.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#

class WebauthnCredential < ApplicationRecord
SIGN_COUNT_LIMIT = (2**63)

validates :external_id, :public_key, :nickname, :sign_count, presence: true
validates :external_id, uniqueness: true
validates :nickname, uniqueness: { scope: :user_id }
validates :sign_count,
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: (2**63) - 1 }
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: SIGN_COUNT_LIMIT - 1 }
end
4 changes: 4 additions & 0 deletions app/views/redirects/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- content_for :header_tags do
%meta{ name: 'robots', content: 'noindex, noarchive' }/
%link{ rel: 'canonical', href: @redirect_path }

.redirect
.redirect__logo
= link_to render_logo, root_path
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Application < Rails::Application
Doorkeeper::AuthorizationsController.layout 'modal'
Doorkeeper::AuthorizedApplicationsController.layout 'admin'
Doorkeeper::Application.include ApplicationExtension
Doorkeeper::AccessGrant.include AccessGrantExtension
Doorkeeper::AccessToken.include AccessTokenExtension
Devise::FailureApp.include AbstractController::Callbacks
Devise::FailureApp.include Localized
Expand Down
6 changes: 5 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@
}

# TODO: Remove once devise-two-factor data migration complete
config.x.otp_secret = ENV.fetch('OTP_SECRET')
config.x.otp_secret = if ENV['SECRET_KEY_BASE_DUMMY']
SecureRandom.hex(64)
else
ENV.fetch('OTP_SECRET')
end

# Enable DNS rebinding protection and other `Host` header attacks.
# config.hosts = [
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/active_record_encryption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY
).each do |key|
if ENV['SECRET_KEY_BASE_DUMMY']
# Use placeholder value during production env asset compilation
ENV[key] = SecureRandom.hex(64)
end

value = ENV.fetch(key) do
abort <<~MESSAGE
Expand Down
Loading

0 comments on commit 68c9fa8

Please sign in to comment.