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.

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