allowGuestSearching config .. second attempt

v1.18.x
akhoury 11 years ago
parent 65d5a6cb81
commit 114294e24a

@ -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'

@ -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));

@ -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>

@ -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="#">

@ -205,6 +205,9 @@ var async = require('async'),
}, {
field: 'allowGuestPosting',
value: 0
}, {
field: 'allowGuestSearching',
value: 0
}, {
field: 'minimumTitleLength',
value: 3

@ -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();

@ -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 {

@ -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');
}

@ -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
}
});
}

Loading…
Cancel
Save