Skip to content

Node.js based forum software built for the modern web

admin stuff, removed deprecated install templates, blah blah

Julian Lamea8aa3fff240
diff --git a/public/src/forum/admin/footer.js b/public/src/forum/admin/footer.js
index 8a99da7a74..f992abc9c6 100644
--- a/public/src/forum/admin/footer.js
+++ b/public/src/forum/admin/footer.js
@@ -15,28 +15,6 @@ jQuery('document').ready(function() {
}, false);
});
-socket.once('api:config.get', function(config) {
+socket.emit('api:meta.config.get', function(config) {
app.config = config;
});
-
-socket.emit('api:config.get');
-
-socket.on('api:config.set', function(data) {
- if (data.status === 'ok') {
- app.alert({
- alert_id: 'config_status',
- timeout: 2500,
- title: 'Changes Saved',
- message: 'Your changes to the NodeBB configuration have been saved.',
- type: 'success'
- });
- } else {
- app.alert({
- alert_id: 'config_status',
- timeout: 2500,
- title: 'Changes Not Saved',
- message: 'NodeBB encountered a problem saving your changes',
- type: 'danger'
- });
- }
-});
\ No newline at end of file
diff --git a/public/src/forum/admin/index.js b/public/src/forum/admin/index.js
index 96acb81c46..92bfbe2f2c 100644
--- a/public/src/forum/admin/index.js
+++ b/public/src/forum/admin/index.js
@@ -3,7 +3,9 @@ define(function() {
Admin.init = function() {
ajaxify.register_events(['api:get_all_rooms']);
- socket.on('api:get_all_rooms', function(data) {
+
+ app.enterRoom('admin');
+ socket.emit('api:meta.rooms.getAll', function(data) {
var active_users = document.getElementById('active_users'),
total = 0;
@@ -20,9 +22,6 @@ define(function() {
document.getElementById('connections').innerHTML = total;
});
- app.enterRoom('admin');
- socket.emit('api:get_all_rooms');
-
$('#logout-link').on('click', function() {
$.post(RELATIVE_PATH + '/logout', {
_csrf: $('#csrf_token').val()
diff --git a/public/src/forum/admin/settings.js b/public/src/forum/admin/settings.js
index 95cc3c1b9b..aa2ec727e4 100644
--- a/public/src/forum/admin/settings.js
+++ b/public/src/forum/admin/settings.js
@@ -67,9 +67,27 @@ define(['uploader'], function(uploader) {
value = fields[x].value;
}
- socket.emit('api:config.set', {
+ socket.emit('api:meta.config.set', {
key: key,
value: value
+ }, function(data) {
+ if (data.status === 'ok') {
+ app.alert({
+ alert_id: 'config_status',
+ timeout: 2500,
+ title: 'Changes Saved',
+ message: 'Your changes to the NodeBB configuration have been saved.',
+ type: 'success'
+ });
+ } else {
+ app.alert({
+ alert_id: 'config_status',
+ timeout: 2500,
+ title: 'Changes Not Saved',
+ message: 'NodeBB encountered a problem saving your changes',
+ type: 'danger'
+ });
+ }
});
}
});
@@ -98,7 +116,7 @@ define(['uploader'], function(uploader) {
};
Settings.remove = function(key) {
- socket.emit('api:config.remove', key);
+ socket.emit('api:meta.config.remove', key);
};
return Settings;
diff --git a/public/templates/install/basic.tpl b/public/templates/install/basic.tpl
deleted file mode 100644
index 5c3936cefa..0000000000
--- a/public/templates/install/basic.tpl
+++ /dev/null
@@ -1,51 +0,0 @@
-
-<h1>Step 2 &ndash; Basic Information</h1>
-
-<form class="form-inline">
- <h3>Path Information</h3>
- <p>
- Please enter the web-accessible url that will be used to point to the NodeBB installation. If you are using a port number in the address,
- <strong>include it in the field below, not here</strong>. Do not include a trailing slash.<br />
- <input type="text" class="input-large" data-field="base_url" placeholder="http://www.example.org" />
- </p>
-
- <p>
- <label class="checkbox"><input type="checkbox" data-field="use_port" checked /> Use port</label>
- </p>
- <p>
- <label>Port</label> <input type="number" class="input-mini" data-field="port" value="4567" placeholder="4567" />
- </p>
-
- <p>
- Path to uploads folder (relative to the root of the NodeBB install)<br />
- <input type="text" class="input-large" data-field="upload_url" value="/public/uploads" placeholder="/public/uploads" />
- </p>
-</form>
-
-<h3>NodeBB Secret</h3>
-<p>
- This "secret" is used to encode user sessions, so they are not stored in plaintext. Enter a bunch of random characters below:
-</p>
-<input type="text" class="input-xxlarge" data-field="secret" placeholder="n239he#dh9j9$jc4h%y4yuhnx9y(&#y9ryn9c3" />
-
-<hr />
-<div class="pull-right">
- <button data-path="mail" class="btn btn-primary btn-lg">Next &ndash; <i class="fa fa-envelope"></i> Mail</button>
-</div>
-<div>
- <button data-path="redis" class="btn btn-primary btn-lg">Previous &ndash; <i class="fa fa-hdd-o"></i> Redis</button>
-</div>
-
-<script>
- (function() {
- nodebb_setup.prepare();
-
- var portToggle = document.querySelector('input[data-field="use_port"]'),
- portEl = document.querySelector('input[data-field="port"]');
-
- portToggle.addEventListener('change', function(e) {
- if (e.target.checked) portEl.disabled = false;
- else portEl.disabled = true;
- });
- })();
-</script>
\ No newline at end of file
diff --git a/public/templates/install/footer.tpl b/public/templates/install/footer.tpl
deleted file mode 100644
index 8fc558d4c8..0000000000
--- a/public/templates/install/footer.tpl
+++ /dev/null
@@ -1,143 +0,0 @@
-
- </div>
- <script>
- var nodebb_setup = {
- config: undefined,
- prepare: function() {
- // Bounce if config is not ready
- // if (nodebb_setup.config === undefined) {
- // ajaxify.go('install/redis');
- // app.alert({
- // alert_id: 'config-ready',
- // type: 'danger',
- // timeout: 10000,
- // title: 'NodeBB Configuration Not Ready!',
- // message: 'NodeBB cannot proceed with setup at this time as Redis database information ' +
- // 'was not found. Please enter the information below.'
- // });
-
- // return;
- // }
-
- // Come back in 500ms if the config isn't ready yet
- if (nodebb_setup.config === undefined) {
- console.log('Config not ready...');
- setTimeout(function() {
- nodebb_setup.prepare();
- }, 500);
- return;
- }
-
- // Populate the fields on the page from the config
- var fields = document.querySelectorAll('#content [data-field]'),
- numFields = fields.length,
- x, key, inputType;
- for(x=0;x<numFields;x++) {
- key = fields[x].getAttribute('data-field');
- inputType = fields[x].getAttribute('type');
- if (nodebb_setup.config[key]) {
- switch(inputType) {
- case 'text':
- case 'textarea':
- case 'number':
- fields[x].value = nodebb_setup.config[key];
- break;
-
- case 'checkbox':
- fields[x].checked = nodebb_setup.config[key] ? true : false;
- break;
- }
- } else {
- // Save defaults, if they're not found in the config
- var defaultFields = [
- 'use_port', 'port', 'upload_url', 'mailer:host',
- 'mailer:port', 'privileges:manage_content',
- 'privileges:manage_topic'
- ],
- defaultVal;
- if (defaultFields.indexOf(key) !== -1) {
- console.log('saving default value: ', key);
- switch(inputType) {
- case 'text':
- case 'textarea':
- case 'number':
- defaultVal = fields[x].value;
- break;
-
- case 'checkbox':
- defaultVal = fields[x].checked ? '1' : '0';
- break;
- }
- socket.emit('api:config.set', {
- key: key,
- value: defaultVal
- });
- nodebb_setup.config[key] = defaultVal;
- }
- }
- }
- }
- };
-
- (function() {
- // Listen for field changes and auto-save on change
- var contentEl = document.getElementById('content');
-
- contentEl.addEventListener('change', function(e) {
- if (e.target.hasAttribute('data-field')) {
- var key = e.target.getAttribute('data-field'),
- value;
-
- switch(e.target.getAttribute('type')) {
- case 'text':
- case 'textarea':
- case 'number':
- value = e.target.value;
- break;
- case 'checkbox':
- value = e.target.checked ? 1 : 0;
- break;
-
- default:
- return false;
- break;
- }
-
- socket.emit('api:config.set', { key: key, value: value });
- nodebb_setup.config[key] = value;
- }
- }, false);
- contentEl.addEventListener('click', function(e) {
- if (e.target.hasAttribute('data-path')) {
- var href = 'install/' + e.target.getAttribute('data-path');
- if (!e.target.disabled) ajaxify.go(href);
- }
- }, false);
-
- socket.emit('api:config.get');
- socket.on('api:config.get', function(data) {
- nodebb_setup.config = data;
- });
-
- socket.on('api:config.set', function(data) {
- if (data.status === 'ok') {
- app.alert({
- alert_id: 'config_status',
- timeout: 2500,
- title: 'Configuration Saved',
- message: 'Your changes to the NodeBB configuration have been saved',
- type: 'success'
- });
- } else {
- app.alert({
- alert_id: 'config_status',
- timeout: 2500,
- title: 'Configuration Not Saved',
- message: 'NodeBB encountered a problem saving your changes',
- type: 'danger'
- });
- }
- });
- })();
- </script>
-</body>
\ No newline at end of file
diff --git a/public/templates/install/header.tpl b/public/templates/install/header.tpl
deleted file mode 100644
index 5cae4b5e03..0000000000
--- a/public/templates/install/header.tpl
+++ /dev/null
@@ -1,52 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>NodeBB</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="title" CONTENT="NodeBB">
- <meta name="description" content="Node.js/Redis/Socket.io powered forums for a new generation">
- <link href="/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
- <link href="/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
- <link rel="stylesheet" href="/vendor/fontawesome/css/font-awesome.min.css">
- <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
- <script type="text/javascript" src="/vendor/jquery/js/jquery-ui-1.10.3.custom.min.js"></script>
- <script type="text/javascript" src="/vendor/jquery/js/jquery.form.js"></script>
- <script type="text/javascript" src="/vendor/bootstrap/js/bootstrap.min.js"></script>
- <script type="text/javascript" src="/socket.io/socket.io.js"></script>
- <script type="text/javascript" src="/src/app.js"></script>
- <script type="text/javascript" src="/src/templates.js"></script>
- <script type="text/javascript" src="/src/ajaxify.js"></script>
- <script type="text/javascript" src="/src/utils.js"></script>
-
- <link rel="stylesheet" type="text/css" href="/css/style.css" />
-</head>
-
-<body>
- <div class="navbar navbar-inverse navbar-fixed-top">
- <div class="navbar-inner">
- <div class="container">
- <a class="brand" href="/install">NodeBB Installation</a>
- <button type="button" class="btn navbar-btn" data-toggle="collapse" data-target=".nav-collapse">
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <div class="nav-collapse collapse">
- <ul class="nav nodebb-inline-block">
- <li>
- <a data-tab="email" href="/install/email"><i class="fa fa-envelope"></i> Mail</a>
- </li>
- <li>
- <a data-tab="social" href="/install/social"><i class="fa fa-facebook"></i> Social</a>
- </li>
- <li>
- <a data-tab="privileges" href="/install/privileges"><i class="fa fa-gavel"></i> Privileges</a>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div id="alert_window"></div>
-
- <div class="container" id="content">
\ No newline at end of file
diff --git a/public/templates/install/mail.tpl b/public/templates/install/mail.tpl
deleted file mode 100644
index 070c03d111..0000000000
--- a/public/templates/install/mail.tpl
+++ /dev/null
@@ -1,33 +0,0 @@
-
-<h1>Mailer Information</h1>
-
-<form class="form-inline">
- <p>
- The mailer information is used when sending out registration confirmation emails to new users.
- It is also used to send password reset emails to users who have forgotten their password.
- </p>
- <p>
- The defaults here correspond to a local <code>sendmail</code> server, although any third-party
- mail server can be used.
- </p>
- <p>
- <label>Hostname</label> <input type="text" class="input-medium" data-field="mailer:host" value="127.0.0.1" placeholder="127.0.0.1" />
- </p>
- <p>
- <label>Port</label> <input type="number" class="input-mini" data-field="mailer:port" value="25" placeholder="25" />
- </p>
- <p>
- <label>From</label> <input type="text" class="input-large" data-field="mailer:from" placeholder="John Smith <[email protected]>" />
- </p>
-</form>
-
-<hr />
-<div class="pull-right">
- <button data-path="social" class="btn btn-primary btn-lg">Next &ndash; <i class="fa fa-facebook"></i> Social</button>
-</div>
-
-<script>
- (function() {
- nodebb_setup.prepare();
- })();
-</script>
\ No newline at end of file
diff --git a/public/templates/install/privileges.tpl b/public/templates/install/privileges.tpl
deleted file mode 100644
index c54f7cf7f7..0000000000
--- a/public/templates/install/privileges.tpl
+++ /dev/null
@@ -1,45 +0,0 @@
-<h1>User Privilege Thresholds</h1>
-
-<form class="form-inline">
- <p>
- Privilege thresholds grants a community membership the ability to moderate itself.
- These numbers denote the minimum amount of user reputation required before the
- corresponding privilege is unlocked.
- </p>
- <p>
- Reputation is gained when other users favourite posts that you have made.
- </p>
-
- <p>
- <label>Manage Content</label> <input type="number" class="input-mini" value="1000" placeholder="1000" data-field="privileges:manage_content" />
- </p>
- <p>
- Users who reach the "Manage Content" threshold are able to edit/delete other users' posts.
- </p>
- <p>
- <label>Manage Topics</label> <input type="number" class="input-mini" value="2000" placeholder="2000" data-field="privileges:manage_topic" />
- </p>
- <p>
- Users who reach the "Manage Topics" threshold are able to edit, lock, pin, close, and delete topics.
- </p>
-</form>
-
-<hr />
-<div class="pull-right">
- <button id="start-nodebb" class="btn btn-success btn-lg"><i class="fa fa-thumbs-up"></i> Start using NodeBB!</button>
-</div>
-<div>
- <button data-path="social" class="btn btn-primary btn-lg">Previous &ndash; <i class="fa fa-facebook"></i> Social</button>
-</div>
-
-<script>
- (function() {
- nodebb_setup.prepare();
-
- var startEl = document.getElementById('start-nodebb');
- startEl.addEventListener('click', function(e) {
- e.preventDefault();
- document.location.href = '/';
- });
- })();
-</script>
diff --git a/public/templates/install/redis.tpl b/public/templates/install/redis.tpl
deleted file mode 100644
index 5fa4d2a828..0000000000
--- a/public/templates/install/redis.tpl
+++ /dev/null
@@ -1,81 +0,0 @@
-
-<h1>Step 1 &ndash; Establish Redis Connection</h1>
-
-<p class="lead">
- Thanks for choosing to install NodeBB! We&apos;ll need some information to set up your installation
- configuration...
-</p>
-<p>
- Please enter the details of your Redis server here. If redis is hosted on the same
- server as NodeBB, you can leave the default values as-is.
-</p>
-
-<form class="form-horizontal">
- <div class="control-group">
- <label class="control-label" for="redis-hostname">Hostname</label>
- <div class="controls">
- <input type="text" id="redis-hostname" class="input-medium" placeholder="127.0.0.1" value="127.0.0.1" />
- </div>
- </div>
- <div class="control-group">
- <label class="control-label" for="redis-port">Port</label>
- <div class="controls">
- <input type="number" id="redis-port" class="input-mini" placeholder="6379" value="6379" />
- </div>
- </div>
- <div class="control-group">
- <div class="controls">
- <button class="btn" id="test-redis">Test</button>
- </div>
- </div>
-</form>
-
-<hr />
-<div class="pull-right">
- <button data-path="basic" class="btn btn-primary btn-lg" disabled>Next &ndash; <i class="fa fa-cog"></i> Basic</button>
-</div>
-
-<script>
- (function() {
- var testRedisEl = document.getElementById('test-redis');
- testRedisEl.addEventListener('click', function(e) {
- e.preventDefault();
-
- if (e.target.className.indexOf('testing') === -1) {
- e.target.className += ' testing';
- e.target.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Testing';
- socket.once('api:config.redisTest', function(data) {
- if (data && data.status === 'ok') {
- e.target.className = 'btn btn-success testing';
- e.target.innerHTML = 'Redis Connection Successful!';
-
- app.alert({
- type: 'success',
- timeout: 10000,
- alert_id: 'config-ready',
- title: 'Setup Ready!',
- message: 'NodeBB is ready to continue with the setup process. ' +
- 'Any changes you make now will be saved automatically'
- });
-
- // Grab configs from the db and enable the 'next' button
- socket.emit('api:config.setup', {
- 'redis/host': document.getElementById('redis-hostname').value,
- 'redis/port': document.getElementById('redis-port').value
- });
- } else {
- e.target.className = 'btn btn-danger';
- e.target.innerHTML = 'Could not connect to Redis, click here to test again';
- }
- });
- socket.emit('api:config.redisTest');
- }
- });
-
- var nextBtn = document.querySelector('button[data-path="basic"]');
- socket.once('api:config.setup', function(data) {
- nodebb_setup.config = data;
- nextBtn.disabled = false;
- });
- })();
-</script>
diff --git a/public/templates/install/social.tpl b/public/templates/install/social.tpl
deleted file mode 100644
index 6179ca1f35..0000000000
--- a/public/templates/install/social.tpl
+++ /dev/null
@@ -1,47 +0,0 @@
-
-<h1>Social Media Logins</h1>
-
-<form class="form-inline">
- <p>
- You may opt to allow users to register and login in via a social media account, if that
- social network supports doing so.
- </p>
-
- <h3>Facebook</h3>
- <p>
- <label>Application ID</label> <input type="text" class="input-medium" data-field="social:facebook:app_id" />
- </p>
- <p>
- <label>Application Secret</label> <input type="text" class="input-large" data-field="social:facebook:secret" />
- </p>
-
- <h3>Twitter</h3>
- <p>
- <label>Application Key</label> <input type="text" class="input-medium" data-field="social:twitter:key" />
- </p>
- <p>
- <label>Application Secret</label> <input type="text" class="input-large" data-field="social:twitter:secret" />
- </p>
-
- <h3>Google</h3>
- <p>
- <label>Application ID</label> <input type="text" class="input-xxlarge" data-field="social:google:id" />
- </p>
- <p>
- <label>Application Secret</label> <input type="text" class="input-large" data-field="social:google:secret" />
- </p>
-</form>
-
-<hr />
-<div class="pull-right">
- <button data-path="privileges" class="btn btn-primary btn-lg">Next &ndash; <i class="fa fa-gavel"></i> Privileges</button>
-</div>
-<div>
- <button data-path="mail" class="btn btn-primary btn-lg">Previous &ndash; <i class="fa fa-envelope"></i> Mail</button>
-</div>
-
-<script>
- (function() {
- nodebb_setup.prepare();
- })();
-</script>
\ No newline at end of file
diff --git a/src/admin/user.js b/src/admin/user.js
index 8e754ab1a4..1c9453b9fb 100644
--- a/src/admin/user.js
+++ b/src/admin/user.js
@@ -72,6 +72,7 @@ var utils = require('../../public/src/utils'),
user.ban(theirid, function(err, result) {
callback(true);
socket.emit('event:alert', {
+ alert_id: 'ban_user',
title: 'User Banned',
message: 'This user is banned!',
type: 'success',
@@ -88,6 +89,7 @@ var utils = require('../../public/src/utils'),
if (amIAdmin) {
user.unban(theirid, function(err, result) {
socket.emit('event:alert', {
+ alert_id: 'ban_user',
title: 'User Unbanned',
message: 'This user is unbanned!',
type: 'success',
diff --git a/src/socket.io/index.js b/src/socket.io/index.js
index a814d743bf..5723465c25 100644
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@ -150,7 +150,8 @@ Sockets.init = function() {
uid: uid,
socket: socket,
rooms: rooms,
- server: io
+ server: io,
+ userSockets: userSockets
},
socketArgs = [];
diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js
index d774a02a18..732dc072ff 100644
--- a/src/socket.io/meta.js
+++ b/src/socket.io/meta.js
@@ -1,6 +1,9 @@
var meta = require('../meta'),
user = require('../user'),
+ logger = require('../logger'),
+ plugins = require('../plugins'),
+ nconf = require('nconf'),
gravatar = require('gravatar'),
SocketMeta = {};
@@ -69,6 +72,43 @@ SocketMeta.rooms.enter = function(data, sessionData) {
}
};
+SocketMeta.rooms.getAll = function(callback, sessionData) {
+ callback(sessionData.server.sockets.manager.rooms);
+};
+
+/* Config */
+
+SocketMeta.config = {};
+
+SocketMeta.config.get = function(callback, sessionData) {
+ meta.configs.list(function(err, config) {
+ if (!err) {
+ callback(config);
+ }
+ });
+};
+
+SocketMeta.config.set = function(data, callback, sessionData) {
+ meta.configs.set(data.key, data.value, function(err) {
+ if (!err) {
+ callback({
+ status: 'ok'
+ });
+
+ plugins.fireHook('action:config.set', {
+ key: data.key,
+ value: data.value
+ });
+ }
+
+ logger.monitorConfig({io: sessionData.server}, data);
+ });
+};
+
+SocketMeta.config.remove = function(key) {
+ meta.configs.remove(key);
+};
+
/* Exports */
module.exports = SocketMeta;
\ No newline at end of file
diff --git a/src/websockets.js b/src/websockets.js
index 1f0fe0fcc6..a7f8e82025 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -35,9 +35,7 @@ var cookie = require('cookie'),
websockets.init = function(io) {
- socket.on('api:get_all_rooms', function(data) {
- socket.emit('api:get_all_rooms', io.sockets.manager.rooms);
- });
+
@@ -299,32 +297,7 @@ websockets.init = function(io) {
});
});
- socket.on('api:config.get', function(data) {
- meta.configs.list(function(err, config) {
- if (!err) socket.emit('api:config.get', config);
- });
- });
-
- socket.on('api:config.set', function(data) {
- meta.configs.set(data.key, data.value, function(err) {
- if (!err) {
- socket.emit('api:config.set', {
- status: 'ok'
- });
-
- plugins.fireHook('action:config.set', {
- key: data.key,
- value: data.value
- });
- }
- logger.monitorConfig({io: io}, data);
- });
- });
-
- socket.on('api:config.remove', function(key) {
- meta.configs.remove(key);
- });
socket.on('api:composer.push', function(data, callback) {
@@ -389,193 +362,7 @@ websockets.init = function(io) {
});
});
- socket.on('api:admin.topics.getMore', function(data, callback) {
- topics.getAllTopics(data.limit, data.after, function(err, topics) {
- callback(JSON.stringify(topics));
- });
- });
-
- socket.on('api:admin.categories.create', function(data, callback) {
- categories.create(data, function(err, data) {
- callback(err, data);
- });
- });
-
- socket.on('api:admin.categories.update', function(data) {
- admin.categories.update(data, socket);
- });
-
- socket.on('api:admin.user.makeAdmin', function(theirid) {
- if (uid && uid > 0) {
- admin.user.makeAdmin(uid, theirid, socket);
- }
- });
-
- socket.on('api:admin.user.removeAdmin', function(theirid) {
- if (uid && uid > 0) {
- admin.user.removeAdmin(uid, theirid, socket);
- }
- });
-
- socket.on('api:admin.user.createUser', function(user, callback) {
- if (uid && uid > 0) {
- admin.user.createUser(uid, user, callback);
- }
- });
-
- socket.on('api:admin.user.banUser', function(theirid) {
- if (uid && uid > 0) {
- admin.user.banUser(uid, theirid, socket, function(isBanned) {
- if(isBanned) {
- if(userSockets[theirid]) {
- for(var i=0; i<userSockets[theirid].length; ++i) {
- userSockets[theirid][i].emit('event:banned');
- }
- }
- websockets.logoutUser(theirid);
- }
- });
- }
- });
-
- socket.on('api:admin.user.unbanUser', function(theirid) {
- if (uid && uid > 0) {
- admin.user.unbanUser(uid, theirid, socket);
- }
- });
-
- socket.on('api:admin.user.search', function(username, callback) {
- if (!(uid && uid > 0)) {
- return callback();
- }
-
- user.search(username, function(data) {
- function isAdmin(userData, next) {
- user.isAdministrator(userData.uid, function(err, isAdmin) {
- if(err) {
- return next(err);
- }
-
- userData.administrator = isAdmin?'1':'0';
- next();
- });
- }
- async.each(data, isAdmin, function(err) {
- if(err) {
- return callback({message: err.message});
- }
-
- callback(null, data);
- });
- });
- });
-
- socket.on('api:admin.categories.search', function(username, cid, callback) {
- if (uid && uid > 0) {
- user.search(username, function(data) {
- async.map(data, function(userObj, next) {
- CategoryTools.privileges(cid, userObj.uid, function(err, privileges) {
- if (!err) {
- userObj.privileges = privileges;
- } else {
- winston.error('[socket api:admin.categories.search] Could not retrieve permissions');
- }
-
- next(null, userObj);
- });
- }, function(err, data) {
- if (!callback) socket.emit('api:admin.categories.search', data);
- else callback(null, data);
- });
- });
- } else {
- if (!callback) socket.emit('api:admin.user.search', null);
- else callback();
- }
- });
-
- socket.on('api:admin.categories.setPrivilege', function(cid, uid, privilege, set, callback) {
- var cb = function(err) {
- CategoryTools.privileges(cid, uid, callback);
- };
-
- if (set) {
- groups.joinByGroupName('cid:' + cid + ':privileges:' + privilege, uid, cb);
- } else {
- groups.leaveByGroupName('cid:' + cid + ':privileges:' + privilege, uid, cb);
- }
- });
-
- socket.on('api:admin.categories.getPrivilegeSettings', function(cid, callback) {
- async.parallel({
- "+r": function(next) {
- groups.getByGroupName('cid:' + cid + ':privileges:+r', { expand: true }, function(err, groupObj) {
- if (!err) {
- next.apply(this, arguments);
- } else {
- next(null, {
- members: []
- });
- }
- });
- },
- "+w": function(next) {
- groups.getByGroupName('cid:' + cid + ':privileges:+w', { expand: true }, function(err, groupObj) {
- if (!err) {
- next.apply(this, arguments);
- } else {
- next(null, {
- members: []
- });
- }
- });
- }
- }, function(err, data) {
- callback(null, {
- "+r": data['+r'].members,
- "+w": data['+w'].members
- });
- });
- });
-
- socket.on('api:admin.categories.setGroupPrivilege', function(cid, gid, privilege, set, callback) {
- if (set) {
- groups.joinByGroupName('cid:' + cid + ':privileges:' + privilege, gid, callback);
- } else {
- groups.leaveByGroupName('cid:' + cid + ':privileges:' + privilege, gid, callback);
- }
- });
-
- socket.on('api:admin.categories.groupsList', function(cid, callback) {
- groups.list({expand:false}, function(err, data){
- async.map(data, function(groupObj, next) {
- CategoryTools.groupPrivileges(cid, groupObj.gid, function(err, privileges) {
- if (!err) {
- groupObj.privileges = privileges;
- } else {
- winston.error('[socket api:admin.categories.groupsList] Could not retrieve permissions');
- }
-
- next(null, groupObj);
- });
- }, function(err, data) {
- callback(null, data);
- });
- });
- });
-
- socket.on('api:admin.themes.getInstalled', function(callback) {
- meta.themes.get(function(err, themeArr) {
- callback(themeArr);
- });
- });
-
- socket.on('api:admin.plugins.toggle', function(plugin_id) {
- plugins.toggleActive(plugin_id, function(status) {
- socket.emit('api:admin.plugins.toggle', status);
- });
- });