mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 08:48:53 +00:00
Add shareable wrapstodon links (#37047)
This commit is contained in:
23
app/controllers/wrapstodon_controller.rb
Normal file
23
app/controllers/wrapstodon_controller.rb
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class WrapstodonController < ApplicationController
|
||||||
|
include WebAppControllerConcern
|
||||||
|
include Authorization
|
||||||
|
include AccountOwnedConcern
|
||||||
|
|
||||||
|
vary_by 'Accept, Accept-Language, Cookie'
|
||||||
|
|
||||||
|
before_action :set_generated_annual_report
|
||||||
|
|
||||||
|
skip_before_action :require_functional!, only: :show, unless: :limited_federation_mode?
|
||||||
|
|
||||||
|
def show
|
||||||
|
expires_in 10.seconds, public: true if current_account.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_generated_annual_report
|
||||||
|
@generated_annual_report = GeneratedAnnualReport.find_by!(account: @account, year: params[:year], share_key: params[:share_key])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -43,7 +43,8 @@ class AnnualReport
|
|||||||
account: @account,
|
account: @account,
|
||||||
year: @year,
|
year: @year,
|
||||||
schema_version: SCHEMA,
|
schema_version: SCHEMA,
|
||||||
data: data
|
data: data,
|
||||||
|
share_key: SecureRandom.hex(8)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,14 @@
|
|||||||
# Table name: generated_annual_reports
|
# Table name: generated_annual_reports
|
||||||
#
|
#
|
||||||
# id :bigint(8) not null, primary key
|
# id :bigint(8) not null, primary key
|
||||||
# account_id :bigint(8) not null
|
|
||||||
# year :integer not null
|
|
||||||
# data :jsonb not null
|
# data :jsonb not null
|
||||||
# schema_version :integer not null
|
# schema_version :integer not null
|
||||||
|
# share_key :string
|
||||||
# viewed_at :datetime
|
# viewed_at :datetime
|
||||||
|
# year :integer not null
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
|
# account_id :bigint(8) not null
|
||||||
#
|
#
|
||||||
|
|
||||||
class GeneratedAnnualReport < ApplicationRecord
|
class GeneratedAnnualReport < ApplicationRecord
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class REST::AnnualReportSerializer < ActiveModel::Serializer
|
class REST::AnnualReportSerializer < ActiveModel::Serializer
|
||||||
attributes :year, :data, :schema_version
|
attributes :year, :data, :schema_version, :share_url
|
||||||
|
|
||||||
|
def share_url
|
||||||
|
public_wrapstodon_url(object.account, object.year, object.share_key) if object.share_key.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
9
app/views/wrapstodon/show.html.haml
Normal file
9
app/views/wrapstodon/show.html.haml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
- content_for :page_title, t('wrapstodon.title', name: display_name(@account), year: @generated_annual_report.year)
|
||||||
|
|
||||||
|
- content_for :header_tags do
|
||||||
|
%meta{ name: 'robots', content: 'noindex, noarchive' }/
|
||||||
|
|
||||||
|
= opengraph 'og:site_name', site_title
|
||||||
|
= opengraph 'profile:username', acct(@account)[1..]
|
||||||
|
|
||||||
|
= render 'shared/web_app'
|
||||||
@@ -2186,3 +2186,5 @@ en:
|
|||||||
not_supported: This browser doesn't support security keys
|
not_supported: This browser doesn't support security keys
|
||||||
otp_required: To use security keys please enable two-factor authentication first.
|
otp_required: To use security keys please enable two-factor authentication first.
|
||||||
registered_on: Registered on %{date}
|
registered_on: Registered on %{date}
|
||||||
|
wrapstodon:
|
||||||
|
title: Wrapstodon %{year} for %{name}
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ Rails.application.routes.draw do
|
|||||||
get '/@:account_username/followers', to: 'follower_accounts#index'
|
get '/@:account_username/followers', to: 'follower_accounts#index'
|
||||||
get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
|
get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
|
||||||
get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
|
get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
|
||||||
|
get '/@:account_username/wrapstodon/:year/:share_key', to: 'wrapstodon#show', as: :public_wrapstodon
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/@:username_with_domain/(*any)', to: 'home#index', constraints: { username_with_domain: %r{([^/])+?} }, as: :account_with_domain, format: false
|
get '/@:username_with_domain/(*any)', to: 'home#index', constraints: { username_with_domain: %r{([^/])+?} }, as: :account_with_domain, format: false
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddShareKeyToGeneratedAnnualReports < ActiveRecord::Migration[8.0]
|
||||||
|
def change
|
||||||
|
add_column :generated_annual_reports, :share_key, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2025_12_01_155054) do
|
ActiveRecord::Schema[8.0].define(version: 2025_12_02_140424) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_catalog.plpgsql"
|
enable_extension "pg_catalog.plpgsql"
|
||||||
|
|
||||||
@@ -616,6 +616,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_12_01_155054) do
|
|||||||
t.datetime "viewed_at"
|
t.datetime "viewed_at"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.string "share_key"
|
||||||
t.index ["account_id", "year"], name: "index_generated_annual_reports_on_account_id_and_year", unique: true
|
t.index ["account_id", "year"], name: "index_generated_annual_reports_on_account_id_and_year", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user