Skip to content
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

create initial admin from UI #103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class User < ApplicationRecord

before_save :guard_unconfirmed_email

after_save :remove_invalid_unconfirmed_emails
after_save :remove_invalid_unconfirmed_emails, :verify_default_admin!

before_destroy do
raise "Never destroy users!"
Expand Down Expand Up @@ -599,6 +599,16 @@ def remember_me
true
end

def verify_default_admin!
if is_initial_user?
Role.add_admin(self)
end
end

def is_initial_user?
User.count == 1
end

private

def clearable_fields
Expand Down