Skip to content

Commit

Permalink
Add setting to display search result for users in specific roles (#2532)
Browse files Browse the repository at this point in the history
* DNN-27680: add setting to display search result for users in specific roles.

* DNN-27680: add choice for super users.
  • Loading branch information
zyhfish authored and mitchelsellers committed Apr 9, 2019
1 parent 11a19a4 commit d3d91b1
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 14 deletions.
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,20 @@ 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)
{
if (userInSearchResult.IsSuperUser)
{
return scopeForRoles.Contains("Superusers");
}

return scopeForRoles.Any(i => userInSearchResult.IsInRole(i));
}

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>
16 changes: 16 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,18 @@ 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");
roles.Insert(0, new RoleInfo(){RoleName = "Superusers" });

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 +153,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.

0 comments on commit d3d91b1

Please sign in to comment.