Use /collections/:id as canonical URL for a collection (#38783)
This commit is contained in:
parent
c4eec632b9
commit
fdb2563abf
@ -17,7 +17,10 @@ class CollectionsController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
# TODO: format.html
|
format.html do
|
||||||
|
expires_in expiration_duration, public: true unless user_signed_in?
|
||||||
|
render template: 'home/index'
|
||||||
|
end
|
||||||
|
|
||||||
format.json do
|
format.json do
|
||||||
expires_in expiration_duration, public: true if public_fetch_mode?
|
expires_in expiration_duration, public: true if public_fetch_mode?
|
||||||
@ -28,8 +31,17 @@ class CollectionsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_account
|
||||||
|
if account_id_param.present?
|
||||||
|
@account = Account.local.find(account_id_param)
|
||||||
|
else
|
||||||
|
@collection = Collection.find(params[:id])
|
||||||
|
@account = @collection.account
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def set_collection
|
def set_collection
|
||||||
@collection = @account.collections.find(params[:id])
|
@collection ||= @account.collections.find(params[:id])
|
||||||
authorize @collection, :show?
|
authorize @collection, :show?
|
||||||
rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
|
rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
|
||||||
not_found
|
not_found
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class ActivityPub::TagManager
|
|||||||
when :flag
|
when :flag
|
||||||
target.uri
|
target.uri
|
||||||
when :featured_collection
|
when :featured_collection
|
||||||
account_collection_url(target.account, target)
|
collection_url(target)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
= t('admin.collections.collection_title', name: @account.pretty_acct)
|
= t('admin.collections.collection_title', name: @account.pretty_acct)
|
||||||
|
|
||||||
- content_for :heading_actions do
|
- content_for :heading_actions do
|
||||||
= link_to t('admin.collections.open'), account_collection_path(@account, @collection), class: 'button', target: '_blank', rel: 'noopener'
|
= link_to t('admin.collections.open'), collection_path(@collection), class: 'button', target: '_blank', rel: 'noopener'
|
||||||
|
|
||||||
%h3= t('admin.collections.contents')
|
%h3= t('admin.collections.contents')
|
||||||
|
|
||||||
|
|||||||
@ -18,5 +18,5 @@
|
|||||||
·
|
·
|
||||||
= t('admin.collections.number_of_accounts', count: collection.accepted_collection_items.size)
|
= t('admin.collections.number_of_accounts', count: collection.accepted_collection_items.size)
|
||||||
·
|
·
|
||||||
= link_to account_collection_path(collection.account, collection), class: 'detailed-status__link', target: 'blank', rel: 'noopener' do
|
= link_to collection_path(collection), class: 'detailed-status__link', target: 'blank', rel: 'noopener' do
|
||||||
= t('admin.collections.view_publicly')
|
= t('admin.collections.view_publicly')
|
||||||
|
|||||||
@ -97,7 +97,6 @@ Rails.application.routes.draw do
|
|||||||
get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
|
get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
|
||||||
|
|
||||||
concern :account_resources do
|
concern :account_resources do
|
||||||
resources :collections, only: [:show], constraints: { id: /\d+/ }
|
|
||||||
resources :followers, only: [:index], controller: :follower_accounts
|
resources :followers, only: [:index], controller: :follower_accounts
|
||||||
resources :following, only: [:index], controller: :following_accounts
|
resources :following, only: [:index], controller: :following_accounts
|
||||||
|
|
||||||
@ -125,6 +124,7 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
scope path: 'ap', as: 'ap' do
|
scope path: 'ap', as: 'ap' do
|
||||||
resources :accounts, path: 'users', only: [:show], param: :id, concerns: :account_resources do
|
resources :accounts, path: 'users', only: [:show], param: :id, concerns: :account_resources do
|
||||||
|
resources :collections, only: [:show], constraints: { id: /\d+/ }
|
||||||
resources :collection_items, only: [:show]
|
resources :collection_items, only: [:show]
|
||||||
resources :feature_authorizations, only: [:show], module: :activitypub
|
resources :feature_authorizations, only: [:show], module: :activitypub
|
||||||
resources :featured_collections, only: [:index], module: :activitypub
|
resources :featured_collections, only: [:index], module: :activitypub
|
||||||
@ -141,6 +141,8 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :collections, only: [:show]
|
||||||
|
|
||||||
resource :inbox, only: [:create], module: :activitypub
|
resource :inbox, only: [:create], module: :activitypub
|
||||||
resources :contexts, only: [:show], module: :activitypub, constraints: { id: /[0-9]+-[0-9]+/ } do
|
resources :contexts, only: [:show], module: :activitypub, constraints: { id: /[0-9]+-[0-9]+/ } do
|
||||||
member do
|
member do
|
||||||
|
|||||||
@ -3,8 +3,20 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'Collections' do
|
RSpec.describe 'Collections' do
|
||||||
describe 'GET /@:account_username/collections/:id', feature: :collections do
|
describe 'GET /collections/:id', feature: :collections do
|
||||||
subject { get account_collection_path(account, collection, format: :json) }
|
subject { get collection_path(collection) }
|
||||||
|
|
||||||
|
let(:collection) { Fabricate(:collection) }
|
||||||
|
|
||||||
|
it 'returns success' do
|
||||||
|
subject
|
||||||
|
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'GET /ap/:account_id/collections/:id', feature: :collections do
|
||||||
|
subject { get ap_account_collection_path(account.id, collection, format: :json) }
|
||||||
|
|
||||||
let(:collection) { Fabricate(:collection) }
|
let(:collection) { Fabricate(:collection) }
|
||||||
let(:account) { collection.account }
|
let(:account) { collection.account }
|
||||||
@ -80,7 +92,7 @@ RSpec.describe 'Collections' do
|
|||||||
|
|
||||||
context 'with "HTTP Signature" access signed by a remote account' do
|
context 'with "HTTP Signature" access signed by a remote account' do
|
||||||
subject do
|
subject do
|
||||||
get account_collection_path(account, collection, format: :json),
|
get ap_account_collection_path(account.id, collection, format: :json),
|
||||||
headers: nil,
|
headers: nil,
|
||||||
sign_with: remote_account
|
sign_with: remote_account
|
||||||
end
|
end
|
||||||
|
|||||||
@ -25,7 +25,7 @@ RSpec.describe ActivityPub::FeaturedCollectionSerializer do
|
|||||||
'attributedTo' => ActivityPub::TagManager.instance.uri_for(collection.account),
|
'attributedTo' => ActivityPub::TagManager.instance.uri_for(collection.account),
|
||||||
'sensitive' => false,
|
'sensitive' => false,
|
||||||
'discoverable' => false,
|
'discoverable' => false,
|
||||||
'url' => account_collection_url(collection.account, collection),
|
'url' => collection_url(collection),
|
||||||
'topic' => {
|
'topic' => {
|
||||||
'href' => match(%r{/tags/people$}),
|
'href' => match(%r{/tags/people$}),
|
||||||
'type' => 'Hashtag',
|
'type' => 'Hashtag',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user