Skip to content

Commit

Permalink
Merge pull request #41 from Mark-89/feature/IS-38
Browse files Browse the repository at this point in the history
Closes #38
  • Loading branch information
EPTamminga authored Aug 22, 2018
2 parents ad61188 + 4978eae commit e1f71cb
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 126 deletions.
8 changes: 7 additions & 1 deletion App_LocalResources/Settings.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<data name="plSortBy.Text" xml:space="preserve">
<value>Sort by</value>
</data>
<data name="SorByUserName.Text" xml:space="preserve">
<data name="SortByUserName.Text" xml:space="preserve">
<value>Username</value>
</data>
<data name="SortByDisplayName.Text" xml:space="preserve">
Expand All @@ -144,4 +144,10 @@
<data name="plSelectingMethod.Text" xml:space="preserve">
<value>Selecting method</value>
</data>
<data name="Fast.Text" xml:space="preserve">
<value>Fast selecting method</value>
</data>
<data name="Slow.Text" xml:space="preserve">
<value>Slow selecting method</value>
</data>
</root>
6 changes: 6 additions & 0 deletions App_LocalResources/ViewIdentitySwitcher.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,10 @@
<data name="Website.Text" xml:space="preserve">
<value>Website</value>
</data>
<data name="FilterText.Text" xml:space="preserve">
<value>Filter:</value>
</data>
<data name="SwitchToText.Text" xml:space="preserve">
<value>Switch to:</value>
</data>
</root>
32 changes: 17 additions & 15 deletions Components/ModuleInstanceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@

namespace DNN.Modules.IdentitySwitcher.Components
{
using DNN.Modules.IdentitySwitcher.Model;
using DNN.Modules.IdentitySwitcher.ModuleSettings;
using DotNetNuke.Entities.Modules;

/// <summary>
/// </summary>
public class ModuleInstanceBase
Expand All @@ -43,22 +39,28 @@ public class ModuleInstanceBase
public int ModuleID { get; set; }

/// <summary>
/// Gets a value indicating whether [switch user in one click].
/// Gets or sets a value indicating whether [switch user in one click].
/// </summary>
/// <value>
/// <c>true</c> if [switch user in one click]; otherwise, <c>false</c>.
/// </value>
public bool SwitchUserInOneClick
{
get
{
var moduleInfo = new ModuleController().GetModule(this.ModuleID);
var repository = new IdentitySwitcherModuleSettingsRepository();
var settings = repository.GetSettings(moduleInfo);
public bool SwitchUserInOneClick { get; set; }

/// <summary>
/// Gets or sets the filter text.
/// </summary>
/// <value>
/// The filter text.
/// </value>
public string FilterText { get; set; }

return settings.UserSwitchingSpeed == UserSwitchingSpeed.UsingOneClick;
}
}
/// <summary>
/// Gets or sets the switch to text.
/// </summary>
/// <value>
/// The switch to text.
/// </value>
public string SwitchToText { get; set; }

#endregion
}
Expand Down
54 changes: 36 additions & 18 deletions Controllers/IdentitySwitcherController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class IdentitySwitcherController : DnnApiController
/// Gets the search items.
/// </summary>
/// <returns></returns>
[DnnAuthorize]
[AllowAnonymous]
[HttpGet]
public IHttpActionResult GetSearchItems()
{
Expand Down Expand Up @@ -87,29 +87,46 @@ public IHttpActionResult GetSearchItems()
/// </summary>
/// <param name="searchText">The search text.</param>
/// <param name="selectedSearchItem">The selected search item.</param>
/// <param name="onlyDefault">if set to <c>true</c> [only default].</param>
/// <returns></returns>
[DnnAuthorize]
[AllowAnonymous]
[HttpGet]
public IHttpActionResult GetUsers(string searchText = null, string selectedSearchItem = null)
public IHttpActionResult GetUsers(string searchText = null, string selectedSearchItem = null,
bool onlyDefault = false)
{
var result = default(IHttpActionResult);

// Get all users if no searchtext is provided or filtered users if a searchtext is provided.
try
{
var users = searchText == null ? this.GetAllUsers() : this.GetFilteredUsers(searchText, selectedSearchItem);
users = this.SortUsers(users);
this.AddDefaultUsers(users);
var usersInfo = new List<UserInfo>();

var resultData = users.Select(userInfo => new UserDto
// Get only the default users or..
if (!onlyDefault)
{
Id = userInfo.UserID,
UserName = userInfo.Username,
UserAndDisplayName = userInfo.DisplayName != null
? $"{userInfo.DisplayName} - {userInfo.Username}"
: userInfo.Username
})
.ToList();
// ..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);
}

this.AddDefaultUsers(usersInfo);

var selectedUserId = this.UserInfo.UserID;

var resultData = new UserCollectionDto
{
Users = usersInfo.Select(userInfo => new UserDto
{
Id = userInfo.UserID,
UserName = userInfo.Username,
UserAndDisplayName = userInfo.DisplayName != null
? $"{userInfo.DisplayName} - {userInfo.Username}"
: userInfo.Username
})
.ToList(),
SelectedUserId = selectedUserId
};

result = this.Ok(resultData);
}
Expand All @@ -129,7 +146,7 @@ public IHttpActionResult GetUsers(string searchText = null, string selectedSearc
/// <param name="selectedUserId">The selected user identifier.</param>
/// <param name="selectedUserName">Name of the selected user user.</param>
/// <returns></returns>
[DnnAuthorize]
[AllowAnonymous]
[HttpPost]
public IHttpActionResult SwitchUser(int selectedUserId, string selectedUserName)
{
Expand Down Expand Up @@ -197,11 +214,12 @@ private void AddDefaultUsers(List<UserInfo> users)
{
users.Insert(
0,
new UserInfo { Username = hostUser.Username, UserID = hostUser.UserID, DisplayName = null });
new UserInfo {Username = hostUser.Username, UserID = hostUser.UserID, DisplayName = null});
}
}

users.Insert(0, new UserInfo { Username = "Anonymous", DisplayName = null });
users.Insert(0, new UserInfo {Username = "Anonymous", DisplayName = null});

}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions IdentitySwitcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<ItemGroup />
<ItemGroup>
<Compile Include="Controllers\IdentitySwitcherController.cs" />
<Compile Include="Model\UserCollectionDto.cs" />
<Compile Include="ModuleSettings\IdentitySwitcherModuleSettings.cs" />
<Compile Include="ModuleSettings\IdentitySwitcherModuleSettingsRepository.cs" />
<Compile Include="Model\SortBy.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Installation/Project.targets
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@
<!--Copy the files-->
<!-- Uncomment if you are developing in a running DNN site -->

