From d7ffaf1f80d9a20a3c665be3a115494b23e3bfb7 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 2 Sep 2023 12:41:43 +0100 Subject: [PATCH] Fix: Creating flags on review apps attempting to notify our flags Discord channel Because: * When creating a flag on a review app it was returning a 500 response because the discord notifier isn't configured. * We don't want testing flags on review apps to create noise in our Discord channel. This commit: * Do not run the discord notifier service if we're in the development environment or staging (review apps). * Removes the json responses for creating flags, those were used from the removed react implementation of the flag form. --- .../project_submissions/flags_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/project_submissions/flags_controller.rb b/app/controllers/project_submissions/flags_controller.rb index de2b293271..25320d6fcc 100644 --- a/app/controllers/project_submissions/flags_controller.rb +++ b/app/controllers/project_submissions/flags_controller.rb @@ -6,7 +6,7 @@ def new @flag = @project_submission.flags.new end - def create # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def create @flag = @project_submission.flags.new(flag_params) respond_to do |format| @@ -14,10 +14,8 @@ def create # rubocop:disable Metrics/AbcSize, Metrics/MethodLength notify_discord_admins format.html { redirect_to lesson_path(@project_submission.lesson) } - format.json { render json: @flag, status: :created } format.turbo_stream { flash.now[:notice] = 'Thank you! your report has been submitted.' } else - format.json { render json: { error: 'Unable to flag project submission' }, status: :unprocessable_entity } format.html { render :new, status: :unprocessable_entity } end end @@ -34,10 +32,14 @@ def flag_params end def notify_discord_admins - return unless Rails.env.production? + return unless discord_notifications_enabled? DiscordNotifier.notify( Notifications::FlagSubmission.new(@flag) ) end + + def discord_notifications_enabled? + Rails.env.production? && ENV['STAGING'].blank? + end end