Skip to content

Commit

Permalink
Merge pull request #53 from EPTamminga/Issue_52
Browse files Browse the repository at this point in the history
Close #52
  • Loading branch information
EPTamminga authored Aug 2, 2019
2 parents 7dcb5da + 83e991b commit c783118
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 63 deletions.
44 changes: 22 additions & 22 deletions Controllers/IdentitySwitcherController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ public IHttpActionResult GetSearchItems()
var resultData = new List<string>();

var profileProperties =
ProfileController.GetPropertyDefinitionsByPortal(this.PortalSettings.PortalId, false);
ProfileController.GetPropertyDefinitionsByPortal(PortalSettings.PortalId, false);

foreach (ProfilePropertyDefinition definition in profileProperties)
{
resultData.Add(definition.PropertyName);
}
resultData.AddRange(new List<string> { "RoleName", "Email", "Username" });

result = this.Ok(resultData);
result = Ok(resultData);
}
catch (Exception exception)
{
Exceptions.LogException(exception);

result = this.InternalServerError(exception);
result = InternalServerError(exception);
}

return result;
Expand Down Expand Up @@ -105,14 +105,14 @@ public IHttpActionResult GetUsers(string searchText = null, string selectedSearc
{
// ..get all users if no searchtext is provided or filtered users if a searchtext is provided.
usersInfo = searchText == null
? this.GetAllUsers()
: this.GetFilteredUsers(searchText, selectedSearchItem);
usersInfo = this.SortUsers(usersInfo);
? GetAllUsers()
: GetFilteredUsers(searchText, selectedSearchItem);
usersInfo = SortUsers(usersInfo);
}

this.AddDefaultUsers(usersInfo);
AddDefaultUsers(usersInfo);

var selectedUserId = this.UserInfo.UserID;
var selectedUserId = UserInfo.UserID;

var resultData = new UserCollectionDto
{
Expand All @@ -128,13 +128,13 @@ public IHttpActionResult GetUsers(string searchText = null, string selectedSearc
SelectedUserId = selectedUserId
};

result = this.Ok(resultData);
result = Ok(resultData);
}
catch (Exception exception)
{
Exceptions.LogException(exception);

result = this.InternalServerError(exception);
result = InternalServerError(exception);
}

return result;
Expand All @@ -160,25 +160,25 @@ public IHttpActionResult SwitchUser(int selectedUserId, string selectedUserName)
}
else
{
var selectedUser = UserController.GetUserById(this.PortalSettings.PortalId, selectedUserId);
var selectedUser = UserController.GetUserById(PortalSettings.PortalId, selectedUserId);

DataCache.ClearUserCache(this.PortalSettings.PortalId, selectedUserName);
DataCache.ClearUserCache(PortalSettings.PortalId, selectedUserName);

// Sign current user out.
var objPortalSecurity = new PortalSecurity();
objPortalSecurity.SignOut();

// Sign new user in.
UserController.UserLogin(this.PortalSettings.PortalId, selectedUser, this.PortalSettings.PortalName,
UserController.UserLogin(PortalSettings.PortalId, selectedUser, PortalSettings.PortalName,
HttpContext.Current.Request.UserHostAddress, false);
}
result = this.Ok();
result = Ok();
}
catch (Exception exception)
{
Exceptions.LogException(exception);

result = this.InternalServerError(exception);
result = InternalServerError(exception);
}

