Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream changes up to d8c428472356abd70aaf1f514b99114464ee7f61 #2704

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2f73e48
Switched HTMLEntities to the expanded flavor which supports a larger …
timothyjrogers May 5, 2024
e4841ca
Update dependency irb to v1.13.1 (#30177)
renovate[bot] May 6, 2024
d544b83
Update formatjs monorepo (#30175)
renovate[bot] May 6, 2024
a96b828
Update dependency postcss-preset-env to v9.5.11 (#30171)
renovate[bot] May 6, 2024
9be2c02
New Crowdin Translations (automated) (#30169)
github-actions[bot] May 6, 2024
86f17e4
Update devDependencies (non-major) (#30185)
renovate[bot] May 6, 2024
00c3407
Update eslint (non-major) (#30186)
renovate[bot] May 6, 2024
4f0d181
Update DefinitelyTyped types (non-major) (#30184)
renovate[bot] May 6, 2024
e5062b7
Fix post deletion not being deferred when those are part of an accoun…
ClearlyClaire May 6, 2024
dbaa4ed
Use `chewy` which relaxes ES version reqs (#30157)
mjankowski May 6, 2024
8e4fea7
Fix race condition in `POST /api/v1/push/subscription` (#30166)
ClearlyClaire May 6, 2024
30ef9fc
Fix hashtag matching pattern matching some link anchors (#30190)
ClearlyClaire May 6, 2024
116f01e
Implement RFC 8414 for OAuth 2.0 server metadata (#29191)
ThisIsMissEm May 6, 2024
05126d1
Redirect back after site upload deletion (#30141)
FawazFarid May 6, 2024
b152f93
Migrate paperclip `_file_size` columns to bigint (#29263)
mjankowski May 6, 2024
bc24c47
Allow admins to configure instance favicon and logo (#30040)
FawazFarid May 6, 2024
2fe1b8d
Add API to get multiple accounts and statuses (#27871)
ClearlyClaire May 6, 2024
016d194
Merge commit '2fe1b8d1695d8faa452a69872fde94ccc4611576' into glitch-s…
ClearlyClaire May 6, 2024
6167894
Update dependency pino-http to v10 (#30191)
renovate[bot] May 6, 2024
996292c
Fix `db:encryption:init` requiring ActiveRecord encryption variables …
ClearlyClaire May 7, 2024
96fb6e4
Revert "Migrate paperclip `_file_size` columns to bigint (#29263)" (#…
ClearlyClaire May 7, 2024
ed556db
New Crowdin Translations (automated) (#30201)
github-actions[bot] May 7, 2024
8540004
Update dependency dotenv to v3.1.2 (#30197)
renovate[bot] May 7, 2024
5cd13ee
Update dependency aws-sdk-s3 to v1.149.1 (#30196)
renovate[bot] May 7, 2024
f7dadc9
Merge commit '5cd13ee4f19c112ea855063c2495e2874746f23a' into glitch-s…
ClearlyClaire May 7, 2024
c9ccba7
Update dependency sass to v1.77.0 (#30200)
renovate[bot] May 7, 2024
d8c4284
Ensure custom favicon is converted to PNG and ICO (#30208)
ClearlyClaire May 7, 2024
21c904b
Merge commit 'd8c428472356abd70aaf1f514b99114464ee7f61' into glitch-s…
ClearlyClaire May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ GEM
awrence (1.2.1)
aws-eventstream (1.3.0)
aws-partitions (1.922.0)
aws-sdk-core (3.194.0)
aws-sdk-core (3.194.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.8)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.80.0)
aws-sdk-core (~> 3, >= 3.193.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.149.0)
aws-sdk-s3 (1.149.1)
aws-sdk-core (~> 3, >= 3.194.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.8)
Expand Down Expand Up @@ -167,9 +167,9 @@ GEM
activesupport
cbor (0.5.9.8)
charlock_holmes (0.7.7)
chewy (7.5.1)
chewy (7.6.0)
activesupport (>= 5.2)
elasticsearch (>= 7.12.0, < 7.14.0)
elasticsearch (>= 7.14.0, < 8)
elasticsearch-dsl
chunky_png (1.4.0)
climate_control (1.2.0)
Expand Down Expand Up @@ -217,17 +217,17 @@ GEM
domain_name (0.6.20240107)
doorkeeper (5.6.9)
railties (>= 5)
dotenv (3.1.1)
dotenv (3.1.2)
drb (2.2.1)
ed25519 (1.3.0)
elasticsearch (7.13.3)
elasticsearch-api (= 7.13.3)
elasticsearch-transport (= 7.13.3)
elasticsearch-api (7.13.3)
elasticsearch (7.17.10)
elasticsearch-api (= 7.17.10)
elasticsearch-transport (= 7.17.10)
elasticsearch-api (7.17.10)
multi_json
elasticsearch-dsl (0.1.10)
elasticsearch-transport (7.13.3)
faraday (~> 1)
elasticsearch-transport (7.17.10)
faraday (>= 1, < 3)
multi_json
email_spec (2.2.2)
htmlentities (~> 4.3.3)
Expand Down Expand Up @@ -346,7 +346,7 @@ GEM
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.7.2)
irb (1.13.0)
irb (1.13.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jmespath (1.6.2)
Expand Down Expand Up @@ -601,7 +601,7 @@ GEM
redlock (1.3.2)
redis (>= 3.0.0, < 6.0)
regexp_parser (2.9.0)
reline (0.5.4)
reline (0.5.5)
io-console (~> 0.5)
request_store (1.6.0)
rack (>= 1.4)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/site_uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def destroy

@site_upload.destroy!

redirect_to admin_settings_path, notice: I18n.t('admin.site_uploads.destroyed_msg')
redirect_back fallback_location: admin_settings_path, notice: I18n.t('admin.site_uploads.destroyed_msg')
end

private
Expand Down
30 changes: 26 additions & 4 deletions app/controllers/api/v1/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ class Api::V1::AccountsController < Api::BaseController
before_action -> { doorkeeper_authorize! :follow, :write, :'write:blocks' }, only: [:block, :unblock]
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: [:create]

before_action :require_user!, except: [:show, :create]
before_action :set_account, except: [:create]
before_action :check_account_approval, except: [:create]
before_action :check_account_confirmation, except: [:create]
before_action :require_user!, except: [:index, :show, :create]
before_action :set_account, except: [:index, :create]
before_action :set_accounts, only: [:index]
before_action :check_account_approval, except: [:index, :create]
before_action :check_account_confirmation, except: [:index, :create]
before_action :check_enabled_registrations, only: [:create]
before_action :check_accounts_limit, only: [:index]

skip_before_action :require_authenticated_user!, only: :create

override_rate_limit_headers :follow, family: :follows

def index
render json: @accounts, each_serializer: REST::AccountSerializer
end

def show
cache_if_unauthenticated!
render json: @account, serializer: REST::AccountSerializer
Expand Down Expand Up @@ -79,6 +85,10 @@ def set_account
@account = Account.find(params[:id])
end

def set_accounts
@accounts = Account.where(id: account_ids).without_unapproved
end

def check_account_approval
raise(ActiveRecord::RecordNotFound) if @account.local? && @account.user_pending?
end
Expand All @@ -87,10 +97,22 @@ def check_account_confirmation
raise(ActiveRecord::RecordNotFound) if @account.local? && !@account.user_confirmed?
end

def check_accounts_limit
raise(Mastodon::ValidationError) if account_ids.size > DEFAULT_ACCOUNTS_LIMIT
end

def relationships(**options)
AccountRelationshipsPresenter.new([@account], current_user.account_id, **options)
end

def account_ids
Array(accounts_params[:ids]).uniq.map(&:to_i)
end

def accounts_params
params.permit(ids: [])
end

def account_params
params.permit(:username, :email, :password, :agreement, :locale, :reason, :time_zone, :invite_code)
end
Expand Down
33 changes: 21 additions & 12 deletions app/controllers/api/v1/push/subscriptions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
# frozen_string_literal: true

class Api::V1::Push::SubscriptionsController < Api::BaseController
include Redisable
include Lockable

before_action -> { doorkeeper_authorize! :push }
before_action :require_user!
before_action :set_push_subscription
before_action :set_push_subscription, only: [:show, :update]
before_action :check_push_subscription, only: [:show, :update]

def show
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
end

def create
@push_subscription&.destroy!
with_redis_lock("push_subscription:#{current_user.id}") do
destroy_web_push_subscriptions!

@push_subscription = Web::PushSubscription.create!(
endpoint: subscription_params[:endpoint],
key_p256dh: subscription_params[:keys][:p256dh],
key_auth: subscription_params[:keys][:auth],
data: data_params,
user_id: current_user.id,
access_token_id: doorkeeper_token.id
)
@push_subscription = Web::PushSubscription.create!(
endpoint: subscription_params[:endpoint],
key_p256dh: subscription_params[:keys][:p256dh],
key_auth: subscription_params[:keys][:auth],
data: data_params,
user_id: current_user.id,
access_token_id: doorkeeper_token.id
)
end

render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
end
Expand All @@ -31,14 +36,18 @@ def update
end

def destroy
@push_subscription&.destroy!
destroy_web_push_subscriptions!
render_empty
end

private

def destroy_web_push_subscriptions!
doorkeeper_token.web_push_subscriptions.destroy_all
end

def set_push_subscription
@push_subscription = Web::PushSubscription.find_by(access_token_id: doorkeeper_token.id)
@push_subscription = doorkeeper_token.web_push_subscriptions.first
end

def check_push_subscription
Expand Down
29 changes: 26 additions & 3 deletions app/controllers/api/v1/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ class Api::V1::StatusesController < Api::BaseController

before_action -> { authorize_if_got_token! :read, :'read:statuses' }, except: [:create, :update, :destroy]
before_action -> { doorkeeper_authorize! :write, :'write:statuses' }, only: [:create, :update, :destroy]
before_action :require_user!, except: [:show, :context]
before_action :set_status, only: [:show, :context]
before_action :set_thread, only: [:create]
before_action :require_user!, except: [:index, :show, :context]
before_action :set_statuses, only: [:index]
before_action :set_status, only: [:show, :context]
before_action :set_thread, only: [:create]
before_action :check_statuses_limit, only: [:index]

override_rate_limit_headers :create, family: :statuses
override_rate_limit_headers :update, family: :statuses
Expand All @@ -23,6 +25,11 @@ class Api::V1::StatusesController < Api::BaseController
DESCENDANTS_LIMIT = 60
DESCENDANTS_DEPTH_LIMIT = 20

def index
@statuses = cache_collection(@statuses, Status)
render json: @statuses, each_serializer: REST::StatusSerializer
end

def show
cache_if_unauthenticated!
@status = cache_collection([@status], Status).first
Expand Down Expand Up @@ -113,6 +120,10 @@ def destroy

private

def set_statuses
@statuses = Status.permitted_statuses_from_ids(status_ids, current_account)
end

def set_status
@status = Status.find(params[:id])
authorize @status, :show?
Expand All @@ -127,6 +138,18 @@ def set_thread
render json: { error: I18n.t('statuses.errors.in_reply_not_found') }, status: 404
end

def check_statuses_limit
raise(Mastodon::ValidationError) if status_ids.size > DEFAULT_STATUSES_LIMIT
end

def status_ids
Array(statuses_params[:ids]).uniq.map(&:to_i)
end

def statuses_params
params.permit(ids: [])
end

def status_params
params.permit(
:status,
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/well_known/oauth_metadata_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module WellKnown
class OauthMetadataController < ActionController::Base # rubocop:disable Rails/ApplicationController
include CacheConcern

# Prevent `active_model_serializer`'s `ActionController::Serialization` from calling `current_user`
# and thus re-issuing session cookies
serialization_scope nil

def show
# Due to this document potentially changing between Mastodon versions (as
# new OAuth scopes are added), we don't use expires_in to cache upstream,
# instead just caching in the rails cache:
render_with_cache(
json: ::OauthMetadataPresenter.new,
serializer: ::OauthMetadataSerializer,
content_type: 'application/json',
expires_in: 15.minutes
)
end
end
end
7 changes: 7 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ def prerender_custom_emojis(html, custom_emojis, other_options = {})
EmojiFormatter.new(html, custom_emojis, other_options.merge(animate: prefers_autoplay?)).to_s
end

def site_icon_path(type, size = '48')
icon = SiteUpload.find_by(var: type)
return nil unless icon

icon.file.url(size)
end

# glitch-soc addition to handle the multiple flavors
def preload_locale_pack
supported_locales = Themes.instance.flavour(current_flavour)['locales']
Expand Down
Loading