remote_interaction_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # frozen_string_literal: true
  2. class RemoteInteractionController < ApplicationController
  3. include Authorization
  4. layout 'modal'
  5. before_action :authenticate_user!, if: :whitelist_mode?
  6. before_action :set_interaction_type
  7. before_action :set_status
  8. before_action :set_body_classes
  9. def new
  10. @remote_follow = RemoteFollow.new(session_params)
  11. end
  12. def create
  13. @remote_follow = RemoteFollow.new(resource_params)
  14. if @remote_follow.valid?
  15. session[:remote_follow] = @remote_follow.acct
  16. redirect_to @remote_follow.interact_address_for(@status)
  17. else
  18. render :new
  19. end
  20. end
  21. private
  22. def resource_params
  23. params.require(:remote_follow).permit(:acct)
  24. end
  25. def session_params
  26. { acct: session[:remote_follow] }
  27. end
  28. def set_status
  29. @status = Status.find(params[:id])
  30. authorize @status, :show?
  31. rescue Mastodon::NotPermittedError
  32. # Reraise in order to get a 404
  33. raise ActiveRecord::RecordNotFound
  34. end
  35. def set_body_classes
  36. @body_classes = 'modal-layout'
  37. @hide_header = true
  38. end
  39. def set_interaction_type
  40. @interaction_type = %w(reply reblog favourite).include?(params[:type]) ? params[:type] : 'reply'
  41. end
  42. end