Skip to content

Commit

Permalink
DNN-8833: Added 'DNN Improvement Program" logic and UI elements in co…
Browse files Browse the repository at this point in the history
…ntrol bar.
  • Loading branch information
galatrash committed Aug 11, 2016
1 parent ec7e6da commit fd32f95
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,7 @@ Website/Portals/_default/CK*.xml
Website/Portals/_default/Install/CK*.xml
Website/Portals/_default/Skins/Xcillion/
Website/Portals/_default/Containers/Xcillion/
DNN Platform/Dnn.AuthServices.Jwt/Package/
Website/Portals/_default/Install/Dnn.CKEditorDefaultSettings.xml
Website/Portals/_default/Install/Dnn.CKToolbarButtons.xml
Website/Portals/_default/Install/Dnn.CKToolbarSets.xml
3 changes: 3 additions & 0 deletions DNN Platform/Library/DotNetNuke.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@
<Compile Include="Services\GeneratedImage\StartTransform\PlaceHolderTransform.cs" />
<Compile Include="Services\GeneratedImage\StartTransform\SecureFileTransform.cs" />
<Compile Include="Services\GeneratedImage\StartTransform\UserProfilePicTransform.cs" />
<Compile Include="Services\ImprovementsProgram\BeaconService.cs" />
<Compile Include="Services\ImprovementsProgram\IBeaconService.cs" />
<Compile Include="Services\ImprovementsProgram\RolesEnum.cs" />
<Compile Include="Services\Installer\Blocker\IInstallBlocker.cs" />
<Compile Include="Services\Installer\Blocker\InstallBlocker.cs" />
<Compile Include="Services\Installer\Dependencies\IManagedPackageDependency.cs" />
Expand Down
13 changes: 13 additions & 0 deletions DNN Platform/Library/Entities/Host/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,19 @@ public static bool DebugMode
}
}

/// -----------------------------------------------------------------------------
/// <summary>
/// Gets whether the installation participates in the improvements program.
/// </summary>
/// -----------------------------------------------------------------------------
public static bool ParticipateInImprovementProg
{
get
{
return HostController.Instance.GetBoolean("DNNImprovementProgram", true);
}
}

/// -----------------------------------------------------------------------------
/// <summary>
/// Gets whether a css class based on the Module Name is automatically rendered
Expand Down
117 changes: 117 additions & 0 deletions DNN Platform/Library/Services/ImprovementsProgram/BeaconService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using DotNetNuke.Entities.Host;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;

