Skip to content

Node.js based forum software built for the modern web

allowGuestSearching config .. second attempt

akhoury114294e24a64
diff --git a/public/src/app.js b/public/src/app.js
index 837403d906..25cae1c74b 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -80,7 +80,7 @@ var socket,
socket.emit('reconnected');
setTimeout(function() {
- reconnectEl.removeClass('active');
+ reconnectEl.removeClass('active').addClass("hide");
}, 3000);
}
@@ -104,7 +104,7 @@ var socket,
reconnecting = true;
if (!reconnectEl.hasClass('active')) reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>');
- reconnectEl.addClass('active');
+ reconnectEl.addClass('active').removeClass("hide");
reconnectEl.tooltip({
placement: 'bottom'
diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js
index 34e61d8cf0..a16006f319 100644
--- a/public/src/forum/footer.js
+++ b/public/src/forum/footer.js
@@ -1,18 +1,19 @@
-(function() {
+(function($) {
socket.emit('api:updateHeader', {
fields: ['username', 'picture', 'userslug']
});
socket.on('api:updateHeader', function(data) {
- jQuery('#search-button').on('click', function() {
- jQuery('#search-fields').removeClass('hide').show();
- jQuery(this).hide();
- jQuery('#search-fields input').focus()
-
- jQuery('#search-form').on('submit', function() {
- jQuery('#search-fields').hide();
- jQuery('#search-button').show();
+
+ $('#search-button').on('click', function() {
+ $('#search-fields').removeClass('hide').show();
+ $(this).hide();
+ $('#search-fields input').focus();
+
+ $('#search-form').on('submit', function() {
+ $('#search-fields').hide();
+ $('#search-button').show();
});
$('#search-fields input').on('blur', function() {
@@ -22,16 +23,17 @@
});
var loggedInMenu = $('#logged-in-menu'),
- isLoggedIn = data.uid > 0;
+ isLoggedIn = data.uid > 0,
+ allowGuestSearching = (data.config || {}).allowGuestSearching === '1';
if (isLoggedIn) {
- jQuery('.nodebb-loggedin').show();
- jQuery('.nodebb-loggedout').hide();
+ $('.nodebb-loggedin').show();
+ $('.nodebb-loggedout').hide();
$('#logged-out-menu').addClass('hide');
$('#logged-in-menu').removeClass('hide');
- $('#search-button').show();
+ $('#search-button').removeClass("hide").show();
var userLabel = loggedInMenu.find('#user_label');
@@ -46,10 +48,14 @@
$('#logout-link').on('click', app.logout);
}
} else {
- $('#search-button').hide();
+ if (allowGuestSearching) {
+ $('#search-button').removeClass("hide").show();
+ } else {
+ $('#search-button').addClass("hide").hide();
+ }
- jQuery('.nodebb-loggedin').hide();
- jQuery('.nodebb-loggedout').show();
+ $('.nodebb-loggedin').hide();
+ $('.nodebb-loggedout').show();
$('#logged-out-menu').removeClass('hide');
$('#logged-in-menu').addClass('hide');
@@ -264,4 +270,4 @@
require(['mobileMenu'], function(mobileMenu) {
mobileMenu.init();
});
-}());
+}(jQuery));
diff --git a/public/templates/admin/settings.tpl b/public/templates/admin/settings.tpl
index 4a72c95fcc..8c7a0d44e6 100644
--- a/public/templates/admin/settings.tpl
+++ b/public/templates/admin/settings.tpl
@@ -97,6 +97,11 @@
<input type="checkbox" data-field="allowGuestPosting"> <strong>Allow guests to post without logging in</strong>
</label>
</div>
+ <div class="checkbox">
+ <label>
+ <input type="checkbox" data-field="allowGuestSearching"> <strong>Allow guests to search without logging in</strong>
+ </label>
+ </div>
<div class="checkbox">
<label>
<input type="checkbox" data-field="useOutgoingLinksPage"> <strong>Use Outgoing Links Warning Page</strong>
diff --git a/public/templates/header.tpl b/public/templates/header.tpl
index 17d1f98e6d..6a3418a63b 100644
--- a/public/templates/header.tpl
+++ b/public/templates/header.tpl
@@ -74,19 +74,7 @@
<ul id="logged-in-menu" class="nav navbar-nav navbar-right hide">
<li>
- <a href="#" id="reconnect" title="Connection to {title} has been lost, attempting to reconnect..."><i class="fa fa-check"></i></a>
- </li>
-
- <li>
- <form id="search-form" class="navbar-form navbar-right hidden-xs" role="search" method="GET" action="">
- <div class="hide" id="search-fields">
- <div class="form-group">
- <input type="text" class="form-control" placeholder="Search" name="query" value="">
- </div>
- <button type="submit" class="btn btn-default hide">[[global:search]]</button>
- </div>
- <button id="search-button" type="button" class="btn btn-link"><i class="fa fa-search"></i></button>
- </form>
+ <a href="#" id="reconnect" class="hide" title="Connection to {title} has been lost, attempting to reconnect..."><i class="fa fa-check"></i></a>
</li>
<li class="notifications dropdown text-center hidden-xs">
@@ -143,6 +131,20 @@
</li>
</ul>
+ <ul id="logged-conditional-menu" class="nav navbar-nav navbar-right">
+ <li>
+ <form id="search-form" class="navbar-form navbar-right hidden-xs" role="search" method="GET" action="">
+ <div class="hide" id="search-fields">
+ <div class="form-group">
+ <input type="text" class="form-control" placeholder="Search" name="query" value="">
+ </div>
+ <button type="submit" class="btn btn-default hide">[[global:search]]</button>
+ </div>
+ <button id="search-button" type="button" class="btn btn-link hide"><i class="fa fa-search"></i></button>
+ </form>
+ </li>
+ </ul>
+
<ul class="nav navbar-nav navbar-right pagination-block">
<li class="active">
<a href="#">
diff --git a/src/install.js b/src/install.js
index ba59ac4826..e9fef9a3f5 100644
--- a/src/install.js
+++ b/src/install.js
@@ -205,6 +205,9 @@ var async = require('async'),
}, {
field: 'allowGuestPosting',
value: 0
+ }, {
+ field: 'allowGuestSearching',
+ value: 0
}, {
field: 'minimumTitleLength',
value: 3
diff --git a/src/routes/api.js b/src/routes/api.js
index ca0955ccbe..8d4e69e48e 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -222,7 +222,7 @@ var path = require('path'),
});
app.get('/search', function (req, res) {
- if (req.user && req.user.uid) {
+ if ((req.user && req.user.uid) || meta.config.allowGuestSearching === '1') {
return res.json({
show_no_topics: 'hide',
show_no_posts: 'hide',
@@ -273,7 +273,7 @@ var path = require('path'),
});
}
- if (req.user && req.user.uid) {
+ if ((req.user && req.user.uid) || meta.config.allowGuestSearching === '1') {
async.parallel([searchPosts, searchTopics], function (err, results) {
if (err) {
return next();
diff --git a/src/upgrade.js b/src/upgrade.js
index dac9e4a015..e404bd2855 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -12,7 +12,7 @@ var db = require('./database'),
Upgrade.check = function(callback) {
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
- var latestSchema = new Date(2013, 11, 2).getTime();
+ var latestSchema = new Date(2013, 11, 11).getTime();
db.get('schemaDate', function(err, value) {
if (parseInt(value, 10) >= latestSchema) {
@@ -303,6 +303,32 @@ Upgrade.upgradeRedis = function(callback) {
winston.info('[2013/12/2] Update to global keys skipped');
next();
}
+ },
+ function(next) {
+
+ thisSchemaDate = new Date(2013, 11, 11).getTime();
+ if (schemaDate < thisSchemaDate) {
+ updatesMade = true;
+
+ RDB.hmget('config', 'allowGuestSearching', function(err, value) {
+ if(err) {
+ return next(err);
+ }
+
+ if(value[0] === null) {
+ RDB.hset('config', 'allowGuestSearching', '0', function(err){
+ if (err) {
+ return next(err);
+ }
+ winston.info('[2013/12/11] Updated guest search config.');
+ next();
+ });
+ }
+ });
+ } else {
+ winston.info('[2013/12/11] Update to guest search skipped');
+ next();
+ }
}
// Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 12!!!
@@ -333,7 +359,9 @@ Upgrade.upgradeRedis = function(callback) {
};
Upgrade.upgradeMongo = function(callback) {
- var MDB = db.client;
+ // why can't we just use the abstracted db module here? and in upgradeRedis()?
+ var MDB = db.client,
+ updatesMade = false;
winston.info('Beginning Mongo database schema update');
@@ -344,6 +372,32 @@ Upgrade.upgradeMongo = function(callback) {
thisSchemaDate = new Date(2013, 11, 6).getTime();
next();
});
+ },
+ function(next) {
+
+ thisSchemaDate = new Date(2013, 11, 11).getTime();
+ if (schemaDate < thisSchemaDate) {
+ updatesMade = true;
+
+ db.getObjectField('config', 'allowGuestSearching', function(err, value) {
+ if(err) {
+ return next(err);
+ }
+
+ if(!value) {
+ db.setObjectField('config', 'allowGuestSearching', '0', function(err){
+ if (err) {
+ return next(err);
+ }
+ winston.info('[2013/12/11] Updated guest search config.');
+ next();
+ });
+ }
+ });
+ } else {
+ winston.info('[2013/12/11] Update to guest search skipped');
+ next();
+ }
}
// Add new schema updates here
@@ -351,7 +405,11 @@ Upgrade.upgradeMongo = function(callback) {
if (!err) {
db.set('schemaDate', thisSchemaDate, function(err) {
if (!err) {
- winston.info('[upgrade] Mongo schema update complete!');
+ if(updatesMade) {
+ winston.info('[upgrade] Mongo schema update complete!');
+ } else {
+ winston.info('[upgrade] Mongo schema already up to date!');
+ }
if (callback) {
callback(err);
} else {
diff --git a/src/webserver.js b/src/webserver.js
index 15f4d10a6f..1a04bf6860 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -379,7 +379,7 @@ var path = require('path'),
// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
(function () {
var routes = ['login', 'register', 'account', 'recent', '403', '404', '500'],
- loginRequired = ['unread', 'search', 'notifications'];
+ loginRequired = ['unread', 'notifications'];
async.each(routes.concat(loginRequired), function(route, next) {
app.get('/' + route, function (req, res) {
@@ -741,7 +741,7 @@ var path = require('path'),
});
app.get('/search/:term', function (req, res) {
- if (!req.user) {
+ if (!req.user && !meta.config.allowGuestSearching) {
return res.redirect('/403');
}
diff --git a/src/websockets.js b/src/websockets.js
index b7ccb81ee2..5a540c5f24 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -236,7 +236,10 @@ websockets.init = function(io) {
email: '',
picture: gravatar.url('', {
s: '24'
- }, nconf.get('https'))
+ }, nconf.get('https')),
+ config: {
+ allowGuestSearching: meta.config.allowGuestSearching
+ }
});
}