Skip to content

Commit 79f316c

Browse files
authored
Make teacher invitation email addresses case-insensitive (#562)
## Status - Related to RaspberryPiFoundation/digital-editor-issues#662 and RaspberryPiFoundation/digital-editor-issues#663 ## What's Changed? - Modified email address comparison logic for teacher invitations to make it case-insensitive as this was breaking for users if the email address invited was not all downcased.
1 parent 27da723 commit 79f316c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

app/controllers/api/teacher_invitations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def load_invitation
2929
end
3030

3131
def ensure_invitation_email_matches_user_email
32-
return if @invitation.email_address == current_user.email
32+
return if @invitation.email_address.casecmp?(current_user.email)
3333

3434
render json: { error: 'Invitation email does not match user email' }, status: :forbidden
3535
end

spec/features/teacher_invitations/accepting_an_invitation_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,27 @@
155155
end
156156
end
157157

158+
context 'when inviation email and account email differ only in casing' do
159+
let(:invitation_email) { user.email.upcase }
160+
161+
it 'responds 200 OK' do
162+
put("/api/teacher_invitations/#{token}/accept", headers:)
163+
expect(response).to have_http_status(:ok)
164+
end
165+
166+
it 'gives the user the teacher role for the school to which they have been invited' do
167+
put("/api/teacher_invitations/#{token}/accept", headers:)
168+
expect(user).to be_school_teacher(school)
169+
end
170+
171+
it 'sets the accepted_at timestamp on the invitation' do
172+
freeze_time(with_usec: false) do
173+
put("/api/teacher_invitations/#{token}/accept", headers:)
174+
expect(invitation.reload.accepted_at).to eq(Time.current)
175+
end
176+
end
177+
end
178+
158179
context 'when invitation has already been accepted' do
159180
let(:original_accepted_at) { 1.week.ago.noon }
160181

0 commit comments

Comments
 (0)