2015-10-18 05:32:35 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-07-22 18:56:56 +00:00
|
|
|
// ENiGMA½
|
|
|
|
const { MenuModule } = require('./menu_module.js');
|
|
|
|
const { getUserList } = require('./user.js');
|
|
|
|
const { Errors } = require('./enig_error.js');
|
2015-10-18 05:32:35 +00:00
|
|
|
|
2018-07-22 18:56:56 +00:00
|
|
|
// deps
|
2018-06-23 03:26:46 +00:00
|
|
|
const moment = require('moment');
|
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2015-10-18 05:32:35 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2018-06-23 03:26:46 +00:00
|
|
|
name : 'User List',
|
|
|
|
desc : 'Lists all system users',
|
|
|
|
author : 'NuSkooler',
|
2015-10-18 05:32:35 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const MciViewIds = {
|
2018-07-22 18:56:56 +00:00
|
|
|
userList : 1,
|
2015-10-18 17:48:08 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class UserListModule extends MenuModule {
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
|
|
|
if(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
2018-07-22 18:56:56 +00:00
|
|
|
(next) => {
|
|
|
|
return this.prepViewController('userList', 0, mciData.menu, next);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2018-07-22 18:56:56 +00:00
|
|
|
(next) => {
|
|
|
|
const userListView = this.viewControllers.userList.getView(MciViewIds.userList);
|
|
|
|
if(!userListView) {
|
|
|
|
return cb(Errors.MissingMci(`Missing user list MCI ${MciViewIds.userList}`));
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 18:56:56 +00:00
|
|
|
const fetchOpts = {
|
|
|
|
properties : [ 'real_name', 'location', 'affiliation', 'last_login_timestamp' ],
|
|
|
|
propsCamelCase : true, // e.g. real_name -> realName
|
|
|
|
};
|
|
|
|
getUserList(fetchOpts, (err, userList) => {
|
|
|
|
if(err) {
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const dateTimeFormat = _.get(
|
|
|
|
this, 'menuConfig.config.dateTimeFormat', this.client.currentTheme.helpers.getDateTimeFormat('short'));
|
|
|
|
|
|
|
|
userList = userList.map(entry => {
|
|
|
|
return Object.assign(
|
|
|
|
entry,
|
|
|
|
{
|
|
|
|
text : entry.userName,
|
|
|
|
affils : entry.affiliation,
|
|
|
|
lastLoginTs : moment(entry.lastLoginTimestamp).format(dateTimeFormat),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
userListView.setItems(userList);
|
|
|
|
userListView.redraw();
|
|
|
|
return next(null);
|
|
|
|
});
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
],
|
2018-07-22 18:56:56 +00:00
|
|
|
err => {
|
2018-06-22 05:15:04 +00:00
|
|
|
if(err) {
|
2018-07-22 18:56:56 +00:00
|
|
|
this.client.log.error( { error : err.message }, 'Error loading user list');
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2018-07-22 18:56:56 +00:00
|
|
|
return cb(err);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
};
|