return result;
Expand All @@ -192,7 +192,7 @@ public IHttpActionResult SwitchUser(int selectedUserId, string selectedUserName)
/// <returns></returns>
private List<UserInfo> GetAllUsers()
{
var users = UserController.GetUsers(this.PortalSettings.PortalId).OfType<UserInfo>().ToList();
var users = UserController.GetUsers(PortalSettings.PortalId).OfType<UserInfo>().ToList();

return users;
}
Expand All @@ -203,7 +203,7 @@ private List<UserInfo> GetAllUsers()
private void AddDefaultUsers(List<UserInfo> users)
{
var repository = new IdentitySwitcherModuleSettingsRepository();
var settings = repository.GetSettings(this.ActiveModule);
var settings = repository.GetSettings(ActiveModule);

// If includehost setting is set to true, add host users to the list.
if (settings.IncludeHost ?? false)
Expand All @@ -228,7 +228,7 @@ private void AddDefaultUsers(List<UserInfo> users)
private List<UserInfo> SortUsers(List<UserInfo> users)
{
var repository = new IdentitySwitcherModuleSettingsRepository();
var settings = repository.GetSettings(this.ActiveModule);
var settings = repository.GetSettings(ActiveModule);

switch (settings.SortBy)
{
Expand Down Expand Up @@ -260,22 +260,22 @@ private List<UserInfo> GetFilteredUsers(string searchText, string selectedSearch
{
case "Email":
users = UserController
.GetUsersByEmail(this.PortalSettings.PortalId, searchText + "%", -1, -1, ref total)
.GetUsersByEmail(PortalSettings.PortalId, searchText + "%", -1, -1, ref total)
.OfType<UserInfo>().ToList();
break;
case "Username":
users = UserController
.GetUsersByUserName(this.PortalSettings.PortalId, searchText + "%", -1, -1, ref total)
.GetUsersByUserName(PortalSettings.PortalId, searchText + "%", -1, -1, ref total)
.OfType<UserInfo>().ToList();
break;
case "RoleName":
users = RoleController
.Instance.GetUsersByRole(this.PortalSettings.PortalId, searchText).ToList();
.Instance.GetUsersByRole(PortalSettings.PortalId, searchText).ToList();
break;

default:
users = UserController
.GetUsersByProfileProperty(this.PortalSettings.PortalId, selectedSearchItem, searchText + "%",
.GetUsersByProfileProperty(PortalSettings.PortalId, selectedSearchItem, searchText + "%",
0, 1000, ref total)
.OfType<UserInfo>().ToList();
break;
Expand Down
4 changes: 3 additions & 1 deletion IdentitySwitcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@
<None Include="Installation\Project.targets">
<SubType>Designer</SubType>
</None>
<Content Include="Installation\CleanUp\Cleanup.03.01.00.txt" />
<Content Include="Installation\CleanUp\Cleanup.03.00.00.txt" />
<Content Include="Installation\ReleaseNotes\Release.03.01.00.txt" />
<Content Include="Installation\ReleaseNotes\Release.03.00.00.txt" />
<Content Include="packages.config">
<SubType>Designer</SubType>
Expand Down Expand Up @@ -200,7 +202,7 @@
<Import Project="$(MSBuildBinPath)/Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
<Import Project="$(MSBuildProjectDirectory)\Installation\Project.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" />
<Import Project="packages\MSBuild.NugetContentRestore.0.1.6\build\net40\MSBuild.NugetContentRestore.targets" Condition="Exists('packages\MSBuild.NugetContentRestore.0.1.6\build\net40\MSBuild.NugetContentRestore.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions Installation/CleanUp/Cleanup.03.01.00.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Install\Module\IdentitySwitcher.03.00.00.Install.zip
5 changes: 3 additions & 2 deletions Installation/IdentitySwitcher.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="IdentitySwitcher" type="Module" version="3.0.0">
<package name="IdentitySwitcher" type="Module" version="3.1.0">
<friendlyName>IdentitySwitcher</friendlyName>
<description>The IdentitySwitcher is a simple and useful tool to allow you to switch between users, without knowing their passwords.</description>
<iconFile>DesktopModules\IdentitySwitcher\IdentitySwitcher.png</iconFile>
Expand All @@ -11,7 +11,7 @@
<email>[email protected]</email>
</owner>
<license src="License.txt"></license>
<releaseNotes src="Release.03.00.00.txt"></releaseNotes>
<releaseNotes src="Release.03.01.00.txt"></releaseNotes>
<azureCompatible>true</azureCompatible>
<dependencies></dependencies>
<components>
Expand Down Expand Up @@ -78,6 +78,7 @@
</resourceFiles>
</component>
<component type="Cleanup" version="03.00.00" fileName="Installation\CleanUp\Cleanup.03.00.00.txt" />
<component type="Cleanup" version="03.01.00" fileName="Installation\CleanUp\Cleanup.03.01.00.txt" />
</components>
</package>
</packages>
Expand Down
2 changes: 1 addition & 1 deletion Installation/License.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DNN-Connect - https://www.dnn-connect.org<br/>
Copyright (c) 2018<br/>
Copyright (c) 2019<br/>
by DNN-Connect
<br/>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
Expand Down
16 changes: 16 additions & 0 deletions Installation/ReleaseNotes/Release.03.01.00.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h2>Release notes Identity Switcher 03.01.00</h2>
<p>Full details on the changes can be found in great detail at <a href="https://github.com/DNN-Connect/IdentitySwitcher" target="_blank">https://github.com/DNN-Connect/IdentitySwitcher</a>.</p>
<h3>BUG FIXES</h3>
<ul>
<li>Corrected handling of users in multiple portals within 1 DNN installation</li>
</ul>
<h3>CHANGES</h3>
<ul>
<li>Code clean-up</li>
<li>Improved UI with new Angular front end construction</li>
</ul>
<h3>NOTES</h3>
<ul>
<li>Tested on DNN 9.3.2 and when placing the module on a page you need to refresh the page at least once to display the module correctly</li>
<li>Don't place multiple IdentitySwitcher modules on the same page as the module is not fit for such a scenario</li>
</ul>
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]
[assembly: AssemblyVersion("3.1.0.0")]
[assembly: AssemblyFileVersion("3.1.0.0")]
36 changes: 18 additions & 18 deletions Settings.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,31 @@ public override void LoadSettings()
{
try
{
if (this.Page.IsPostBack == false)
if (Page.IsPostBack == false)
{
var repository = new IdentitySwitcherModuleSettingsRepository();
var settings = repository.GetSettings(this.ModuleConfiguration);
var settings = repository.GetSettings(ModuleConfiguration);

this.rbSortBy.Items.Add(new ListItem(Localization.GetString("SortByDisplayName.Text", this.LocalResourceFile), "0"));
this.rbSortBy.Items.Add(new ListItem(Localization.GetString("SortByUserName.Text", this.LocalResourceFile), "1"));
rbSortBy.Items.Add(new ListItem(Localization.GetString("SortByDisplayName.Text", LocalResourceFile), "0"));
rbSortBy.Items.Add(new ListItem(Localization.GetString("SortByUserName.Text", LocalResourceFile), "1"));

this.rbSelectingMethod.Items.Add(new ListItem(Localization.GetString("Fast.Text", this.LocalResourceFile), "0"));
this.rbSelectingMethod.Items.Add(new ListItem(Localization.GetString("Slow.Text", this.LocalResourceFile), "1"));
rbSelectingMethod.Items.Add(new ListItem(Localization.GetString("Fast.Text", LocalResourceFile), "0"));
rbSelectingMethod.Items.Add(new ListItem(Localization.GetString("Slow.Text", LocalResourceFile), "1"));

if (this.UserInfo.IsSuperUser)
if (UserInfo.IsSuperUser)
{
if (settings.IncludeHost != null)
{
this.cbIncludeHostUser.Checked = (bool) settings.IncludeHost;
cbIncludeHostUser.Checked = (bool) settings.IncludeHost;
}
}
else
{
this.trHostSettings.Visible = false;
trHostSettings.Visible = false;
}

this.rbSortBy.SelectedValue = ((int) settings.SortBy).ToString();
this.rbSelectingMethod.SelectedValue = ((int) settings.UserSwitchingSpeed).ToString();
rbSortBy.SelectedValue = ((int) settings.SortBy).ToString();
rbSelectingMethod.SelectedValue = ((int) settings.UserSwitchingSpeed).ToString();
}
}
catch (Exception exception) //Module failed to load
Expand All @@ -108,20 +108,20 @@ public override void UpdateSettings()
try
{
var repository = new IdentitySwitcherModuleSettingsRepository();
var settings = repository.GetSettings(this.ModuleConfiguration);
var settings = repository.GetSettings(ModuleConfiguration);

if (this.UserInfo.IsSuperUser)
if (UserInfo.IsSuperUser)
{
settings.IncludeHost = this.cbIncludeHostUser.Checked;
settings.IncludeHost = cbIncludeHostUser.Checked;
}
settings.SortBy = (SortBy) Enum.Parse(typeof(SortBy), this.rbSortBy.SelectedValue);
settings.SortBy = (SortBy) Enum.Parse(typeof(SortBy), rbSortBy.SelectedValue);
settings.UserSwitchingSpeed =
(UserSwitchingSpeed) Enum.Parse(typeof(UserSwitchingSpeed), this.rbSelectingMethod.SelectedValue);
(UserSwitchingSpeed) Enum.Parse(typeof(UserSwitchingSpeed), rbSelectingMethod.SelectedValue);

repository.SaveSettings(this.ModuleConfiguration, settings);
repository.SaveSettings(ModuleConfiguration, settings);

// refresh cache
ModuleController.SynchronizeModule(this.ModuleId);
ModuleController.SynchronizeModule(ModuleId);
}
catch (Exception exception) //Module failed to load
{
Expand Down
34 changes: 17 additions & 17 deletions ViewIdentitySwitcher.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ private string ModuleFolderName
{
get
{
if (string.IsNullOrWhiteSpace(this._moduleFolderName))
if (string.IsNullOrWhiteSpace(_moduleFolderName))
{
this._moduleFolderName =
Path.Combine(Globals.DesktopModulePath, this.ModuleConfiguration.DesktopModule.FolderName);
_moduleFolderName =
Path.Combine(Globals.DesktopModulePath, ModuleConfiguration.DesktopModule.FolderName);
}
return this._moduleFolderName;
return _moduleFolderName;
}
}

Expand All @@ -96,7 +96,7 @@ private string ModuleFolderName
/// <value>
/// The module script folder.
/// </value>
private string ModuleScriptFolder => Path.Combine(this.ModuleFolderName, this.ScriptFolderName);
private string ModuleScriptFolder => Path.Combine(ModuleFolderName, ScriptFolderName);

#endregion

Expand All @@ -110,7 +110,7 @@ private void InitializeModuleInstanceJson(HtmlGenericControl initControl)
if (initControl != null)
{
var initScript = string.Format(CultureInfo.InvariantCulture, "vm.init({0})",
this.GetModuleInstance().ToJson());
GetModuleInstance().ToJson());

initControl.Attributes.Add("ng-init", initScript);
}
Expand All @@ -125,7 +125,7 @@ private void InitializeModuleInstanceJson(HtmlGenericControl initControl)
private void RegisterScript(string folder, string fileName, int priority)
{
var scriptPath = string.IsNullOrWhiteSpace(folder) ? fileName : Path.Combine(folder, fileName);
ClientResourceManager.RegisterScript(this.Page, scriptPath, priority);
ClientResourceManager.RegisterScript(Page, scriptPath, priority);
}

/// <summary>
Expand All @@ -134,7 +134,7 @@ private void RegisterScript(string folder, string fileName, int priority)
/// <returns></returns>
private ModuleInstanceBase GetModuleInstance()
{
return this.GetModuleInstance<ModuleInstanceBase>(this);
return GetModuleInstance<ModuleInstanceBase>(this);
}

/// <summary>
Expand All @@ -152,8 +152,8 @@ private TModuleInstance GetModuleInstance<TModuleInstance>(PortalModuleBase modu
{
result.ModuleID = moduleControl.ModuleId;
result.PortalId = moduleControl.PortalId;
result.FilterText = Localization.GetString("FilterText.Text", this.LocalResourceFile);
result.SwitchToText = Localization.GetString("SwitchToText.Text", this.LocalResourceFile);
result.FilterText = Localization.GetString("FilterText.Text", LocalResourceFile);
result.SwitchToText = Localization.GetString("SwitchToText.Text", LocalResourceFile);

var moduleInfo = new ModuleController().GetModule(moduleControl.ModuleId);
var repository = new IdentitySwitcherModuleSettingsRepository();
Expand All @@ -177,13 +177,13 @@ private void Page_Init(object sender, EventArgs e)
var priority = 0;

//Javascript Resources
var jsFolder = Path.Combine(this.ModuleScriptFolder, ResourcesFolderName);
this.RegisterScript(jsFolder, "angular.min.js", priority++);
this.RegisterScript(jsFolder, "angular-resource.min.js", priority++);
var jsFolder = Path.Combine(ModuleScriptFolder, ResourcesFolderName);
RegisterScript(jsFolder, "angular.min.js", priority++);
RegisterScript(jsFolder, "angular-resource.min.js", priority++);

//Typescript
jsFolder = Path.Combine(this.ModuleScriptFolder, DistributionFolderName);
this.RegisterScript(jsFolder, "dnn.identityswitcher.js", priority++);
jsFolder = Path.Combine(ModuleScriptFolder, DistributionFolderName);
RegisterScript(jsFolder, "dnn.identityswitcher.js", priority++);

}
catch (Exception exception)
Expand All @@ -201,9 +201,9 @@ private void Page_Load(object sender, EventArgs e)
{
try
{
if (!this.Page.IsPostBack)
if (!Page.IsPostBack)
{
this.InitializeModuleInstanceJson(this.divBaseDiv);
InitializeModuleInstanceJson(divBaseDiv);
}
}
catch (Exception exception) //Module failed to load
Expand Down

0 comments on commit c783118

Please sign in to comment.