Skip to content

Commit 625e284

Browse files
authored
feat: add golden ticket custom field to Sidekick reviews (#136)
1 parent b2780ec commit 625e284

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

app/controllers/api/sidekick_controller.rb

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def submit_review_action
138138
admin_content: @input[:justification],
139139
approved_seconds: (@input[:hoursAssigned].to_f * 3600).to_i
140140
)
141-
serialize_approval_event(review, ship_id)
141+
apply_golden_ticket!(project, @input.dig(:fields, :grant_golden_ticket))
142+
serialize_approval_event(review, ship_id, project: project)
142143
when "reject"
143144
review = project.reviews.create!(
144145
author: reviewer,
@@ -190,6 +191,7 @@ def update_review_action
190191
updates[:admin_content] = @input[:internalMessage] if type == "rejection" && @input.key?(:internalMessage)
191192

192193
review.update!(updates)
194+
apply_golden_ticket!(project, @input.dig(:fields, :grant_golden_ticket)) if type == "approval"
193195
{ success: true }
194196
end
195197

@@ -453,12 +455,20 @@ def build_ships(project, all_versions = nil)
453455
else "pending"
454456
end
455457

456-
{
458+
ship = {
457459
id: "v#{version.id}",
458460
hoursSubmitted: submission_hours(project, version, all_versions),
459461
submittedAt: submitted_at.iso8601,
460462
status: status
461463
}
464+
465+
if status == "pending"
466+
ship[:approveFields] = [
467+
{ name: "grant_golden_ticket", label: "Grant golden ticket", type: "boolean", defaultValue: project.high_quality? }
468+
]
469+
end
470+
471+
ship
462472
end.sort_by { |s| s[:submittedAt] }
463473
end
464474

@@ -557,14 +567,16 @@ def find_ship_id_for_review(review, submission_versions)
557567

558568
# --- Timeline event serializers ---
559569

560-
def serialize_approval_event(review, ship_id)
570+
def serialize_approval_event(review, ship_id, project: nil)
571+
project ||= review.project
561572
{
562573
type: "approval",
563574
shipId: ship_id,
564575
actorId: actor_id_for(review.author),
565576
hoursAssigned: review.approved_seconds / 3600.0,
566577
feedbackMessage: review.content || "",
567578
justification: review.admin_content || "",
579+
fields: { grant_golden_ticket: project.high_quality? },
568580
timestamp: review.created_at.iso8601
569581
}
570582
end
@@ -593,6 +605,20 @@ def serialize_comment_event(review, internal: false)
593605

594606
# --- Helpers ---
595607

608+
def apply_golden_ticket!(project, grant)
609+
return unless grant == true || grant == "true"
610+
611+
was_high_quality = project.high_quality?
612+
project.update!(high_quality: true)
613+
614+
if !was_high_quality
615+
author_ping = project.user.slack_id.present? ? "<@#{project.user.slack_id}>" : project.user.username
616+
text = ":rac_woah: #{author_ping} got a golden ticket for their project *#{project.title}*!! check it out <#{project.demo_link}|here!>"
617+
channel = ENV.fetch("GOLDEN_TICKET_SLACK_CHANNEL", SlackChannels::THE_GAME)
618+
SlackApiService.post_message(channel: channel, text: text)
619+
end
620+
end
621+
596622
def actor_id_for(user)
597623
return user.slack_id if user.slack_id.present?
598624
return "ident!#{user.account_id}" if user.account_id.present?

0 commit comments

Comments
 (0)