namespace DotNetNuke.Services.ImprovementsProgram
{
public class BeaconService : ServiceLocator<IBeaconService, BeaconService>, IBeaconService
{
protected override Func<IBeaconService> GetFactory()
{
return () => new BeaconService();
}

private string _beaconEndpoint;
private readonly SHA256 _sha256 = SHA256.Create();

public string GetBeaconEndpoint()
{
if (string.IsNullOrEmpty(_beaconEndpoint))
{
var ep = ConfigurationManager.AppSettings["ImprovementProgram.Epdpoint"];
#if DEBUG
_beaconEndpoint = string.IsNullOrEmpty(ep)
? "https://dev-bcn.dnnapi.com/beacon"
: ep;
#else
_beaconEndpoint = string.IsNullOrEmpty(ep)
? "https://bcn.dnnapi.com/beacon"
: ep;
#endif
}
return _beaconEndpoint;
}

public bool IsBeaconEnabled(UserInfo user)
{
//check for Update Service Opt-in
//check if a host or admin
//check if currently on a host/admin page
var enabled = false;

if (Host.ParticipateInImprovementProg)
{
var roles = GetUserRolesBitValues(user);
var tabPath = TabController.CurrentPage.TabPath;
enabled = (roles & (RolesEnum.Host | RolesEnum.Admin)) != 0 &&
(tabPath.StartsWith("//Admin") || tabPath.StartsWith("//Host"));
}

return enabled;
}

public string GetBeaconQuery(UserInfo user, string filePath = null)
{
var roles = 0;
if (user.UserID >= 0)
{
if (user.IsSuperUser) roles |= (int)RolesEnum.Host;
if (user.IsInRole("Administrators")) roles |= (int)RolesEnum.Admin;
if (user.IsInRole("Content Managers")) roles |= (int)RolesEnum.ContentManager;
if (user.IsInRole("Content Editors")) roles |= (int)RolesEnum.ContentEditor;
if (user.IsInRole("Community Manager")) roles |= (int)RolesEnum.CommunityManager;
}

// h: Host GUID - hashed
// p: Portal ID
// a: Portal Alias
// r: Role(s) - bitmask - Host = 1, Admin = 2, ContentManager=4, ContentEditor=8, CommunityManager=16
// u: UserSession - hashed
// f: filename/path (optional; unused here)

var portalSettings = PortalController.Instance.GetCurrentPortalSettings();
var qparams = new Dictionary<string, string>
{
// Remember to URL ENCODE values that can be ambigious
{"h", HttpUtility.UrlEncode(GetHash(Host.GUID))},
{"p", portalSettings.PortalId.ToString("D")},
{"a", HttpUtility.UrlEncode(portalSettings.PortalAlias.HTTPAlias)},
{"u", HttpUtility.UrlEncode(GetHash(user.UserID.ToString("D")))},
{"r", roles.ToString("D")},
};

if (!string.IsNullOrEmpty(filePath))
qparams["f"] = HttpUtility.UrlEncode(filePath);

return "/log?" + string.Join("&", qparams.Select(kpv => kpv.Key + "=" + kpv.Value));
}

private string GetHash(string data)
{
return Convert.ToBase64String(_sha256.ComputeHash(Encoding.UTF8.GetBytes(data)));
}

private static RolesEnum GetUserRolesBitValues(UserInfo user)
{
var roles = RolesEnum.None;
if (user.UserID >= 0)
{
if (user.IsSuperUser) roles |= RolesEnum.Host;
if (user.IsInRole("Administrators")) roles |= RolesEnum.Admin;
if (user.IsInRole("Content Managers")) roles |= RolesEnum.ContentManager;
if (user.IsInRole("Content Editors")) roles |= RolesEnum.ContentEditor;
if (user.IsInRole("Community Manager")) roles |= RolesEnum.CommunityManager;
}
return roles;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using DotNetNuke.Entities.Users;

namespace DotNetNuke.Services.ImprovementsProgram
{
public interface IBeaconService
{
string GetBeaconEndpoint();
string GetBeaconQuery(UserInfo user, string filePath = null);
bool IsBeaconEnabled(UserInfo user);
}
}
15 changes: 15 additions & 0 deletions DNN Platform/Library/Services/ImprovementsProgram/RolesEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace DotNetNuke.Services.ImprovementsProgram
{
[Flags]
internal enum RolesEnum
{
None = 0,
Host = 1,
Admin = 2,
CommunityManager = 4,
ContentManager = 8,
ContentEditor = 16
}
}
7 changes: 7 additions & 0 deletions DNN Platform/Website/Install/Config/08.00.04.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<configuration>
<nodes configfile="web.config">
<node path="/configuration/appSettings" action="update" key="key" collision="ignore">
<add key="ImprovementProgram.Epdpoint" value="https://bcn.dnnapi.com/beacon" />
</node>
</nodes>
</configuration>
2 changes: 2 additions & 0 deletions DNN_Platform.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Support Projects", "Support Projects", "{1DFA65CE-5978-49F9-83BA-CFBD0C7A1814}"
Expand Down Expand Up @@ -377,6 +378,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{15EE26
DNN Platform\Website\Install\Config\08.00.00.22.config = DNN Platform\Website\Install\Config\08.00.00.22.config
DNN Platform\Website\Install\Config\08.00.00.26.config = DNN Platform\Website\Install\Config\08.00.00.26.config
DNN Platform\Website\Install\Config\08.00.00.30.config = DNN Platform\Website\Install\Config\08.00.00.30.config
DNN Platform\Website\Install\Config\08.00.04.config = DNN Platform\Website\Install\Config\08.00.04.config
DNN Platform\Website\Install\Config\BindingRedirect.config = DNN Platform\Website\Install\Config\BindingRedirect.config
DNN Platform\Website\Install\Config\Net35.config = DNN Platform\Website\Install\Config\Net35.config
DNN Platform\Website\Install\Config\Net40.config = DNN Platform\Website\Install\Config\Net40.config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,12 @@ Both Compacting and Re-Indexing are done by Site Search Crawler scheduled job.
<data name="plDebugMode.Text" xml:space="preserve">
<value>Debug Mode:</value>
</data>
<data name="plImprovementProgram.Help" xml:space="preserve">
<value>Check this box to participate in the DNN Improvement Program. &lt;a href="http://www.dnnsoftware.com/dnn-improvement-program" target="_blank"&gt;See More&lt;/a&gt;.</value>
</data>
<data name="plImprovementProgram.Text" xml:space="preserve">
<value>Participate in DNN Improvement Program:</value>
</data>
<data name="plShowCriticalErrors.Help" xml:space="preserve">
<value>This setting determines if error messages sent via the error querystring parameter should be shown inline in the page.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ private void BindData()
chkAutoSync.Checked = Entities.Host.Host.EnableFileAutoSync;
chkEnableContentLocalization.Checked = Entities.Host.Host.EnableContentLocalization;
chkDebugMode.Checked = Entities.Host.Host.DebugMode;
chkImprovementProgram.Checked = Entities.Host.Host.ParticipateInImprovementProg;
chkCriticalErrors.Checked = Entities.Host.Host.ShowCriticalErrors;
txtBatch.Text = Entities.Host.Host.MessageSchedulerBatchSize.ToString();
txtMaxUploadSize.Text = (Config.GetMaxUploadSize() / (1024 * 1024)).ToString();
Expand Down Expand Up @@ -863,6 +864,7 @@ protected void UpdateSettings(object sender, EventArgs e)
HostController.Instance.Update("HelpURL", txtHelpURL.Text, false);
HostController.Instance.Update("EnableContentLocalization", chkEnableContentLocalization.Checked ? "Y" : "N", false);
HostController.Instance.Update("DebugMode", chkDebugMode.Checked ? "True" : "False", false);
HostController.Instance.Update("DNNImprovementProgram", chkImprovementProgram.Checked ? "True" : "False", false);
HostController.Instance.Update("ShowCriticalErrors", chkCriticalErrors.Checked ? "Y" : "N", true);
HostController.Instance.Update("MessageSchedulerBatchSize", txtBatch.Text, false);
HostController.Instance.Update("UpgradeForceSSL", chkUpgradeForceSSL.Checked ? "Y" : "N", false);
Expand Down

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

4 changes: 4 additions & 0 deletions Website/DesktopModules/Admin/HostSettings/hostsettings.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@
<dnn:label id="plDebugMode" controlname="chkDebugMode" runat="server" />
<asp:CheckBox ID="chkDebugMode" runat="server" />
</div>
<div class="dnnFormItem">
<dnn:label id="plImprovementProgram" controlname="chkImprovementProgram" runat="server" />
<asp:CheckBox ID="chkImprovementProgram" runat="server" />
</div>
<div class="dnnFormItem">
<dnn:label id="plShowCriticalErrors" controlname="chkCriticalErrors" runat="server" />
<asp:CheckBox ID="chkCriticalErrors" runat="server" />
Expand Down
4 changes: 4 additions & 0 deletions Website/admin/ControlPanel/ControlBar.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@
$('a#ControlBar_ViewInPreview').click(function() {
<%=PreviewPopup() %>;
});
<% if (IsBeaconEnabled) { %>
(new Image()).src = "<%= GetBeaconUrl() %>";
<% } %>
});
function openFileUploader() {
Expand Down
Loading

0 comments on commit fd32f95

Please sign in to comment.