2018-08-18 01:03:12 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AuthorizeInteractionsController < ApplicationController
|
|
|
|
include Authorization
|
|
|
|
|
|
|
|
layout 'modal'
|
|
|
|
|
|
|
|
before_action :authenticate_user!
|
|
|
|
before_action :set_body_classes
|
|
|
|
before_action :set_resource
|
2018-08-18 16:04:49 +00:00
|
|
|
before_action :set_pack
|
2018-08-18 01:03:12 +00:00
|
|
|
|
|
|
|
def show
|
|
|
|
if @resource.is_a?(Account)
|
|
|
|
render :show
|
|
|
|
elsif @resource.is_a?(Status)
|
2022-04-30 22:56:34 +00:00
|
|
|
redirect_to web_url("@#{@resource.account.pretty_acct}/#{@resource.id}")
|
2018-08-18 01:03:12 +00:00
|
|
|
else
|
|
|
|
render :error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-03-08 14:17:39 +00:00
|
|
|
if @resource.is_a?(Account) && FollowService.new.call(current_account, @resource, with_rate_limit: true)
|
2018-08-18 01:03:12 +00:00
|
|
|
render :success
|
|
|
|
else
|
|
|
|
render :error
|
|
|
|
end
|
2022-04-30 22:56:34 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2018-08-18 01:03:12 +00:00
|
|
|
render :error
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_resource
|
2022-04-30 22:56:34 +00:00
|
|
|
@resource = located_resource
|
2018-08-18 01:03:12 +00:00
|
|
|
authorize(@resource, :show?) if @resource.is_a?(Status)
|
2022-04-30 22:56:34 +00:00
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2018-08-18 01:03:12 +00:00
|
|
|
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, '').gsub(/\Aacct:/, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_body_classes
|
|
|
|
@body_classes = 'modal-layout'
|
|
|
|
end
|
2018-08-18 16:04:49 +00:00
|
|
|
|
|
|
|
def set_pack
|
|
|
|
use_pack 'modal'
|
|
|
|
end
|
2018-08-18 01:03:12 +00:00
|
|
|
end
|