闭社主体 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.

66 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class AuthorizeFollowsController < ApplicationController
  3. layout 'modal'
  4. before_action :authenticate_user!
  5. before_action :set_body_classes
  6. def show
  7. @account = located_account || render(:error)
  8. end
  9. def create
  10. @account = follow_attempt.try(:target_account)
  11. if @account.nil?
  12. render :error
  13. else
  14. render :success
  15. end
  16. rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
  17. render :error
  18. end
  19. private
  20. def follow_attempt
  21. FollowService.new.call(current_account, acct_without_prefix)
  22. end
  23. def located_account
  24. if acct_param_is_url?
  25. account_from_remote_fetch
  26. else
  27. account_from_remote_follow
  28. end
  29. end
  30. def account_from_remote_fetch
  31. FetchRemoteAccountService.new.call(acct_without_prefix)
  32. end
  33. def account_from_remote_follow
  34. ResolveRemoteAccountService.new.call(acct_without_prefix)
  35. end
  36. def acct_param_is_url?
  37. parsed_uri.path && %w(http https).include?(parsed_uri.scheme)
  38. end
  39. def parsed_uri
  40. Addressable::URI.parse(acct_without_prefix).normalize
  41. end
  42. def acct_without_prefix
  43. acct_params.gsub(/\Aacct:/, '')
  44. end
  45. def acct_params
  46. params.fetch(:acct, '')
  47. end
  48. def set_body_classes
  49. @body_classes = 'modal-layout'
  50. end
  51. end