~cytrogen/masto-fe

ref: 2f8f92df48326c7ae61679773e64afca46d9a374 masto-fe/app/controllers/authorize_interactions_controller.rb -rw-r--r-- 1.1 KiB
2f8f92df — Matt Jankowski Fix Elastic check deprecation warning about gem version (#27262) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

class AuthorizeInteractionsController < ApplicationController
  include Authorization

  before_action :authenticate_user!
  before_action :set_resource

  def show
    if @resource.is_a?(Account)
      redirect_to web_url("@#{@resource.pretty_acct}")
    elsif @resource.is_a?(Status)
      redirect_to web_url("@#{@resource.account.pretty_acct}/#{@resource.id}")
    else
      not_found
    end
  end

  private

  def set_resource
    @resource = located_resource
    authorize(@resource, :show?) if @resource.is_a?(Status)
  rescue Mastodon::NotPermittedError
    not_found
  end

  def located_resource
    if uri_param_is_url?
      ResolveURLService.new.call(uri_param)
    else
      account_from_remote_follow
    end
  end

  def account_from_remote_follow
    ResolveAccountService.new.call(uri_param)
  end

  def uri_param_is_url?
    parsed_uri.path && %w(http https).include?(parsed_uri.scheme)
  end

  def parsed_uri
    Addressable::URI.parse(uri_param).normalize
  end

  def uri_param
    params[:uri] || params.fetch(:acct, '').delete_prefix('acct:')
  end
end