Commit dc8a0802 authored by Viet Hoang's avatar Viet Hoang

allow to enable/disable

parent d6798485
......@@ -2,14 +2,14 @@
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<vhsXAnalyticsSiteFilterRestriction>
<vhsXAnalyticsSiteFilterRestriction enabled="true">
<superReportViewerRoles>sitecore\Super Report Viewer,sitecore\Master Report</superReportViewerRoles>
<sitesAndReportViewerRoles>
<sites>
<tekcent>sitecore\Tekcent Report Viewer,tekcent\Report Viewer</tekcent>
<Demo>sitecore\Demo Report Viewer,demo\Report Viewer</Demo>
<site1>sitecore\site1 Report Viewer,site1\Report Viewer</site1>
<Site2>sitecore\Site2 Report Viewer,site2\Report Viewer</Site2>
</sites>
</sitesAndReportViewerRoles>
......
......@@ -4,6 +4,18 @@ namespace Vhs.XAnalyticsSiteFilterRestriction.Services
{
public static class ConfigurationService
{
public static bool Enabled
{
get
{
var xmlAttributes = SC.Configuration.Factory.GetConfigNode("vhsXAnalyticsSiteFilterRestriction")
?.Attributes;
if (xmlAttributes == null) return false;
bool enabled;
return bool.TryParse(xmlAttributes["enabled"]?.Value, out enabled);
}
}
public static string SuperReportViewerRoles => SC.Configuration.Factory.GetConfigNode("vhsXAnalyticsSiteFilterRestriction/superReportViewerRoles")
?.InnerXml;
......
......@@ -34,7 +34,10 @@
var renderingId = rendering.ControlId;
var helper = new RenderingHelper(Html, renderingId);
var sites = helper.GetSiteComboBoxItems();
sites = GetSiteListByRoles(sites);
if (ConfigurationService.Enabled)
{
sites = GetSiteListByRoles(sites);
}
helper.MakeBorder("ContentWrapper", renderingId + "DropDownWrapper", contentWrapper =>
{
......@@ -65,17 +68,19 @@ helper.MakeBorder("ContentWrapper", renderingId + "DropDownWrapper", contentWrap
}
var userRoles = Sitecore.Context.User.Roles;
var superReportViewerRoles = ConfigurationService.SuperReportViewerRoles.Split(Separator).ToList();
if (userRoles.Any(x => superReportViewerRoles.Any(y => y.Equals(x.Name, StringComparison.OrdinalIgnoreCase))))
var superReportViewerRoles = ConfigurationService.SuperReportViewerRoles?.Split(Separator).ToList();
if (superReportViewerRoles != null && userRoles.Any(x => superReportViewerRoles.Any(y => y.Equals(x.Name, StringComparison.OrdinalIgnoreCase))))
{
return sites;
}
var allowedSites = new List<ComboBoxItem>();
var sitesAndReportViewerRoleList = ConfigurationService.SitesAndReportViewerRoleList;
if (string.IsNullOrWhiteSpace(sitesAndReportViewerRoleList)) return allowedSites;
var sitesXmlDoc = new XmlDocument();
sitesXmlDoc.LoadXml(sitesAndReportViewerRoleList);
var allowedSites = new List<ComboBoxItem>();
foreach (var site in sites)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment