1
0
mirror of https://github.com/mastodon/mastodon synced 2024-12-12 21:58:20 +09:00

Add support for numeric-based URIs for local accounts

This commit is contained in:
Claire 2024-10-31 16:54:41 +01:00
parent 0a1b5df202
commit c4179b333f
4 changed files with 40 additions and 1 deletions

View File

@ -71,6 +71,10 @@ class AccountsController < ApplicationController
params[:username] params[:username]
end end
def account_id_param
params[:id]
end
def skip_temporary_suspension_response? def skip_temporary_suspension_response?
request.format == :json request.format == :json
end end

View File

@ -18,7 +18,11 @@ module AccountOwnedConcern
end end
def set_account def set_account
@account = Account.find_local!(username_param) @account = username_param.present? ? Account.find_local!(username_param) : Account.local.find(account_id_param)
end
def account_id_param
params[:numeric_account_id]
end end
def username_param def username_param

View File

@ -148,6 +148,29 @@ Rails.application.routes.draw do
end end
end end
resources :accounts, path: 'u', only: [:show], param: :id, as: :numeric_account do
resources :statuses, only: [:show] do
member do
get :activity
get :embed
end
resources :replies, only: [:index], module: :activitypub
resources :likes, only: [:index], module: :activitypub
resources :shares, only: [:index], module: :activitypub
end
resources :followers, only: [:index], controller: :follower_accounts
resources :following, only: [:index], controller: :following_accounts
scope module: :activitypub do
resource :outbox, only: [:show]
resource :inbox, only: [:create]
resources :collections, only: [:show]
resource :followers_synchronization, only: [:show]
end
end
resource :inbox, only: [:create], module: :activitypub resource :inbox, only: [:create], module: :activitypub
constraints(encoded_path: /%40.*/) do constraints(encoded_path: /%40.*/) do

View File

@ -5,6 +5,14 @@ require 'rails_helper'
RSpec.describe 'Accounts show response' do RSpec.describe 'Accounts show response' do
let(:account) { Fabricate(:account) } let(:account) { Fabricate(:account) }
context 'with numeric-based identifiers' do
it 'returns http success' do
get "/u/#{account.id}"
expect(response).to have_http_status(200)
end
end
context 'with an unapproved account' do context 'with an unapproved account' do
before { account.user.update(approved: false) } before { account.user.update(approved: false) }