Skip to content

Commit d163ecc

Browse files
committed
Add logic allowing superusers to confirm emails
This change addresses an issue where some users reported not receiving the confirmation instructions email. Rather than having to manually update the users email confirmation status within the Rails console, this change allows users to confirm/unconfirm user emails within the app.
1 parent 2535269 commit d163ecc

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

app/controllers/super_admin/users_controller.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def update
3838

3939
# Remove the extraneous Org Selector hidden fields
4040
attrs = remove_org_selection_params(params_in: attrs)
41+
attrs = handle_confirmed_at_param(attrs)
4142

4243
if @user.update(attrs)
4344
# If its a new Org create it
@@ -125,7 +126,8 @@ def user_params
125126
:org_id, :org_name, :org_crosswalk,
126127
:department_id,
127128
:language_id,
128-
:other_organisation)
129+
:other_organisation,
130+
:confirmed_at)
129131
end
130132

131133
def merge_accounts
@@ -136,5 +138,20 @@ def merge_accounts
136138
flash.now[:alert] = failure_message(@user, _('merge'))
137139
end
138140
end
141+
142+
def handle_confirmed_at_param(attrs)
143+
# if an unconfirmed email is now being confirmed
144+
if !@user.confirmed? && attrs[:confirmed_at] == '1'
145+
attrs[:confirmed_at] = Time.current
146+
# elsif a confirmed email is now being unconfirmed
147+
elsif @user.confirmed? && attrs[:confirmed_at] == '0'
148+
attrs[:confirmed_at] = nil
149+
else
150+
# else delete the param
151+
# (keeps value nil for unconfirmed user and maintains previous Time value for confirmed user)
152+
attrs.delete(:confirmed_at)
153+
end
154+
attrs
155+
end
139156
end
140157
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="form-group col-xs-12">
2+
<%= f.label(:confirmed_at, _('Email Confirmation Status'), class: 'control-label') %>
3+
<br>
4+
<%= f.check_box(:confirmed_at, checked: @user.confirmed? ) %>
5+
<%= @user.confirmed? ? _("Confirmed.") : _("Unconfirmed.") %>
6+
<small><%= _("(Use checkbox to change status.)") %></small>
7+
</div>

app/views/super_admin/users/edit.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
</div>
5858
<% end %>
5959

60+
<%= render 'email_confirmation_status', f: f %>
61+
6062
<div class="form-control mb-3 col-xs-12">
6163
<%= f.button(_('Save'), class: 'btn btn-secondary', type: "submit", id: "personal_details_registration_form_submit") %>
6264

0 commit comments

Comments
 (0)