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/migrations/v19.coffee

28 lines
1.1 KiB

Meteor.startup ->
Migrations.add
version: 19
up: ->
###
# Migrate existing admin users to Role based admin functionality
# 'admin' role applies to global scope
###
admins = Meteor.users.find({ admin: true }, { fields: { _id: 1, username:1 } }).fetch()
RocketChat.authz.addUsersToRoles( _.pluck(admins, '_id'), ['admin'])
Meteor.users.update({}, { $unset :{admin:''}}, {multi:true})
usernames = _.pluck( admins, 'username').join(', ')
console.log "Migrate #{usernames} from admin field to 'admin' role".green
# Add 'user' role to all users
users = Meteor.users.find().fetch()
RocketChat.authz.addUsersToRoles( _.pluck(users, '_id'), ['user'])
usernames = _.pluck( users, 'username').join(', ')
console.log "Add #{usernames} to 'user' role".green
# Add 'moderator' role to channel/group creators
rooms = RocketChat.models.Rooms.findByTypes(['c','p']).fetch()
_.each( rooms, (room) ->
creator = room?.u?._id
if creator
RocketChat.authz.addUsersToRoles( creator, ['moderator'], room._id)
console.log "Add #{room.u.username} to 'moderator' role".green
)