<!--<Copy SourceFiles="@(BinFiles)" DestinationFolder="..\..\bin\" SkipUnchangedFiles="true" ContinueOnError="false" />-->
<Copy SourceFiles="@(BinFiles)" DestinationFolder="..\..\bin\" SkipUnchangedFiles="true" ContinueOnError="false" />

</Target>
</Project>
5 changes: 5 additions & 0 deletions Installation/ReleaseNotes/Release.03.00.00.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
<li>DNNtc.MSBuild structure and attributes build in</li>
<li>Replace all deprecated DNN API calls by new API calls</li>
<li>Replaced UI with new Angular front end construction</li>
</ul>
<h3>NOTES<h3>
<ul>
<li>Tested under 9.2.1 and when placing the module on a page user needs to refresh once to make the module work</li>
<li>Don't place multiple IdentitySwitcher modules on the same page as the module is not configured for this.</li>
</ul>
2 changes: 1 addition & 1 deletion Model/SortBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public enum SortBy
/// <summary>
/// The display name
/// </summary>
DisplayName = 1,
DisplayName,

/// <summary>
/// The user name
Expand Down
38 changes: 38 additions & 0 deletions Model/UserCollectionDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#region Copyright

//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//

#endregion

namespace DNN.Modules.IdentitySwitcher.Model
{
using System.Collections.Generic;
using Newtonsoft.Json;

public class UserCollectionDto
{
[JsonProperty("users")]
public IList<UserDto> Users { get; set; }

[JsonProperty("selectedUserId")]
public int SelectedUserId { get; set; }
}
}
8 changes: 4 additions & 4 deletions Model/UserSwitchingSpeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ namespace DNN.Modules.IdentitySwitcher.Model
public enum UserSwitchingSpeed
{
/// <summary>
/// The using two clicks
/// The fast
/// </summary>
UsingTwoClicks = 1,
Fast,

/// <summary>
/// The using one click
/// The slow
/// </summary>
UsingOneClick
Slow
}
}
4 changes: 2 additions & 2 deletions ModuleSettings/IdentitySwitcherModuleSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace DNN.Modules.IdentitySwitcher.ModuleSettings
public class IdentitySwitcherModuleSettings
{
// The old version of the module used camelcase for the module settings.
// In order to avoid difficulties these properties are kept that way and translated with the paramtwername attribute to
// In order to avoid difficulties these properties are kept that way and translated with the parametername attribute to
// pascalcase.

/// <summary>
Expand Down Expand Up @@ -62,6 +62,6 @@ public class IdentitySwitcherModuleSettings
/// The user switching speed.
/// </value>
[TabModuleSetting(ParameterName = "userSwitchingSpeed")]
public UserSwitchingSpeed UserSwitchingSpeed { get; set; } = UserSwitchingSpeed.UsingTwoClicks;
public UserSwitchingSpeed UserSwitchingSpeed { get; set; } = UserSwitchingSpeed.Fast;
}
}
27 changes: 10 additions & 17 deletions Settings.ascx
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
<%@ Control Language="C#" AutoEventWireup="true" Inherits="DNN.Modules.IdentitySwitcher.Settings" CodeBehind="Settings.ascx.cs" %>
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
<div>
<div id="trHostSettings" runat="server">
<div>
<dnn:label id="plIncludeHostUser" runat="server" controlname="cbIncludeHostUser" suffix=":" />
</div>
<div>
<asp:CheckBox ID="cbIncludeHostUser" runat="server" />
</div>

