Skip to content

Commit

Permalink
automatically make developers admins on account creation, this solves…
Browse files Browse the repository at this point in the history
… the user #1 problem

you can simply set the DEVELOPER_EMAILS to a comma delimited list and the users will be auto admined
  • Loading branch information
SamSaffron committed Nov 1, 2013
1 parent a65a063 commit 8ff35d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion config/environments/production.rb.sample
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Discourse::Application.configure do
# a comma delimited list of emails your devs have
# developers have god like rights and may impersonate anyone in the system
# normal admins may only impersonate other moderators (not admins)
config.developer_emails = []
if emails = ENV["DEVELOPER_EMAILS"]
config.developer_emails = emails.split(",")
end

end
10 changes: 10 additions & 0 deletions lib/auth/default_current_user_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,19 @@ def log_on_user(user, session, cookies)
user.save!
end
cookies.permanent[TOKEN_COOKIE] = { value: user.auth_token, httponly: true }
make_developer_admin(user)
@env[CURRENT_USER_KEY] = user
end

def make_developer_admin(user)
if user.active? &&
!user.admin &&
Rails.configuration.respond_to?(:developer_emails) &&
Rails.configuration.developer_emails.include?(user.email)
user.update_column(:admin, true)
end
end

def log_off_user(session, cookies)
cookies[TOKEN_COOKIE] = nil
end
Expand Down

0 comments on commit 8ff35d4

Please sign in to comment.