docbrown/app/controllers/feedback_messages_controller.rb
Nick Taylor 86eb75cee7
Report a Message in Connect (#12229)
* Frontend Ready for Connect Report Abuse

* add feedback api

* js defination fix

* Added Hooks to the Component

* add json response in feedback

* Block popup added

* fix render issue

* Made changes in internal view

* change error message

* Added few design changes =

* add test cases

* Update app/javascript/chat/actions/requestActions.js

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* add PR suggestions

* add backend test cases

* report abuse form close

* Update app/javascript/chat/actions/requestActions.js

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* add test cases

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Marcy Sutton <holla@marcysutton.com>

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Marcy Sutton <holla@marcysutton.com>

* group the fieldset

* fix report abuse api

* fix test case

* fix request test case

* fix typo

* cleaned up markup in report abuse component.

* Fixed spacing between abuse options.

* Fixed wording in report abuse confirmation.

* Removed unnecessary data-testid and aria-label attributes.

* Added some top margin to the report abuse form.

* Update app/javascript/chat/message.jsx

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Added a legend to the the fieldset.

* Update app/javascript/chat/actions/requestActions.js

Co-authored-by: Michael Kohl <citizen428@dev.to>

Co-authored-by: Sarthak <7lovesharma7@gmail.com>
Co-authored-by: Narender Singh <narender2031@gmail.com>
Co-authored-by: Marcy Sutton <holla@marcysutton.com>
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Michael Kohl <citizen428@dev.to>
2021-01-19 12:07:47 -05:00

59 lines
1.9 KiB
Ruby

class FeedbackMessagesController < ApplicationController
# No authorization required for entirely public controller
skip_before_action :verify_authenticity_token
def create
flash.clear
rate_limit!(:feedback_message_creation)
params = feedback_message_params.merge(reporter_id: current_user&.id)
@feedback_message = FeedbackMessage.new(params)
recaptcha_enabled = ReCaptcha::CheckEnabled.call(current_user)
if (!recaptcha_enabled || recaptcha_verified? || connect_feedback?) && @feedback_message.save
Slack::Messengers::Feedback.call(
user: current_user,
type: feedback_message_params[:feedback_type],
category: feedback_message_params[:category],
reported_url: feedback_message_params[:reported_url],
message: feedback_message_params[:message],
)
rate_limiter.track_limit_by_action(:feedback_message_creation)
respond_to do |format|
format.html { redirect_to feedback_messages_path }
format.json { render json: { success: true, message: "Your report is submitted" } }
end
else
@previous_message = feedback_message_params[:message]
flash[:notice] = "Make sure the forms are filled 🤖"
respond_to do |format|
format.html { render "pages/report_abuse" }
format.json do
render json: {
success: false,
message: @feedback_message.errors_as_sentence,
status: :bad_request
}
end
end
end
end
private
def recaptcha_verified?
recaptcha_params = { secret_key: SiteConfig.recaptcha_secret_key }
params["g-recaptcha-response"] && verify_recaptcha(recaptcha_params)
end
def connect_feedback?
feedback_message_params[:feedback_type] == "connect"
end
def feedback_message_params
allowed_params = %i[message feedback_type category reported_url offender_id]
params.require(:feedback_message).permit(allowed_params)
end
end