Skip to content

Commit

Permalink
Fix: Creating flags on review apps attempting to notify our flags Dis…
Browse files Browse the repository at this point in the history
…cord 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.
  • Loading branch information
KevinMulhern committed Sep 2, 2023
1 parent fbeeeda commit d7ffaf1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/controllers/project_submissions/flags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ 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|
if @flag.save
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
Expand All @@ -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

0 comments on commit d7ffaf1

Please sign in to comment.