-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DNN-8833: Added 'DNN Improvement Program" logic and UI elements in co…
…ntrol bar.
- Loading branch information
Showing
16 changed files
with
259 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
DNN Platform/Library/Services/ImprovementsProgram/BeaconService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
DNN Platform/Library/Services/ImprovementsProgram/IBeaconService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
DNN Platform/Library/Services/ImprovementsProgram/RolesEnum.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Website/DesktopModules/Admin/HostSettings/HostSettings.ascx.designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.