Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to display search result for users in specific roles #2532

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions DNN Platform/JavaScript Libraries/Selectize/dnn.combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,18 @@
this.$control.find('input.summary').remove();
var $summary = $('<input class="summary" aria-label="Summary" />').prependTo(this.$control);

var options = this.get_options().length;
var items = this.items.length;
var options = this.options;
var items = this.items;
var labels = items.map(function(i) {
return options[i][opts.labelField];
});
var summaryText = "";
if (items === options) {
if (items.length === this.get_options().length) {
summaryText = opts.localization["AllItemsChecked"];
} else if (items === 1) {
summaryText = this.items.join(',');
} else if (items.length === 1) {
summaryText = labels.join(',');
} else {
summaryText = items + ' ' + opts.localization["ItemsChecked"];
summaryText = items.length + ' ' + opts.localization["ItemsChecked"];
}

$summary.val(summaryText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ public override bool HasViewPermission(SearchResult searchResult)

if (searchResult.UniqueKey.Contains("allusers"))
{
var scopeForRoles =
PortalController.GetPortalSetting("SearchResult_ScopeForRoles", searchResult.PortalId, string.Empty)
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();

if (scopeForRoles.Count > 0 && scopeForRoles.All(i => !userInSearchResult.IsInRole(i)))
{
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
<data name="plResultsScopeForPortals.Text" xml:space="preserve">
<value>Results Scope for Site(s)</value>
</data>
<data name="plResultsScopeForRoles.Help" xml:space="preserve">
<value>Limit the search results by selecting the role(s).</value>
</data>
<data name="plResultsScopeForRoles.Text" xml:space="preserve">
<value>Results Scope for Role(s)</value>
</data>
<data name="plShowDescription.Help" xml:space="preserve">
<value>Show Description</value>
</data>
Expand Down
40 changes: 32 additions & 8 deletions Website/DesktopModules/Admin/SearchResults/ResultsSettings.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<asp:RequiredFieldValidator runat="server" ID="filtersRequiredFieldValidator" CssClass="dnnFormMessage dnnFormError" Display="Dynamic"
resourceKey="filtersRequired" ControlToValidate="comboBoxFilters"></asp:RequiredFieldValidator>
</div>

<div class="dnnFormItem" id="scopeForRolesRow">
<dnn:Label ID="plResultsScopeForRoles" runat="server" ControlName="comboBoxRoles" />
<dnn:DnnComboBox ID="comboBoxRoles" runat="server" CheckBoxes="true" Width="437px">
</dnn:DnnComboBox>
</div>

<div class="dnnFormItem">
<dnn:Label ID="plEnableWildSearch" runat="server" ControlName="chkEnableWildSearch" />
Expand Down Expand Up @@ -64,16 +70,34 @@
<script type="text/javascript">
(function($) {
$(document.body).ready(function() {
var $showDescription = $('#<%=chkShowDescription.ClientID%>');
var updateState = function() {
var $maxDescriptionLengthRow = $('#maxDescriptionLengthRow');
$maxDescriptionLengthRow.toggle($showDescription.is(':checked'));
}
(function() {
var $showDescription = $('#<%=chkShowDescription.ClientID%>');
var updateState = function() {
var $maxDescriptionLengthRow = $('#maxDescriptionLengthRow');
$maxDescriptionLengthRow.toggle($showDescription.is(':checked'));
}

updateState();
$showDescription.change(function() {
updateState();
});
})();

(function() {
var $filters = $('#<%=comboBoxFilters.ClientID%>');
var updateState = function() {
var $scopeForRolesRow = $('#scopeForRolesRow');
var usersSelected = $filters.val().toLowerCase().split(',').filter(function(i) {
return i === "users";
}).length > 0;
$scopeForRolesRow.toggle(usersSelected);
}

updateState();
$showDescription.change(function() {
updateState();
});
$filters.change(function() {
updateState();
});
})();
});
})(jQuery);
</script>
14 changes: 14 additions & 0 deletions Website/DesktopModules/Admin/SearchResults/ResultsSettings.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Search.Internals;

Expand Down Expand Up @@ -107,6 +108,16 @@ public override void LoadSettings()
}
}

var scopeForRoles =
PortalController.GetPortalSetting("SearchResult_ScopeForRoles", PortalId, string.Empty)
.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries);
var roles = RoleController.Instance.GetRoles(PortalId, r => !r.IsSystemRole || r.RoleName == "Registered Users");
foreach (var role in roles)
{
var item = new ListItem(role.RoleName, role.RoleName) { Selected = scopeForRoles.Length == 0 || scopeForRoles.Contains(role.RoleName) };
comboBoxRoles.Items.Add(item);
}

chkEnableWildSearch.Checked = GetBooleanSetting("EnableWildSearch", true);
chkShowDescription.Checked = GetBooleanSetting("ShowDescription", true);
chkShowFriendlyTitle.Checked = GetBooleanSetting("ShowFriendlyTitle", true);
Expand Down Expand Up @@ -140,6 +151,9 @@ public override void UpdateSettings()

ModuleController.Instance.UpdateModuleSetting(ModuleId, "ScopeForFilters", selectedFilters.ToString());

var selectedRoles = comboBoxRoles.Value;
PortalController.UpdatePortalSetting(PortalId, "SearchResult_ScopeForRoles", selectedRoles);

ModuleController.Instance.UpdateModuleSetting(ModuleId, "EnableWildSearch", chkEnableWildSearch.Checked.ToString());
ModuleController.Instance.UpdateModuleSetting(ModuleId, "ShowDescription", chkShowDescription.Checked.ToString());
ModuleController.Instance.UpdateModuleSetting(ModuleId, "ShowFriendlyTitle", chkShowFriendlyTitle.Checked.ToString());
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.