/// <inheritdoc /> public async Task AddDesignatedRoleAsync(ulong guildId, ulong roleId, DesignatedRoleType type) { AuthorizationService.RequireAuthenticatedUser(); AuthorizationService.RequireClaims(AuthorizationClaim.DesignatedRoleMappingCreate); using (var transaction = await DesignatedRoleMappingRepository.BeginCreateTransactionAsync()) { if (await DesignatedRoleMappingRepository.AnyAsync(new DesignatedRoleMappingSearchCriteria() { GuildId = guildId, RoleId = roleId, Type = type, IsDeleted = false })) { throw new InvalidOperationException($"Role {roleId} already has a {type} designation"); } await DesignatedRoleMappingRepository.CreateAsync(new DesignatedRoleMappingCreationData() { GuildId = guildId, RoleId = roleId, Type = type, CreatedById = AuthorizationService.CurrentUserId.Value }); transaction.Commit(); } }
public async Task RemoveAsync( [Summary("The role whose designation is to be unassigned")] IRole role, [Summary("The designation to be unassigned")] DesignatedRoleType designation) { await DesignatedRoleService.RemoveDesignatedRoleAsync(role.Guild.Id, role.Id, designation); await Context.AddConfirmation(); }
public async Task AddAsync( [Summary("The role to be assigned a designation")] IRole role, [Summary("The designation to assign")] DesignatedRoleType designation) { await DesignatedRoleService.AddDesignatedRoleAsync(role.Guild.Id, role.Id, designation); await Context.AddConfirmation(); }
public Task <bool> RolesHaveDesignationAsync( ulong guildId, IReadOnlyCollection <ulong> roleIds, DesignatedRoleType designation, CancellationToken cancellationToken) => DesignatedRoleMappingRepository.AnyAsync(new DesignatedRoleMappingSearchCriteria() { GuildId = guildId, RoleIds = roleIds, IsDeleted = false, Type = designation }, default);
public Task <bool> RoleHasDesignationAsync( ulong guildId, ulong roleId, DesignatedRoleType designation, CancellationToken cancellationToken) => DesignatedRoleMappingRepository.AnyAsync(new DesignatedRoleMappingSearchCriteria { GuildId = guildId, RoleId = roleId, IsDeleted = false, Type = designation }, default);
public async Task RoleHasDesignationAsync_Always_ReturnsDesignatedRoleMappingRepositoryAnyAsync( ulong guildId, ulong roleId, DesignatedRoleType designation, bool expectedResult) { using var testContext = new TestContext(); testContext.MockDesignatedRoleMappingRepository .Setup(x => x.AnyAsync(It.IsAny <DesignatedRoleMappingSearchCriteria>(), It.IsAny <CancellationToken>())) .ReturnsAsync(expectedResult); var uut = testContext.BuildUut(); var result = await uut.RoleHasDesignationAsync( guildId, roleId, designation, testContext.CancellationToken); testContext.MockAuthorizationService.Invocations.ShouldBeEmpty(); testContext.MockDesignatedRoleMappingRepository.ShouldHaveReceived(x => x .AnyAsync(It.IsNotNull <DesignatedRoleMappingSearchCriteria>(), It.IsAny <CancellationToken>())); var criteria = testContext.MockDesignatedRoleMappingRepository.Invocations .Where(x => x.Method.Name == nameof(IDesignatedRoleMappingRepository.AnyAsync)) .Select(x => (DesignatedRoleMappingSearchCriteria)x.Arguments[0]) .First(); criteria.GuildId.ShouldBe(guildId); criteria.RoleId.ShouldBe(roleId); criteria.Type.ShouldBe(designation); criteria.IsDeleted.ShouldBe(false); criteria.Id.ShouldBeNull(); criteria.RoleIds.ShouldBeNull(); criteria.CreatedById.ShouldBeNull(); result.ShouldBe(expectedResult); }
/// <inheritdoc /> public async Task RemoveDesignatedRoleAsync(ulong guildId, ulong roleId, DesignatedRoleType type) { AuthorizationService.RequireClaims(AuthorizationClaim.DesignatedRoleMappingDelete); using (var transaction = await DesignatedRoleMappingRepository.BeginDeleteTransactionAsync()) { var deletedCount = await DesignatedRoleMappingRepository.DeleteAsync(new DesignatedRoleMappingSearchCriteria() { GuildId = guildId, RoleId = roleId, Type = type, IsDeleted = false }, AuthorizationService.CurrentUserId.Value); if (deletedCount == 0) { throw new InvalidOperationException($"Role {roleId} does not have a {type} designation"); } transaction.Commit(); } }
public Task RemoveLogRole( [Summary("The role whose designation is to be unassigned")] IRole role, [Summary("The designation to be unassigned")] DesignatedRoleType designation) => DesignatedRoleService.RemoveDesignatedRoleAsync(role.Guild.Id, role.Id, designation);
public Task Add( [Summary("The role to be assigned a designation")] IRole role, [Summary("The designation to assign")] DesignatedRoleType designation) => DesignatedRoleService.AddDesignatedRoleAsync(role.Guild.Id, role.Id, designation);
public async Task <bool> RoleHasDesignationAsync(ulong guildId, ulong roleId, DesignatedRoleType designation) { return((await SearchDesignatedRolesAsync(new DesignatedRoleMappingSearchCriteria { GuildId = guildId, RoleId = roleId, IsDeleted = false, Type = designation })).Any()); }