5 // default log level is error
6 // can be changed with `env "logging:level=info" ./scripts/utils/<name of this script>`
7 process.env['logging:level'] = process.env['logging:level'] || 'error';
9 var shutdown = require('shutdown');
10 var userService = require('gitter-web-users');
11 var groupService = require('gitter-web-groups/lib/group-service');
13 require('../../server/event-listeners').install();
15 const opts = require('yargs')
19 description: 'User who is going to be the admin'
24 description: 'Group uri that is going to have a new admin'
27 .alias('help', 'h').argv;
29 const assignAdmin = async () => {
31 const user = await userService.findByUsername(opts.username);
32 if (!user) throw new Error(`user "${opts.username}" hasn't been found`);
33 const group = await groupService.findByUri(opts.groupUri);
34 if (!group) throw new Error(`group ${opts.groupUri} hasn't been found`);
36 group.sd.extraAdmins.push(user._id);
39 console.log(`User ${user.username} with id ${user._id} is now an admin of ${group.uri}`);
41 // wait 5 seconds to allow for asynchronous `event-listeners` to finish
42 // This isn't clean but works
43 // https://github.com/troupe/gitter-webapp/issues/580#issuecomment-147445395
44 // https://gitlab.com/gitterHQ/webapp/merge_requests/1605#note_222861592
45 console.log(`Waiting 5 seconds to allow for the asynchronous \`event-listeners\` to finish...`);
46 await new Promise(resolve => setTimeout(resolve, 5000));
48 shutdown.shutdownGracefully(0);
51 shutdown.shutdownGracefully(1);