mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 03:14:10 +08:00
Fix issue: 16313 - Administrator can create two same roles
This commit is contained in:
@@ -77,6 +77,15 @@ namespace Orchard.Roles.Controllers {
|
||||
var viewModel = new RoleCreateViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel);
|
||||
|
||||
//check if the role name already exists
|
||||
if (!_roleService.VerifyRoleUnicity(viewModel.Name))
|
||||
{
|
||||
Services.Notifier.Error(T("Creating Role failed: {0}", "Role with same name already exists"));
|
||||
|
||||
return RedirectToAction("Create");
|
||||
}
|
||||
|
||||
_roleService.CreateRole(viewModel.Name);
|
||||
foreach (string key in Request.Form.Keys) {
|
||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||
|
@@ -15,5 +15,13 @@ namespace Orchard.Roles.Services {
|
||||
IEnumerable<string> GetPermissionsForRole(int id);
|
||||
|
||||
IEnumerable<string> GetPermissionsForRoleByName(string name);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Verify if the role name is unique
|
||||
/// </summary>
|
||||
/// <param name="name">Role name</param>
|
||||
/// <returns>Returns false if a role with the given name already exits</returns>
|
||||
bool VerifyRoleUnicity(string name);
|
||||
}
|
||||
}
|
@@ -151,6 +151,17 @@ namespace Orchard.Roles.Services {
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify if the role name is unique
|
||||
/// </summary>
|
||||
/// <param name="name">Role name</param>
|
||||
/// <returns>Returns false if a role with the given name already exits</returns>
|
||||
public bool VerifyRoleUnicity(string name)
|
||||
{
|
||||
return _roleRepository.Get(x => x.Name == name) == null ? true : false;
|
||||
}
|
||||
|
||||
|
||||
IEnumerable<string> GetPermissionsForRoleByNameInner(string name) {
|
||||
var roleRecord = GetRoleByName(name);
|
||||
return roleRecord == null ? Enumerable.Empty<string>() : GetPermissionsForRole(roleRecord.Id);
|
||||
|
Reference in New Issue
Block a user