public ActionResult EditSavePOST(int id) { if (!Services.Authorizer.Authorize(Permissions.ManageRoles, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var viewModel = new RoleEditViewModel(); TryUpdateModel(viewModel); if (String.IsNullOrEmpty(viewModel.Name)) { ModelState.AddModelError("Name", T("Role name can't be empty")); } var role = _roleService.GetRoleByName(viewModel.Name); if (role != null && role.Id != id) { ModelState.AddModelError("Name", T("Role with same name already exists")); } if (!ModelState.IsValid) { return Edit(id); } // Save List<string> rolePermissions = new List<string>(); foreach (string key in Request.Form.Keys) { if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") { string permissionName = key.Substring("Checkbox.".Length); rolePermissions.Add(permissionName); } } _roleService.UpdateRole(viewModel.Id, viewModel.Name, rolePermissions); Services.Notifier.Information(T("Your Role has been saved.")); return RedirectToAction("Edit", new { id }); }
public ActionResult Edit(int id) { if (!Services.Authorizer.Authorize(Permissions.ManageRoles, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var role = _roleService.GetRole(id); if (role == null) { return HttpNotFound(); } var model = new RoleEditViewModel { Name = role.Name, Id = role.Id, RoleCategoryPermissions = _roleService.GetInstalledPermissions(), CurrentPermissions = _roleService.GetPermissionsForRole(id)}; var simulation = UserSimulation.Create(role.Name); model.EffectivePermissions = model.RoleCategoryPermissions .SelectMany(group => group.Value) .Where(permission => _authorizationService.TryCheckAccess(permission, simulation, null)) .Select(permission=>permission.Name) .Distinct() .ToList(); return View(model); }
public ActionResult EditPOST() { if (!Services.Authorizer.Authorize(Permissions.ManageRoles, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var viewModel = new RoleEditViewModel(); try { UpdateModel(viewModel); // Save if (!String.IsNullOrEmpty(HttpContext.Request.Form["submit.Save"])) { List<string> rolePermissions = new List<string>(); foreach (string key in Request.Form.Keys) { if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") { string permissionName = key.Substring("Checkbox.".Length); rolePermissions.Add(permissionName); } } _roleService.UpdateRole(viewModel.Id, viewModel.Name, rolePermissions); } else if (!String.IsNullOrEmpty(HttpContext.Request.Form["submit.Delete"])) { _roleService.DeleteRole(viewModel.Id); } return RedirectToAction("Edit", new { viewModel.Id }); } catch (Exception exception) { Services.Notifier.Error("Editing Role failed: " + exception.Message); return RedirectToAction("Edit", viewModel.Id); } }
public ActionResult Edit(int id) { if (!Services.Authorizer.Authorize(Permissions.ManageRoles, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var role = _roleService.GetRole(id); if (role == null) { //TODO: Error message throw new HttpException(404, "page with id " + id + " was not found"); } var model = new RoleEditViewModel { Name = role.Name, Id = role.Id, ModulePermissions = _roleService.GetInstalledPermissions(), CurrentPermissions = _roleService.GetPermissionsForRole(id)}; var simulation = UserSimulation.Create(role.Name); model.EffectivePermissions = model.ModulePermissions .SelectMany(group => group.Value) .Where(permission => _authorizationService.TryCheckAccess(permission, simulation, null)) .Select(permission=>permission.Name) .Distinct() .ToList(); return View(model); }
public ActionResult EditSavePOST(int id) { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var viewModel = new RoleEditViewModel(); try { UpdateModel(viewModel); // Save List<string> rolePermissions = new List<string>(); foreach (string key in Request.Form.Keys) { if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") { string permissionName = key.Substring("Checkbox.".Length); rolePermissions.Add(permissionName); } } _roleService.UpdateRole(viewModel.Id, viewModel.Name, rolePermissions); Services.Notifier.Information(T("Your Role has been saved.")); return RedirectToAction("Edit", new { id }); } catch (Exception exception) { this.Error(exception, T("Editing Role failed: {0}", exception.Message), Logger, Services.Notifier); return RedirectToAction("Edit", id); } }