The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/startup/initialData.coffee

52 lines
1.9 KiB

Meteor.startup ->
Meteor.defer ->
# Insert server unique id if it doesn't exist
if not Settings.findOne { _id: 'uniqueID' }
Settings.insert
_id: 'uniqueID'
value: Random.id()
if not ChatRoom.findOne('name': 'general')?
ChatRoom.insert
_id: 'GENERAL'
default: true
usernames: []
ts: new Date()
t: 'c'
name: 'general'
msgs: 0
if process.env.ADMIN_EMAIL? and process.env.ADMIN_PASS?
re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if re.test process.env.ADMIN_EMAIL
if _.isEmpty(RocketChat.authz.getUsersInRole( 'admin' ).fetch())
if not Meteor.users.findOne({ "emails.address": process.env.ADMIN_EMAIL })
console.log 'Inserting admin user'.red
console.log "email: #{process.env.ADMIN_EMAIL} | password: #{process.env.ADMIN_PASS}".red
id = Meteor.users.insert
createdAt: new Date
emails: [
address: process.env.ADMIN_EMAIL
verified: true
],
name: 'Admin'
avatarOrigin: 'none'
Accounts.setPassword id, process.env.ADMIN_PASS
RocketChat.authz.addUsersToRoles( id, 'admin')
else
console.log 'E-mail exists; ignoring environment variables ADMIN_EMAIL and ADMIN_PASS'.red
else
console.log 'Admin user exists; ignoring environment variables ADMIN_EMAIL and ADMIN_PASS'.red
else
console.log 'E-mail provided is invalid; ignoring environment variables ADMIN_EMAIL and ADMIN_PASS'.red
# Set oldest user as admin, if none exists yet
if _.isEmpty( RocketChat.authz.getUsersInRole( 'admin' ).fetch())
# get oldest user
oldestUser = Meteor.users.findOne({}, { fields: { username: 1 }, sort: {createdAt: 1}})
if oldestUser
RocketChat.authz.addUsersToRoles( oldestUser._id, 'admin')
console.log "No admins are found. Set #{oldestUser.username} as admin for being the oldest user"