diff --git a/src/controllers/api.js b/src/controllers/api.js index ac8201fd7..b4cd45475 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -57,87 +57,6 @@ apiController.reports = apiReportsV1 apiController.settings = apiSettingsV1 apiController.plugins = apiPluginsV1 -apiController.import = function (req, res) { - var fs = require('fs') - var path = require('path') - var UserModal = require('../models/user') - var groupModel = require('../models/group') - - var array = fs - .readFileSync(path.join(__dirname, '..', 'import.csv')) - .toString() - .split('\n') - var clean = array.filter(function (e) { - return e - }) - - async.eachSeries( - clean, - function (item, cb) { - winston.info(item) - - var fields = item.split(',') - var fullname = fields[0].toString().replace('.', ' ') - var k = fullname.split(' ') - var kCap = _.capitalize(k[0]) - var kCap1 = _.capitalize(k[1]) - fullname = kCap + ' ' + kCap1 - - var groupName = fields[2].replace('\\r', '') - groupName = _.trim(groupName) - var User = new UserModal({ - username: fields[0], - password: 'Password123', - email: fields[1], - fullname: fullname, - role: 'user' - }) - - async.series( - [ - function (next) { - User.save(function (err) { - if (err) return next(err) - - next() - }) - }, - function (next) { - winston.debug('Getting Group "' + groupName + '"') - groupModel.getGroupByName(groupName, function (err, group) { - if (err) return next(err) - - if (_.isUndefined(group) || _.isNull(group)) { - return next('no group found = ' + groupName) - } - - group.addMember(User._id, function (err) { - if (err) return next(err) - - group.save(function (err) { - if (err) return next(err) - - next() - }) - }) - }) - } - ], - function (err) { - if (err) return cb(err) - - cb() - } - ) - }, - function (err) { - if (err) return res.status(500).send(err) - - res.status(200).send('Imported ' + _.size(clean)) - } - ) -} - /** * Redirects to login page * @param {object} req Express Request diff --git a/src/socketio/accountImportSocket.js b/src/socketio/accountImportSocket.js index ec4fb34a7..92b46bb08 100644 --- a/src/socketio/accountImportSocket.js +++ b/src/socketio/accountImportSocket.js @@ -288,10 +288,26 @@ events.onImportLDAP = function (socket) { var addedUsers = data.addedUsers var updatedUsers = data.updatedUsers - + var defaultUserRole = null var completedCount = 0 + async.series( [ + function (next) { + var settingSchema = require('../models/setting') + settingSchema.getSetting('role:user:default', function (err, setting) { + if (err || !setting) { + utils.sendToSelf(socket, '$trudesk:accounts:import:error', { + error: 'Default user role not set. Please contact an Administrator.' + }) + + return next('Default user role not set. Please contact an Administrator') + } + + defaultUserRole = setting.value + return next() + }) + }, function (next) { async.eachSeries( addedUsers, @@ -313,7 +329,7 @@ events.onImportLDAP = function (socket) { fullname: lu.displayName, email: lu.mail, title: lu.title, - role: 'user', + role: defaultUserRole, password: 'Password1!' })