Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def destroy
def auto_login_single_user
# Autocreate an admin user if there isn't one
create_admin_user if User.with_role(:administrator).empty?
# If in single user mode, automatically log in with an admin account
unless Flipper.enabled?(:multiuser)
# If in single user mode, or on first run,
# automatically log in with an admin account
if !Flipper.enabled?(:multiuser) || User.with_role(:administrator).first.reset_password_token == "first_use"
sign_in(:user, User.with_role(:administrator).first)
flash.discard
redirect_back_or_to root_path, alert: nil
Expand Down
17 changes: 16 additions & 1 deletion spec/requests/users/sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

RSpec.describe "Users::Sessions" do
context "when in multiuser mode", :multiuser do
context "when signed out" do
context "when signed out on first use" do
describe "GET /users/sign_in" do
it "creates a default account" do
expect { get "/users/sign_in" }.to change(User, :count).from(0).to(1)
Expand All @@ -17,6 +17,21 @@
expect(User.first.is_administrator?).to be true
end

it "automatically logs in on first use" do
get "/users/sign_in"
expect(controller.current_user).to be_present
end
end
end

context "when signed out after first use" do
describe "GET /users/sign_in" do
let(:admin) { create(:admin) }

before do
admin.update(reset_password_token: nil)
end

it "doesn't auto log in" do
get "/users/sign_in"
expect(controller.current_user).to be_nil
Expand Down