closes #6937
parent
e12a803b16
commit
b6771836cf
@ -1,22 +1,38 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
var navigationAdmin = require('../../navigation/admin');
|
var navigationAdmin = require('../../navigation/admin');
|
||||||
|
const groups = require('../../groups');
|
||||||
|
|
||||||
var navigationController = module.exports;
|
var navigationController = module.exports;
|
||||||
|
|
||||||
navigationController.get = function (req, res, next) {
|
navigationController.get = function (req, res, next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
navigationAdmin.getAdmin,
|
function (next) {
|
||||||
function (data) {
|
async.parallel({
|
||||||
data.enabled.forEach(function (enabled, index) {
|
admin: async.apply(navigationAdmin.getAdmin),
|
||||||
|
groups: async.apply(groups.getNonPrivilegeGroups, 'groups:createtime', 0, -1),
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (result) {
|
||||||
|
result.admin.enabled.forEach(function (enabled, index) {
|
||||||
enabled.index = index;
|
enabled.index = index;
|
||||||
enabled.selected = index === 0;
|
enabled.selected = index === 0;
|
||||||
|
const groupData = _.cloneDeep(result.groups);
|
||||||
|
|
||||||
|
enabled.groups = groupData.map(function (group) {
|
||||||
|
group.selected = enabled.groups.includes(group.name);
|
||||||
|
return group;
|
||||||
|
});
|
||||||
|
|
||||||
|
enabled.groups.sort((a, b) => b.system - a.system);
|
||||||
});
|
});
|
||||||
|
|
||||||
data.navigation = data.enabled.slice();
|
result.admin.navigation = result.admin.enabled.slice();
|
||||||
|
|
||||||
res.render('admin/general/navigation', data);
|
res.render('admin/general/navigation', result.admin);
|
||||||
},
|
},
|
||||||
], next);
|
], next);
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'Navigation item visibility groups',
|
||||||
|
timestamp: Date.UTC(2018, 10, 10),
|
||||||
|
method: function (callback) {
|
||||||
|
const navigationAdmin = require('../../navigation/admin');
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
navigationAdmin.get(next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
data.forEach(function (navItem) {
|
||||||
|
if (navItem) {
|
||||||
|
navItem.groups = [];
|
||||||
|
if (navItem.properties.adminOnly) {
|
||||||
|
navItem.groups.push('administrators');
|
||||||
|
} else if (navItem.properties.globalMod) {
|
||||||
|
navItem.groups.push('Global Moderators');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (navItem.properties.loggedIn) {
|
||||||
|
navItem.groups.push('registered-users');
|
||||||
|
} else if (navItem.properties.guestOnly) {
|
||||||
|
navItem.groups.push('guests');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
navigationAdmin.save(data, next);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
},
|
||||||
|
};
|
@ -0,0 +1,47 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'Widget visibility groups',
|
||||||
|
timestamp: Date.UTC(2018, 10, 10),
|
||||||
|
method: function (callback) {
|
||||||
|
const widgetAdmin = require('../../widgets/admin');
|
||||||
|
const widgets = require('../../widgets');
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
widgetAdmin.get(next);
|
||||||
|
},
|
||||||
|
function (data, next) {
|
||||||
|
async.eachSeries(data.areas, function (area, next) {
|
||||||
|
if (area.data.length) {
|
||||||
|
// area.data is actually an array of widgets
|
||||||
|
area.widgets = area.data;
|
||||||
|
area.widgets.forEach(function (widget) {
|
||||||
|
if (widget && widget.data) {
|
||||||
|
const groupsToShow = ['administrators', 'Global Moderators'];
|
||||||
|
if (widget.data['hide-guests'] !== 'on') {
|
||||||
|
groupsToShow.push('guests');
|
||||||
|
}
|
||||||
|
if (widget.data['hide-registered'] !== 'on') {
|
||||||
|
groupsToShow.push('registered-users');
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.data.groups = groupsToShow;
|
||||||
|
|
||||||
|
// if we are showing to all 4 groups, set to empty array
|
||||||
|
// empty groups is shown to everyone
|
||||||
|
if (groupsToShow.length === 4) {
|
||||||
|
widget.data.groups.length = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
widgets.setArea(area, next);
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue