mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +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();
|
var viewModel = new RoleCreateViewModel();
|
||||||
try {
|
try {
|
||||||
UpdateModel(viewModel);
|
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);
|
_roleService.CreateRole(viewModel.Name);
|
||||||
foreach (string key in Request.Form.Keys) {
|
foreach (string key in Request.Form.Keys) {
|
||||||
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") {
|
||||||
|
|||||||
@@ -15,5 +15,13 @@ namespace Orchard.Roles.Services {
|
|||||||
IEnumerable<string> GetPermissionsForRole(int id);
|
IEnumerable<string> GetPermissionsForRole(int id);
|
||||||
|
|
||||||
IEnumerable<string> GetPermissionsForRoleByName(string name);
|
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) {
|
IEnumerable<string> GetPermissionsForRoleByNameInner(string name) {
|
||||||
var roleRecord = GetRoleByName(name);
|
var roleRecord = GetRoleByName(name);
|
||||||
return roleRecord == null ? Enumerable.Empty<string>() : GetPermissionsForRole(roleRecord.Id);
|
return roleRecord == null ? Enumerable.Empty<string>() : GetPermissionsForRole(roleRecord.Id);
|
||||||
|
|||||||
Reference in New Issue
Block a user