Skip to content

Commit feff8a7

Browse files
committed
Add message notifying SHIELD of new submission
1 parent 90382d4 commit feff8a7

9 files changed

Lines changed: 54 additions & 10 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ GEM
199199
mini_mime (1.1.5)
200200
minitest (5.25.5)
201201
msgpack (1.8.0)
202-
multipart-post (2.4.1)
203202
multi_xml (0.7.2)
204203
bigdecimal (~> 3.1)
204+
multipart-post (2.4.1)
205205
mutex_m (0.3.0)
206206
net-http (0.6.0)
207207
uri

app/controllers/slack/commands_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
class Slack::CommandsController < Slack::ApplicationController
22
def new_puzzle
3-
puts "I'm a new puzzle!"
43
view = SlackClient::Views::PuzzleForm.new.create
54
open_view(view, trigger_id: params[:trigger_id])
65
end

app/controllers/slack/puzzles_controller.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ def create
77
answer = values.dig("answer", "answer", "selected_option", "value")
88
explanation = values.dig("explanation", "explanation", "value")
99
link = values.dig("link", "link", "value")
10-
puzzle = Puzzle.new(question:, answer:, explanation:, link:, status: :pending)
10+
puzzle = Puzzle.new(question:, answer:, explanation:, link:, status: :pending, suggested_by: user_id)
1111

12-
view = if puzzle.save
13-
SlackClient::Views::Success.new.create
12+
if puzzle.save
13+
view = SlackClient::Views::Success.new.create
14+
notification_message = SlackClient::Messages::NewPuzzleNotification.new(puzzle).create
15+
send_message(notification_message, channel_id: ENV.fetch("SHIELD_NOTIFICATIONS_CHANNEL", nil))
1416
else
15-
SlackClient::Views::Failure.new.create
17+
view = SlackClient::Views::Failure.new.create
1618
end
1719

1820
render json: { response_action: "update", view: view }, status: :ok
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module SlackClient
2+
module Messages
3+
class NewPuzzleNotification
4+
def initialize(puzzle, shield_group_id: ENV["SHIELD_GROUP_ID"])
5+
@puzzle = puzzle
6+
@shield_group_id = shield_group_id
7+
end
8+
9+
def create
10+
Slack::BlockKit.blocks do |block|
11+
block.section do |section|
12+
section.mrkdwn text: "*New Puzzle Suggestion!*\n\n"
13+
end
14+
block.section do |section|
15+
section.mrkdwn text: body_text
16+
end
17+
end.as_json
18+
end
19+
20+
private
21+
22+
def body_text
23+
<<~TEXT
24+
Hey <!subteam^#{@shield_group_id}>!
25+
26+
<@#{@puzzle.suggested_by}> has submitted a new suggestion for a puzzle:
27+
28+
Question:
29+
#{@puzzle.question}
30+
31+
Check out the <#{ENV.fetch('APP_URL', nil)}|admin panel> for more details.
32+
TEXT
33+
end
34+
end
35+
end
36+
end

app/lib/slack_client/views/failure.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def create
1313
end
1414
end
1515
end
16-
end
16+
end

app/lib/slack_client/views/puzzle_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def create
3030
end
3131
end
3232
end
33-
end
33+
end

app/lib/slack_client/views/success.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def create
1313
end
1414
end
1515
end
16-
end
16+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddUserToPuzzles < ActiveRecord::Migration[8.0]
2+
def change
3+
add_column :puzzles, :suggested_by, :string
4+
end
5+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)