|
|
|
@ -51,13 +51,12 @@ async function renderWidget(widget, uid, options) {
|
|
|
|
|
if (!widget || !widget.data || (!!widget.data['hide-mobile'] && options.req.useragent.isMobile)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let isVisible = true;
|
|
|
|
|
if (widget.data.groups.length) {
|
|
|
|
|
isVisible = await groups.isMemberOfAny(uid, widget.data.groups);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isVisible = await checkVisibility(widget, uid);
|
|
|
|
|
if (!isVisible) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let config = options.res.locals.config || {};
|
|
|
|
|
if (options.res.locals.isAPI) {
|
|
|
|
|
config = await loadConfigAsync(options.req);
|
|
|
|
@ -99,6 +98,18 @@ async function renderWidget(widget, uid, options) {
|
|
|
|
|
return { html: html };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function checkVisibility(widget, uid) {
|
|
|
|
|
let isVisible = true;
|
|
|
|
|
let isHidden = false;
|
|
|
|
|
if (widget.data.groups.length) {
|
|
|
|
|
isVisible = await groups.isMemberOfAny(uid, widget.data.groups);
|
|
|
|
|
}
|
|
|
|
|
if (widget.data.groupsHideFrom.length) {
|
|
|
|
|
isHidden = await groups.isMemberOfAny(uid, widget.data.groupsHideFrom);
|
|
|
|
|
}
|
|
|
|
|
return isVisible && !isHidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widgets.getWidgetDataForTemplates = async function (templates) {
|
|
|
|
|
const keys = templates.map(tpl => 'widgets:' + tpl);
|
|
|
|
|
const data = await db.getObjects(keys);
|
|
|
|
@ -144,6 +155,11 @@ function parseWidgetData(data) {
|
|
|
|
|
if (widget.data.groups && !Array.isArray(widget.data.groups)) {
|
|
|
|
|
widget.data.groups = [widget.data.groups];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widget.data.groupsHideFrom = widget.data.groupsHideFrom || [];
|
|
|
|
|
if (widget.data.groupsHideFrom && !Array.isArray(widget.data.groupsHideFrom)) {
|
|
|
|
|
widget.data.groupsHideFrom = [widget.data.groupsHideFrom];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return widgets;
|
|
|
|
|