Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Creating flags on review apps attempting to notify our flags Discord channel #4107

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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