mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 00:15:46 +01:00
feat: #7090, abililty to hide widgets
This commit is contained in:
@@ -8,11 +8,27 @@
|
||||
<br/>
|
||||
<label>Groups:</label>
|
||||
<div>
|
||||
<select name="groups" class="form-control" multiple size="10">
|
||||
<!-- BEGIN groups -->
|
||||
<option value="{groups.displayName}">{groups.displayName}</option>
|
||||
<!-- END groups -->
|
||||
</select>
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li role="presentation" class="active"><a href="#showto" aria-controls="showto" role="tab" data-toggle="tab">Show to</a></li>
|
||||
<li role="presentation"><a href="#hidefrom" aria-controls="hidefrom" role="tab" data-toggle="tab">Hide from</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane active" id="showto">
|
||||
<select name="groups" class="form-control" multiple size="10">
|
||||
<!-- BEGIN groups -->
|
||||
<option value="{groups.displayName}">{groups.displayName}</option>
|
||||
<!-- END groups -->
|
||||
</select>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="hidefrom">
|
||||
<select name="groupsHideFrom" class="form-control" multiple size="10">
|
||||
<!-- BEGIN groups -->
|
||||
<option value="{groups.displayName}">{groups.displayName}</option>
|
||||
<!-- END groups -->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="checkbox">
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user