Skip to content

Instantly share code, notes, and snippets.

@barisusakli
Created October 12, 2016 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barisusakli/731bd32d43462f891fa3397d956efb5f to your computer and use it in GitHub Desktop.
Save barisusakli/731bd32d43462f891fa3397d956efb5f to your computer and use it in GitHub Desktop.
create global moderators group if it doesn't exist and show it
'use strict';
/*globals require, console, process */
var nconf = require('nconf');
var async = require('async');
var winston = require('winston');
nconf.file({
file: 'config.json'
});
var db = require('./src/database');
db.init(function(err) {
if (err) {
console.log('NodeBB could not connect to your database. returned the following error: ' + err.message);
process.exit();
}
createGlobalModeratorsGroup(function(err) {
if (err) {
console.log(err.message);
process.exit();
}
console.log('group created');
process.exit();
});
});
function createGlobalModeratorsGroup(next) {
var groups = require('./src/groups');
async.waterfall([
function (next) {
groups.exists('Global Moderators', next);
},
function (exists, next) {
if (exists) {
winston.info('Global Moderators group found, skipping creation!');
return next(null, null);
}
groups.create({
name: 'Global Moderators',
userTitle: 'Global Moderator',
description: 'Forum wide moderators',
hidden: 0,
private: 1,
disableJoinRequests: 1
}, next);
},
function (groupData, next) {
groups.show('Global Moderators', next);
}
], next);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment