public static void CanDelete(Roles roles, DeleteRole command, AppContributors contributors, AppClients clients) { Guard.NotNull(command, nameof(command)); CheckRoleExists(roles, command.Name); Validate.It(e => { if (string.IsNullOrWhiteSpace(command.Name)) { e(Not.Defined(nameof(command.Name)), nameof(command.Name)); } else if (Roles.IsDefault(command.Name)) { e(T.Get("apps.roles.defaultRoleNotRemovable")); } if (clients.Values.Any(x => string.Equals(x.Role, command.Name, StringComparison.OrdinalIgnoreCase))) { e(T.Get("apps.roles.usedRoleByClientsNotRemovable")); } if (contributors.Values.Any(x => string.Equals(x, command.Name, StringComparison.OrdinalIgnoreCase))) { e(T.Get("apps.roles.usedRoleByContributorsNotRemovable")); } }); }
public async Task <IActionResult> DeleteRole(DeleteRole model) { var role = await roleManager.FindByIdAsync(model.Id); if (role == null) { ViewBag.ErrorMessage = $"Role with Id = {model.Id} cannot be found"; return(View("NotFound")); } else { role.Name = model.RoleName; var result = await roleManager.DeleteAsync(role); if (result.Succeeded) { return(RedirectToAction("index")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return(View(model)); } }
public static void CanDelete(Roles roles, DeleteRole command, AppContributors contributors, AppClients clients) { Guard.NotNull(command, nameof(command)); GetRoleOrThrow(roles, command.Name); Validate.It(() => "Cannot delete role.", e => { if (string.IsNullOrWhiteSpace(command.Name)) { e("Name is required.", nameof(command.Name)); } else if (Role.IsDefaultRole(command.Name)) { e("Cannot delete a default role."); } if (clients.Values.Any(x => string.Equals(x.Role, command.Name, StringComparison.OrdinalIgnoreCase))) { e("Cannot remove a role when a client is assigned."); } if (contributors.Values.Any(x => string.Equals(x, command.Name, StringComparison.OrdinalIgnoreCase))) { e("Cannot remove a role when a contributor is assigned."); } }); }
public void DeleteRole_Action_Fails() { // Arrange var roleDto = TestHelper.RoleDto(); GenericServiceResponse <bool> fakeResponse = null; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.RoleService.DeleteRole(roleDto)).Returns(fakeResponse).Verifiable(); var viewModel = new GenericViewModel(); var action = new DeleteRole <GenericViewModel>(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(roleDto); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericViewModel)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 1); Assert.IsTrue(result.HasErrors); Assert.IsNotNull(result.Success); Assert.IsInstanceOfType(result.Success, typeof(bool)); Assert.IsFalse(result.Success); }
public void CanDelete_should_throw_exception_if_role_not_found() { var command = new DeleteRole { Name = roleName }; Assert.Throws <DomainObjectNotFoundException>(() => GuardAppRoles.CanDelete(roles_0, command, contributors, clients)); }
public void CanDelete_should_throw_exception_if_name_empty() { var command = new DeleteRole { Name = null }; ValidationAssert.Throws(() => GuardAppRoles.CanDelete(roles_0, command, contributors, clients), new ValidationError("Name is required.", "Name")); }
public void CanDelete_should_not_throw_exception_if_success() { var roles_1 = roles_0.Add(roleName); var command = new DeleteRole { Name = roleName }; GuardAppRoles.CanDelete(roles_1, command, contributors, clients); }
public void CanDelete_should_not_throw_exception_if_command_is_valid() { var roles_1 = roles_0.Add(roleName); var command = new DeleteRole { Name = roleName }; GuardAppRoles.CanDelete(command, App(roles_1)); }
public async Task <IActionResult> DeleteRole(string app, string roleName) { var command = new DeleteRole { Name = roleName }; var response = await InvokeCommandAsync(command); return(Ok(response)); }
public void CanDelete_should_throw_exception_if_default_role() { var roles_1 = roles_0.Add(Role.Developer); var command = new DeleteRole { Name = Role.Developer }; ValidationAssert.Throws(() => GuardAppRoles.CanDelete(roles_1, command, contributors, clients), new ValidationError("Cannot delete a default role.")); }
public void CanDelete_should_throw_exception_if_client_found() { var roles_1 = roles_0.Add("clientRole"); var command = new DeleteRole { Name = "clientRole" }; ValidationAssert.Throws(() => GuardAppRoles.CanDelete(command, App(roles_1)), new ValidationError("Cannot remove a role when a client is assigned.")); }
public void CanDelete_should_throw_exception_if_client_found() { var roles_1 = roles_0.Add(roleName); var command = new DeleteRole { Name = roleName }; ValidationAssert.Throws(() => GuardAppRoles.CanDelete(roles_1, command, contributors, clients.Add("1", new AppClient("client", "1", roleName))), new ValidationError("Cannot remove a role when a client is assigned.")); }
public async Task <IActionResult> UnlinkRoleOnAllExtensions(string RoleName) { bool?deleted = await DeleteRole.DeleteRoleExtensionsLinksAsync(this.Storage, _roleManager, RoleName); switch (deleted) { case true: return(StatusCode((int)HttpStatusCode.NoContent)); case false: return(StatusCode((int)HttpStatusCode.BadRequest, "Link not deleted, the role is the last Admin grant to SoftinuxBase.Security extension")); default: return(StatusCode((int)HttpStatusCode.BadRequest, "Role or link not found")); } }
public ActionResult DeleteRoleInfo() { int id = DoRequest.GetFormInt("id"); int returnValue = -1; var res = DeleteRole.Do(id); if (res != null && res.Header != null && res.Header.Result != null && res.Header.Result.Code != null) { returnValue = Utils.StrToInt(res.Header.Result.Code, -1); } if (returnValue == 0) { DoCache cache = new DoCache(); cache.RemoveCacheStartsWith("user"); return(Json(new { error = false, message = "操作成功!" })); } return(Json(new { error = true, message = "操作失败" })); }
public async Task <IActionResult> DeleteRole(string id) { var role = await roleManager.FindByIdAsync(id); if (role == null) { ViewBag.ErrorMessage = $"Role with Id = {id} cannot be found"; return(View("NotFound")); } var model = new DeleteRole { Id = role.Id, RoleName = role.Name }; return(View(model)); }
public async Task <IActionResult> DeleteRoleAsync(string roleNameList_) { var errors = new List <string>(); foreach (var role in roleNameList_.Split(new[] { ',' })) { var error = await DeleteRole.DeleteRoleAndAllLinksAsync(this.Storage, _roleManager, role); if (error != null) { errors.Add(error); } } if (errors.Any()) { return(StatusCode((int)HttpStatusCode.BadRequest, errors)); } return(StatusCode((int)HttpStatusCode.OK)); }
public async Task DeleteRole_should_create_events_and_update_state() { var command = new DeleteRole { Name = roleName }; await ExecuteCreateAsync(); await ExecuteAddRoleAsync(); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(0, sut.Snapshot.Roles.CustomCount); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppRoleDeleted { Name = roleName }) ); }
private void DeleteRole(DeleteRole command) { Raise(command, new AppRoleDeleted()); }
public void DeleteRole(DeleteRole command) { RaiseEvent(SimpleMapper.Map(command, new AppRoleDeleted())); }
public void DeleteRole(DeleteRole command) { Raise(command, new AppRoleDeleted()); }
public void Any(DeleteRole request) { Repository.Delete <Role>(request.C_Role_Id); Repository.InvalidateTreeCountsForPath("cfe-admin-role"); }
public void DeleteRole(DeleteRole command) { var role = roleDatabase.Single(x => x.Id == command.RoleId); roleDatabase.Remove(role); }
public static string C2SDeleteRole(string userId, int roleId) { DeleteRole data = new DeleteRole(userId, roleId); return(JsonMapper.ToJson(data)); }
public async Task <Unit> DeleteRoleAsync([FromBody] DeleteRole deleteRole) { return(await _mediator.Send(deleteRole)); }
public async Task DelRole(params string[] args) { SocketRole DeleteRole; if (args.Length == 0) { await ReplyAsync("", false, new EmbedBuilder { Title = "What role?", Description = "Mention the role you wish to delete", Color = Color.Red }.WithCurrentTimestamp()); return; } DeleteRole = GetRole(args[0]); if (DeleteRole == null) { await ReplyAsync("", false, new EmbedBuilder { Title = "What role?", Description = "Mention the role you wish to delete", Color = Color.Red }.WithCurrentTimestamp()); return; } if (Context.Guild.CurrentUser.Roles.All(idk => idk.CompareTo(DeleteRole) < 0)) { await ReplyAsync("", false, new EmbedBuilder { Title = "Hey, thats above me", Description = $"The bot's highest role => {Context.Guild.CurrentUser.Roles.Max().Name}\nThe role you wish to delete => {DeleteRole.Name}", Color = Color.Red }.WithCurrentTimestamp()); return; } if (!(Context.User as SocketGuildUser).Roles.Any(rl => rl.Position > DeleteRole.Position) && Context.Guild.OwnerId != Context.User.Id) { await ReplyAsync("", false, new EmbedBuilder { Title = "Oops!", Description = "You're below the role you want to delete!", Color = Color.Red }.WithCurrentTimestamp()); return; } else { var nm = DeleteRole.Name; await DeleteRole.DeleteAsync(); await ReplyAsync("", false, new EmbedBuilder { Title = $"Role deleted successfully!", Description = $"The role `{nm}` was successfully deleted", Color = Blurple }.WithCurrentTimestamp()); } }