Skip to content

Commit

Permalink
Merge pull request #66 from UpendoVentures/dev
Browse files Browse the repository at this point in the history
Sync dev and main
  • Loading branch information
WillStrohl authored Aug 17, 2023
2 parents b775c65 + 4a7d9a2 commit 59ff6d3
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@
<data name="Disabled.Text" xml:space="preserve">
<value>Disabled</value>
</data>
<data name="GlobalRoles.Text" xml:space="preserve">
<value>Global Roles</value>
</data>
<data name="Pending.Text" xml:space="preserve">
<value>Pending</value>
</data>
<data name="RoleNameExists.Text" xml:space="preserve">
<value>A role with that name already exists</value>
</data>
</root>
30 changes: 28 additions & 2 deletions Modules/UserManager/Controllers/RolesManageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using DotNetNuke.Framework.JavaScriptLibraries;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Localization;
using DotNetNuke.Web.Mvc.Framework.ActionFilters;
using DotNetNuke.Web.Mvc.Framework.Controllers;
using System.Collections.Generic;
using System.Web.Mvc;
using Upendo.Modules.UserManager.Utility;
using Upendo.Modules.UserManager.ViewModels;
Expand All @@ -32,6 +32,7 @@ namespace Upendo.Modules.UserManager.Controllers
public class RolesManageController : DnnController
{
private readonly string ResourceFile = "~/DesktopModules/MVC/Upendo.Modules.UserManager/App_LocalResources/UserManageController.resx";
private readonly string RolesResourceFile = "~/DesktopModules/MVC/Upendo.Modules.UserManager/App_LocalResources/RolesManageController.resx";

public RolesManageController()
{
Expand Down Expand Up @@ -77,6 +78,18 @@ public ActionResult Create()
[HttpPost]
public ActionResult Create(RolesViewModel item)
{
// Check if the RoleName is already in use
var portalId = ModuleContext.PortalId;
var rol = RoleController.Instance.GetRoleByName(portalId, item.RoleName);
if (rol != null)
{
ViewBag.RoleGroups = RolesRepository.GetRoleGroups(portalId);
ViewBag.StatusList = RolesRepository.StatusList();
ViewBag.ErrorMessage = Localization.GetString("RoleNameExists.Text", RolesResourceFile);
return View(item);
}

// If no validation issue, create the role
RolesRepository.CreateRol(item);
return RedirectToAction("Index");
}
Expand All @@ -93,6 +106,19 @@ public ActionResult Edit(int itemId)
[HttpPost]
public ActionResult Edit(RolesViewModel item)
{
// Check if the name has changed and if the new name is already in use
var portalId = ModuleContext.PortalId;
var originalRole = RoleController.Instance.GetRoleById(portalId, item.RoleId);
var existingRole = RoleController.Instance.GetRoleByName(portalId, item.RoleName);
if (originalRole != null && originalRole.RoleName != item.RoleName && existingRole != null)
{
ViewBag.RoleGroups = RolesRepository.GetRoleGroups(portalId);
ViewBag.StatusList = RolesRepository.StatusList();
ViewBag.ErrorMessage = Localization.GetString("RoleNameExists.Text", RolesResourceFile);
return View(item);
}

// If no validation issue, proceed with editing the role
RolesRepository.EditRol(item);
return RedirectToAction("Index");
}
Expand All @@ -111,4 +137,4 @@ public ActionResult Delete(int itemId)
return RedirectToAction("Index");
}
}
}
}
4 changes: 2 additions & 2 deletions Modules/UserManager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("01.00.00")]
[assembly: AssemblyFileVersion("01.00.00")]
[assembly: AssemblyVersion("01.00.01")]
[assembly: AssemblyFileVersion("01.00.01")]
Loading

0 comments on commit 59ff6d3

Please sign in to comment.