mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
fix: #7625, on group rename update nav/widget items
This commit is contained in:
@@ -141,16 +141,7 @@ widgets.getWidgetDataForTemplates = function (templates, callback) {
|
||||
locations.forEach(function (location) {
|
||||
if (templateWidgetData && templateWidgetData[location]) {
|
||||
try {
|
||||
returnData[template][location] = JSON.parse(templateWidgetData[location]);
|
||||
returnData[template][location] = returnData[template][location].map(function (widget) {
|
||||
if (widget) {
|
||||
widget.data.groups = widget.data.groups || [];
|
||||
if (widget.data.groups && !Array.isArray(widget.data.groups)) {
|
||||
widget.data.groups = [widget.data.groups];
|
||||
}
|
||||
}
|
||||
return widget;
|
||||
});
|
||||
returnData[template][location] = parseWidgetData(templateWidgetData[location]);
|
||||
} catch (err) {
|
||||
winston.error('can not parse widget data. template: ' + template + ' location: ' + location);
|
||||
returnData[template][location] = [];
|
||||
@@ -176,7 +167,7 @@ widgets.getArea = function (template, location, callback) {
|
||||
return callback(null, []);
|
||||
}
|
||||
try {
|
||||
result = JSON.parse(result);
|
||||
result = parseWidgetData(result);
|
||||
} catch (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -186,6 +177,19 @@ widgets.getArea = function (template, location, callback) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
function parseWidgetData(data) {
|
||||
const widgets = JSON.parse(data);
|
||||
widgets.forEach(function (widget) {
|
||||
if (widget) {
|
||||
widget.data.groups = widget.data.groups || [];
|
||||
if (widget.data.groups && !Array.isArray(widget.data.groups)) {
|
||||
widget.data.groups = [widget.data.groups];
|
||||
}
|
||||
}
|
||||
});
|
||||
return widgets;
|
||||
}
|
||||
|
||||
widgets.setArea = function (area, callback) {
|
||||
if (!area.location || !area.template) {
|
||||
return callback(new Error('Missing location and template data'));
|
||||
|
||||
Reference in New Issue
Block a user