FEATURE: on initial boot hint users on how to get admin
This commit is contained in:
parent
c27c87911e
commit
7e7c4efcc0
|
@ -67,6 +67,7 @@ class User < ActiveRecord::Base
|
||||||
after_initialize :set_default_external_links_in_new_tab
|
after_initialize :set_default_external_links_in_new_tab
|
||||||
|
|
||||||
after_save :update_tracked_topics
|
after_save :update_tracked_topics
|
||||||
|
after_save :clear_global_notice_if_needed
|
||||||
|
|
||||||
after_create :create_email_token
|
after_create :create_email_token
|
||||||
after_create :create_user_stat
|
after_create :create_user_stat
|
||||||
|
@ -586,6 +587,13 @@ class User < ActiveRecord::Base
|
||||||
TrackedTopicsUpdater.new(id, auto_track_topics_after_msecs).call
|
TrackedTopicsUpdater.new(id, auto_track_topics_after_msecs).call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clear_global_notice_if_needed
|
||||||
|
if admin && SiteSetting.has_login_hint
|
||||||
|
SiteSetting.has_login_hint = false
|
||||||
|
SiteSetting.global_notice = ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_user_stat
|
def create_user_stat
|
||||||
stat = UserStat.new(new_since: Time.now)
|
stat = UserStat.new(new_since: Time.now)
|
||||||
stat.user_id = id
|
stat.user_id = id
|
||||||
|
|
|
@ -45,5 +45,9 @@ Discourse::Application.configure do
|
||||||
|
|
||||||
config.enable_anon_caching = false
|
config.enable_anon_caching = false
|
||||||
require 'rbtrace'
|
require 'rbtrace'
|
||||||
|
|
||||||
|
if emails = GlobalSetting.developer_emails
|
||||||
|
config.developer_emails = emails.split(",")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Some sanity checking so we don't count on an unindexed column on boot
|
||||||
|
if User.limit(20).count < 20 && User.where(admin: true).count == 1
|
||||||
|
notice =
|
||||||
|
if GlobalSetting.developer_emails.blank?
|
||||||
|
"No developer email addresses defined, logging in <a href='https://meta.discourse.org/t/how-to-create-an-administrator-account-after-install/14046'>will be tricky.</a>"
|
||||||
|
else
|
||||||
|
emails = GlobalSetting.developer_emails.split(",")
|
||||||
|
if emails.length > 1
|
||||||
|
emails = emails[0..-2].join(' , ') << " or #{emails[-1]} "
|
||||||
|
end
|
||||||
|
"Please create an account or login with #{emails}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if notice != SiteSetting.global_notice
|
||||||
|
SiteSetting.global_notice = notice
|
||||||
|
SiteSetting.has_login_hint = true
|
||||||
|
end
|
||||||
|
|
||||||
|
# we may be booting with no User table eg: first migration, just skip
|
||||||
|
end rescue nil
|
|
@ -479,6 +479,9 @@ uncategorized:
|
||||||
global_notice:
|
global_notice:
|
||||||
default: ""
|
default: ""
|
||||||
client: true
|
client: true
|
||||||
|
has_login_hint:
|
||||||
|
default: false
|
||||||
|
hidden: true
|
||||||
|
|
||||||
# Category IDs
|
# Category IDs
|
||||||
lounge_category_id:
|
lounge_category_id:
|
||||||
|
|
|
@ -78,7 +78,8 @@ class Auth::DefaultCurrentUserProvider
|
||||||
!user.admin &&
|
!user.admin &&
|
||||||
Rails.configuration.respond_to?(:developer_emails) &&
|
Rails.configuration.respond_to?(:developer_emails) &&
|
||||||
Rails.configuration.developer_emails.include?(user.email)
|
Rails.configuration.developer_emails.include?(user.email)
|
||||||
user.update_column(:admin, true)
|
user.admin = true
|
||||||
|
user.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue