コード例 #1
0
        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"));
                }
            });
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
        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.");
                }
            });
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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"));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: GuardAppRolesTests.cs プロジェクト: seamys/squidex
        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));
        }
コード例 #9
0
        public async Task <IActionResult> DeleteRole(string app, string roleName)
        {
            var command = new DeleteRole {
                Name = roleName
            };

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
コード例 #10
0
        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."));
        }
コード例 #11
0
ファイル: GuardAppRolesTests.cs プロジェクト: seamys/squidex
        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."));
        }
コード例 #12
0
        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."));
        }
コード例 #13
0
        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"));
            }
        }
コード例 #14
0
        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 = "操作失败" }));
        }
コード例 #15
0
        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));
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        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
            })
                );
        }
コード例 #18
0
 private void DeleteRole(DeleteRole command)
 {
     Raise(command, new AppRoleDeleted());
 }
コード例 #19
0
 public void DeleteRole(DeleteRole command)
 {
     RaiseEvent(SimpleMapper.Map(command, new AppRoleDeleted()));
 }
コード例 #20
0
 public void DeleteRole(DeleteRole command)
 {
     Raise(command, new AppRoleDeleted());
 }
コード例 #21
0
 public void Any(DeleteRole request)
 {
     Repository.Delete <Role>(request.C_Role_Id);
     Repository.InvalidateTreeCountsForPath("cfe-admin-role");
 }
コード例 #22
0
        public void DeleteRole(DeleteRole command)
        {
            var role = roleDatabase.Single(x => x.Id == command.RoleId);

            roleDatabase.Remove(role);
        }
コード例 #23
0
    public static string C2SDeleteRole(string userId, int roleId)
    {
        DeleteRole data = new DeleteRole(userId, roleId);

        return(JsonMapper.ToJson(data));
    }
コード例 #24
0
 public async Task <Unit> DeleteRoleAsync([FromBody] DeleteRole deleteRole)
 {
     return(await _mediator.Send(deleteRole));
 }
コード例 #25
0
        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());
            }
        }