Fix issue: 16313 - Administrator can create two same roles

This commit is contained in:
rukshanperera
2011-02-03 13:28:44 +00:00
parent e47c582001
commit 86c11ada8e
3 changed files with 28 additions and 0 deletions

View File

@@ -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") {

View File

@@ -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);
}
}

View File

@@ -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);