Skip to content

Commit 7d8f8f6

Browse files
authored
IIRR-23 / IIRR-24: (#48)
- Add filtering to make sure only ombulabs.com email addresses can log into the admin panel - Add message when number of approved puzzles is running low
1 parent 56fe03c commit 7d8f8f6

6 files changed

Lines changed: 105 additions & 2 deletions

File tree

app/assets/stylesheets/application.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,34 @@ th {
7979
.pending-btn {
8080
background-color: yellow;
8181
color: black;
82+
}
83+
84+
/* Banner styles */
85+
.banner {
86+
position: fixed;
87+
top: 0;
88+
left: 0;
89+
right: 0;
90+
z-index: 1000;
91+
background-color: #f8d7da;
92+
color: #721c24;
93+
border-bottom: 2px solid #f5c6cb;
94+
padding: 10px 20px;
95+
text-align: center;
96+
font-weight: bold;
97+
}
98+
99+
.banner-message.error {
100+
background-color: #f8d7da;
101+
color: #721c24;
102+
}
103+
104+
.banner-message.notice {
105+
background-color: #d4edda;
106+
color: #155724;
107+
}
108+
109+
.banner-message.alert {
110+
background-color: #fff3cd;
111+
color: #856404;
82112
}

app/controllers/sessions_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
class SessionsController < ApplicationController
22
def create
33
auth = request.env["omniauth.auth"]
4+
user_email = auth.info.email
5+
6+
unless user_email.end_with?("@ombulabs.com")
7+
reset_session
8+
flash[:error] = "Access denied. Please access with your @ombulabs.com email address."
9+
redirect_to root_path
10+
return
11+
end
12+
413
session[:user_token] = auth.credentials.token
5-
session[:user_email] = auth.info.email
14+
session[:user_email] = user_email
615
redirect_to root_path
716
end
817

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class PuzzleInventoryCheckJob < ApplicationJob
2+
queue_as :default
3+
retry_on StandardError, attempts: 3
4+
5+
def perform
6+
approved_puzzle_count = Puzzle.where(state: 0).count
7+
8+
if approved_puzzle_count < 5
9+
send_low_inventory_notification(approved_puzzle_count)
10+
end
11+
end
12+
13+
private
14+
15+
def send_low_inventory_notification(count)
16+
notification_message = SlackClient::Messages::LowPuzzleInventoryNotification.new(count).create
17+
send_message(notification_message, channel_id: ENV.fetch("SHIELD_NOTIFICATIONS_CHANNEL", nil))
18+
end
19+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module SlackClient
2+
module Messages
3+
class LowPuzzleInventoryNotification
4+
def initialize(count, shield_group_id: ENV["SHIELD_GROUP_ID"])
5+
@count = count
6+
@shield_group_id = shield_group_id
7+
end
8+
9+
def create
10+
Slack::BlockKit.blocks do |block|
11+
block.header text: "⚠️ Puzzle Inventory Alert ⚠️"
12+
block.section do |section|
13+
section.mrkdwn text: body_text
14+
end
15+
end.as_json
16+
end
17+
18+
private
19+
20+
def body_text
21+
<<~TEXT
22+
Hey <!subteam^#{@shield_group_id}>!
23+
24+
There are currently *only #{@count} approved puzzles* in the database. This is below the minimum threshold of 5 puzzles.
25+
26+
Please add more puzzles so we don't run out!
27+
TEXT
28+
end
29+
end
30+
end
31+
end

app/views/layouts/application.html.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
</head>
2020

2121
<body>
22+
<% if flash.any? %>
23+
<div class="banner">
24+
<% flash.each do |name, msg| %>
25+
<div class="banner-message <%= name %>">
26+
<%= msg %>
27+
</div>
28+
<% end %>
29+
</div>
30+
<% end %>
31+
2232
<%= yield %>
2333
</body>
2434
</html>

config/sidekiq.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66

77
weekly_puzzle_job:
88
cron: "0 0 * * 0" # This runs the every Sunday at midnight
9-
class: "WeeklyLeaderboardJob"
9+
class: "WeeklyLeaderboardJob"
10+
11+
puzzle_inventory_check:
12+
cron: "0 10 * * *" # This runs the job at 10:00 AM every day
13+
class: "PuzzleInventoryCheckJob"

0 commit comments

Comments
 (0)