Inform when no users during autoload to take into account removing the last user

This commit is contained in:
Jérémie Astori 2017-08-23 01:11:28 -04:00
parent 90842267e8
commit f221121998
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8
3 changed files with 14 additions and 12 deletions

View File

@ -18,7 +18,7 @@ ClientManager.prototype.init = function(identHandler, sockets) {
this.identHandler = identHandler; this.identHandler = identHandler;
this.webPush = new WebPush(); this.webPush = new WebPush();
if (!Helper.config.public) { if (!Helper.config.public && !Helper.config.ldap.enable) {
if ("autoload" in Helper.config) { if ("autoload" in Helper.config) {
log.warn(`Autoloading users is now always enabled. Please remove the ${colors.yellow("autoload")} option from your configuration file.`); log.warn(`Autoloading users is now always enabled. Please remove the ${colors.yellow("autoload")} option from your configuration file.`);
} }
@ -32,12 +32,23 @@ ClientManager.prototype.findClient = function(name) {
}; };
ClientManager.prototype.autoloadUsers = function() { ClientManager.prototype.autoloadUsers = function() {
this.getUsers().forEach((name) => this.loadUser(name)); const users = this.getUsers();
const noUsersWarning = `There are currently no users. Create one with ${colors.bold("lounge add <name>")}.`;
if (!users.length) {
log.info(noUsersWarning);
}
users.forEach((name) => this.loadUser(name));
fs.watch(Helper.USERS_PATH, _.debounce(() => { fs.watch(Helper.USERS_PATH, _.debounce(() => {
const loaded = this.clients.map((c) => c.name); const loaded = this.clients.map((c) => c.name);
const updatedUsers = this.getUsers(); const updatedUsers = this.getUsers();
if (!updatedUsers.length) {
log.info(noUsersWarning);
}
// New users created since last time users were loaded // New users created since last time users were loaded
_.difference(updatedUsers, loaded).forEach((name) => this.loadUser(name)); _.difference(updatedUsers, loaded).forEach((name) => this.loadUser(name));

View File

@ -12,7 +12,7 @@ program
.action(function() { .action(function() {
var users = new ClientManager().getUsers(); var users = new ClientManager().getUsers();
if (!users.length) { if (!users.length) {
log.warn("No users found."); log.info(`There are currently no users. Create one with ${colors.bold("lounge add <name>")}.`);
} else { } else {
log.info("Users:"); log.info("Users:");
for (var i = 0; i < users.length; i++) { for (var i = 0; i < users.length; i++) {

View File

@ -1,8 +1,6 @@
"use strict"; "use strict";
var ClientManager = new require("../clientManager");
var program = require("commander"); var program = require("commander");
var colors = require("colors/safe");
var server = require("../server"); var server = require("../server");
var Helper = require("../helper"); var Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
@ -17,8 +15,6 @@ program
.description("Start the server") .description("Start the server")
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp)
.action(function(options) { .action(function(options) {
var users = new ClientManager().getUsers();
var mode = Helper.config.public; var mode = Helper.config.public;
if (options.public) { if (options.public) {
mode = true; mode = true;
@ -26,11 +22,6 @@ program
mode = false; mode = false;
} }
if (!mode && !users.length && !Helper.config.ldap.enable) {
log.warn("No users found.");
log.info(`Create a new user with ${colors.bold("lounge add <name>")}.`);
}
Helper.config.host = options.host || Helper.config.host; Helper.config.host = options.host || Helper.config.host;
Helper.config.port = options.port || Helper.config.port; Helper.config.port = options.port || Helper.config.port;
Helper.config.bind = options.bind || Helper.config.bind; Helper.config.bind = options.bind || Helper.config.bind;