-
Notifications
You must be signed in to change notification settings - Fork 75
feat(admin): allow admins to confirm users and set passwords #834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
markets
merged 4 commits into
coopdevs:develop
from
rewritten:feature/admin-confirm-users
Apr 7, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e49d5b2
feat(admin): allow admins to confirm users and set passwords
rewritten 656a83b
Update app/models/user.rb
rewritten f57fa9b
Fix controller + add tests
rewritten 277f874
fix(admin): use skip_confirmation! to forcibly mark users as confirmed
rewritten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| RSpec.describe Admin::UsersController, type: :controller do | ||
| let(:organization) { Fabricate(:organization) } | ||
| let(:member) { Fabricate(:member, organization: organization) } | ||
| let(:user) { member.user } | ||
|
|
||
| before do | ||
| login(user) | ||
| allow(controller).to receive(:authenticate_superuser!).and_return(true) | ||
| end | ||
|
|
||
| describe "PUT #confirm" do | ||
| context "when the user is unconfirmed" do | ||
| let(:unconfirmed_user) { Fabricate(:user, confirmed_at: nil) } | ||
|
|
||
| it "confirms the user and redirects with notice" do | ||
| put :confirm, params: { id: unconfirmed_user.id } | ||
|
|
||
| expect(unconfirmed_user.reload.confirmed?).to be true | ||
| expect(response).to redirect_to(admin_user_path(unconfirmed_user)) | ||
| expect(flash[:notice]).to eq(I18n.t("active_admin.users.confirmed_notice")) | ||
| end | ||
| end | ||
|
|
||
| context "when the user is already confirmed" do | ||
| it "re-confirms and redirects with notice" do | ||
| put :confirm, params: { id: user.id } | ||
|
|
||
| expect(response).to redirect_to(admin_user_path(user)) | ||
| expect(flash[:notice]).to eq(I18n.t("active_admin.users.confirmed_notice")) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "POST #create" do | ||
| let(:valid_params) do | ||
| { username: "newuser", email: "new@example.com", locale: "en" } | ||
| end | ||
|
|
||
| context "with confirm_immediately checked" do | ||
| it "creates a confirmed user" do | ||
| post :create, params: { user: valid_params.merge(confirm_immediately: "1") } | ||
|
|
||
| created_user = User.find_by(email: "new@example.com") | ||
| expect(created_user).to be_confirmed | ||
| end | ||
| end | ||
|
|
||
| context "without confirm_immediately checked" do | ||
| it "creates an unconfirmed user" do | ||
| post :create, params: { user: valid_params.merge(confirm_immediately: "0") } | ||
|
|
||
| created_user = User.find_by(email: "new@example.com") | ||
| expect(created_user).not_to be_confirmed | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "PUT #update" do | ||
| context "when password is blank" do | ||
| it "does not change the existing password" do | ||
| original_encrypted = user.encrypted_password | ||
|
|
||
| put :update, params: { id: user.id, user: { password: "", password_confirmation: "" } } | ||
|
|
||
| expect(user.reload.encrypted_password).to eq(original_encrypted) | ||
| end | ||
| end | ||
|
|
||
| context "when password is provided" do | ||
| it "updates the password" do | ||
| original_encrypted = user.encrypted_password | ||
|
|
||
| put :update, params: { id: user.id, user: { password: "newpassword123", password_confirmation: "newpassword123" } } | ||
|
|
||
| expect(user.reload.encrypted_password).not_to eq(original_encrypted) | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New admin behaviors are introduced here (manual confirmation endpoint and the ability to set/retain passwords via the ActiveAdmin form/controller overrides) but there are no specs covering them. Adding request/controller specs around
PUT /admin/users/:id/confirm, create with/withoutconfirm_immediately, and update with blank vs non-blank password would help prevent regressions (especially around Devise confirmable).