<asp:Panel runat="server">
<div id="trHostSettings" class="dnnFormItem" runat="server">
<dnn:label id="plIncludeHostUser" runat="server" controlname="cbIncludeHostUser" suffix=":" />
<asp:CheckBox ID="cbIncludeHostUser" runat="server" />
</div>
<div>
<div class="dnnFormItem">
<dnn:label id="plSortBy" runat="server" controlname="rbSortBy" suffix=":" />
</div>
<div>
<asp:RadioButtonList ID="rbSortBy" runat="server" CssClass="Normal" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:RadioButtonList ID="rbSortBy" runat="server" CssClass="Normal" RepeatDirection="Vertical" RepeatLayout="Flow">
</asp:RadioButtonList>
</div>
<div>
<div class="dnnFormItem">
<dnn:label id="plSelectingMethod" runat="server" controlname="rbSelectingMethod" suffix=":" />
</div>
<div>
<asp:RadioButtonList ID="rbSelectingMethod" runat="server" CssClass="Normal" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:RadioButtonList ID="rbSelectingMethod" runat="server" CssClass="Normal" RepeatDirection="Vertical" RepeatLayout="Flow">
</asp:RadioButtonList>
</div>
</div>
</asp:Panel>
28 changes: 9 additions & 19 deletions Settings.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
namespace DNN.Modules.IdentitySwitcher
{
using System;
using System.Resources;
using System.Web.UI.WebControls;
using DNN.Modules.IdentitySwitcher.Model;
using DNN.Modules.IdentitySwitcher.ModuleSettings;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;

/// -----------------------------------------------------------------------------
/// <summary>
Expand All @@ -44,17 +46,6 @@ namespace DNN.Modules.IdentitySwitcher
[DNNtc.ModuleControlProperties("Settings", "IdentitySwitcher Settings", DNNtc.ControlType.Host, "", true, false)]
public partial class Settings : ModuleSettingsBase
{
private void BindEnumToListControls(Type enumType, ListControl listcontrol)
{
var countElements = default(int);
var names = Enum.GetNames(enumType);
var values = Enum.GetValues(enumType);
for (countElements = 0; countElements <= names.Length - 1; countElements++)
{
listcontrol.Items.Add(new ListItem(names[countElements], values.GetValue(countElements).ToString()));
}
}

#region Base Method Implementations

/// -----------------------------------------------------------------------------
Expand All @@ -75,11 +66,11 @@ public override void LoadSettings()
var repository = new IdentitySwitcherModuleSettingsRepository();
var settings = repository.GetSettings(this.ModuleConfiguration);

this.BindEnumToListControls(typeof(SortBy), this.rbSortBy);
this.rbSortBy.SelectedIndex = 0;
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"));

this.BindEnumToListControls(typeof(UserSwitchingSpeed), this.rbSelectingMethod);
this.rbSelectingMethod.SelectedIndex = 0;
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"));

if (this.UserInfo.IsSuperUser)
{
Expand All @@ -92,10 +83,9 @@ public override void LoadSettings()
{
this.trHostSettings.Visible = false;
}

this.rbSortBy.SelectedValue = settings.SortBy.ToString();

this.rbSelectingMethod.SelectedValue = settings.UserSwitchingSpeed.ToString();

this.rbSortBy.SelectedValue = ((int) settings.SortBy).ToString();
this.rbSelectingMethod.SelectedValue = ((int) settings.UserSwitchingSpeed).ToString();
}
}
catch (Exception exception) //Module failed to load
Expand Down
Loading

0 comments on commit e1f71cb

Please sign in to comment.