Add support for numeric-based URIs for local accounts

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

View file

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

View file

@ -18,7 +18,11 @@ module AccountOwnedConcern
end
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
def username_param

View file

@ -117,6 +117,29 @@ Rails.application.routes.draw do
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
constraints(encoded_path: /%40.*/) do

View file

@ -5,6 +5,14 @@ require 'rails_helper'
RSpec.describe 'Accounts show response' do
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
before { account.user.update(approved: false) }