From aa76853d514a05e0692300a0a745a555f0ecc2a5 Mon Sep 17 00:00:00 2001 From: fef Date: Thu, 1 Dec 2022 01:41:47 +0000 Subject: [PATCH] fix reaction deletion bug and clean up controller Turns out the strange error where it would delete the wrong reaction occurred because I forgot to pass the emoji name to the query, which resulted in the database deleting the first reaction it found. Also, this removes the unused set_reaction callback and includes the Authorization module for the status reactions controller. --- .../api/v1/statuses/reactions_controller.rb | 10 +++------- app/services/unreact_service.rb | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/v1/statuses/reactions_controller.rb b/app/controllers/api/v1/statuses/reactions_controller.rb index db43346def..9542d491c8 100644 --- a/app/controllers/api/v1/statuses/reactions_controller.rb +++ b/app/controllers/api/v1/statuses/reactions_controller.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true class Api::V1::Statuses::ReactionsController < Api::BaseController + include Authorization + before_action -> { doorkeeper_authorize! :write, :'write:favourites' } before_action :require_user! - before_action :set_status - before_action :set_reaction, except: :update def update ReactService.new.call(current_account, @status, params[:id]) @@ -13,16 +13,12 @@ class Api::V1::Statuses::ReactionsController < Api::BaseController end def destroy - UnreactService.new.call(current_account, @status) + UnreactService.new.call(current_account, @status, params[:id]) render_empty end private - def set_reaction - @reaction = @status.status_reactions.where(account: current_account).find_by!(name: params[:id]) - end - def set_status @status = Status.find(params[:status_id]) end diff --git a/app/services/unreact_service.rb b/app/services/unreact_service.rb index ebc270383c..f4089f33b5 100644 --- a/app/services/unreact_service.rb +++ b/app/services/unreact_service.rb @@ -3,8 +3,8 @@ class UnreactService < BaseService include Payloadable - def call(account, status) - reaction = StatusReaction.find_by(account: account, status: status) + def call(account, status, name) + reaction = StatusReaction.find_by(account: account, status: status, name: name) return if reaction.nil? reaction.destroy!