* Add comment for public controllers * Add block policy and specs * Add policy for authorizing dashboard * Add follow policy and specs * Refactor a tiny bit * Prevent banned users from following anything * Add a note for email sub controller about auth * Add image upload policies * Add policy for github repos * Fix typo and use correct github repo variable * Fix image uploader and use regular params * Add authenticate_user before action back in * Rename test * Update slack bot message formatting and fix reported URL
37 lines
1.1 KiB
Ruby
37 lines
1.1 KiB
Ruby
class FollowsController < ApplicationController
|
|
after_action :verify_authorized
|
|
|
|
def show
|
|
skip_authorization
|
|
unless current_user
|
|
render plain: "not-logged-in"
|
|
return
|
|
end
|
|
if current_user.id == params[:id].to_i && params[:followable_type] == "User"
|
|
render plain: "self"
|
|
return
|
|
end
|
|
render plain: FollowChecker.new(current_user, params[:followable_type], params[:id]).cached_follow_check
|
|
end
|
|
|
|
def create
|
|
authorize Follow
|
|
followable = if params[:followable_type] == "Organization"
|
|
Organization.find(params[:followable_id])
|
|
elsif params[:followable_type] == "Tag"
|
|
Tag.find(params[:followable_id])
|
|
else
|
|
User.find(params[:followable_id])
|
|
end
|
|
@result = if params[:verb] == "unfollow"
|
|
current_user.stop_following(followable)
|
|
"unfollowed"
|
|
else
|
|
current_user.follow(followable)
|
|
"followed"
|
|
end
|
|
current_user.save
|
|
current_user.touch
|
|
render json: { outcome: @result }
|
|
end
|
|
end
|