闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
944 B

  1. # frozen_string_literal: true
  2. class AuthorizeFollowController < ApplicationController
  3. layout 'public'
  4. before_action :authenticate_user!
  5. def new
  6. uri = Addressable::URI.parse(acct_param)
  7. if uri.path && %w(http https).include?(uri.scheme)
  8. set_account_from_url
  9. else
  10. set_account_from_acct
  11. end
  12. render :error if @account.nil?
  13. end
  14. def create
  15. @account = FollowService.new.call(current_account, acct_param).try(:target_account)
  16. if @account.nil?
  17. render :error
  18. else
  19. redirect_to web_url("accounts/#{@account.id}")
  20. end
  21. rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
  22. render :error
  23. end
  24. private
  25. def set_account_from_url
  26. @account = FetchRemoteAccountService.new.call(acct_param)
  27. end
  28. def set_account_from_acct
  29. @account = FollowRemoteAccountService.new.call(acct_param)
  30. end
  31. def acct_param
  32. params[:acct].gsub(/\Aacct:/, '')
  33. end
  34. end