Skip to content

Commit 8ef37f4

Browse files
authored
[OrganizerPositionInvite] Hint when accepting invite with wrong user (#11911)
## Summary of the problem A user ran into a confusing moment when they attempted to accept an invite with another email address. They were unaware they were using the wrong account because all HCB says is "You are not authorized to perform this action." ## Describe your changes 🥁 Introducing.... a helpful hint! <img width="308" height="232" alt="image" src="https://github.com/user-attachments/assets/1e3999c9-a165-400b-b830-9759ff79a87a" />
1 parent 0565e91 commit 8ef37f4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

app/controllers/organizer_position_invites_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def show
5959
elsif @invite.rejected?
6060
redirect_to root_path, flash: { error: "You’ve already rejected this invitation." }
6161
end
62+
rescue Pundit::NotAuthorizedError
63+
if @invite.user != current_user
64+
flash[:error] = "This invitation was sent to #{@invite.user.redacted_email}, but you are currently logged in as #{current_user.email }."
65+
redirect_to root_path and return
66+
end
67+
68+
raise
6269
end
6370

6471
def accept

app/models/user.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ def initials
291291
words.any? ? words.map(&:first).join.upcase : name
292292
end
293293

294+
# gary@hackclub.com → g***y@hackclub.com
295+
# gt@hackclub.com → g*@hackclub.com
296+
# g@hackclub.com → g@hackclub.com
297+
def redacted_email
298+
handle, domain = email.split("@")
299+
redacted_handle =
300+
if handle.length <= 2
301+
handle[0] + "*" * (handle.length - 1)
302+
else
303+
"#{handle[0]}***#{handle[-1]}"
304+
end
305+
"#{redacted_handle}@#{domain}"
306+
end
307+
294308
def pretty_phone_number
295309
Phonelib.parse(self.phone_number).national
296310
end

0 commit comments

Comments
 (0)