From 8ff35d4b10980bc94db8d485caf9dea0cbcc68df Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 2 Nov 2013 10:25:43 +1100 Subject: [PATCH] automatically make developers admins on account creation, this solves the user #1 problem you can simply set the DEVELOPER_EMAILS to a comma delimited list and the users will be auto admined --- config/environments/production.rb.sample | 4 +++- lib/auth/default_current_user_provider.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/environments/production.rb.sample b/config/environments/production.rb.sample index 3b19c592f9404..8257958fa4894 100644 --- a/config/environments/production.rb.sample +++ b/config/environments/production.rb.sample @@ -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 diff --git a/lib/auth/default_current_user_provider.rb b/lib/auth/default_current_user_provider.rb index 98430e3207247..14341fcccb04f 100644 --- a/lib/auth/default_current_user_provider.rb +++ b/lib/auth/default_current_user_provider.rb @@ -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