* Rubocop enabled style/alias * Enabled Style/ArrayJoin Cop * Enabled Style/Attr * Enabled Case Equality * Enabled CharacterLiteral * Enabled ColonMethodCall Cop * Enabled CommentAnnotation cop * Enabled PreferredHashMethods Cop * Enabled DoubleNegation Cop * Enabled EachWithObject Cop * Enabled EmptyLiteral Cop * Enabled EvenOdd Cop * Enabled IfWithSemicolon Cop * Enabled Lambda and LambdaCall Cop * Enabled LineEndConcatenation Cop * Enabled ModuleFunction Cop; * Enable NegatedIf and NegatedWhile Cop * Enabled NilComparison Cop * Enabled Not Cop * Enabled NumericLiterals Cop * Enabled OneLineConditional Cop * Enabled PercentLiteralDelimiters Cop * Excluded internal/users_controller from negated_if cop * Reverted the double negation change from github_issue_tag and github_issue.rb" * Enabled PerlBackrefs Cop * Changed Regexp.last_match(1) to Regexp.last_match(0) * Enabled proc cop * Enabled RaiseArgs Cop * Reverted Regexp.last_match(0) to Regexp.last_match(1) * Enabled SelfAssignment Cop * Enabled SingleLineMethods Cop * Enabled SpecialGlobalVars Cop * Enabled VariableInterpolation Cop * Enabled WhenThen Cop * Enabled WhileUntilModifier Cop * Enabled WordArray Cop * Enabled IfUnlessModifier Cop * Enabled GuardClause Cop
57 lines
2.2 KiB
Ruby
57 lines
2.2 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
|
|
elsif params[:followable_type] == "User" && FollowChecker.new(current_user, params[:followable_type], params[:id]).cached_follow_check && FollowChecker.new(User.find(params[:id]), params[:followable_type], current_user.id).cached_follow_check
|
|
render plain: "mutual"
|
|
elsif params[:followable_type] == "User" && FollowChecker.new(User.find(params[:id]), params[:followable_type], current_user.id).cached_follow_check
|
|
render plain: "follow-back"
|
|
else
|
|
render plain: FollowChecker.new(current_user, params[:followable_type], params[:id]).cached_follow_check
|
|
end
|
|
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
|
|
add_param_context(:followable_type, :followable_id, :verb)
|
|
need_notification = Follow.need_new_follower_notification_for?(followable.class.name)
|
|
@result = if params[:verb] == "unfollow"
|
|
follow = current_user.stop_following(followable)
|
|
Notification.send_new_follower_notification_without_delay(follow, true) if need_notification
|
|
"unfollowed"
|
|
else
|
|
follow = current_user.follow(followable)
|
|
Notification.send_new_follower_notification(follow) if need_notification
|
|
"followed"
|
|
end
|
|
current_user.touch
|
|
render json: { outcome: @result }
|
|
end
|
|
|
|
def update
|
|
@follow = Follow.find(params[:id])
|
|
authorize @follow
|
|
redirect_to "/dashboard/following" if @follow.update(follow_params)
|
|
end
|
|
|
|
private
|
|
|
|
def follow_params
|
|
params.require(:follow).permit(policy(Follow).permitted_attributes)
|
|
end
|
|
end
|