Example #1
0
        /// <inheritdoc />
        public async Task AddClaimMappingAsync(IGuildUser user, ClaimMappingType type, AuthorizationClaim claim)
        {
            RequireAuthenticatedUser();
            RequireClaims(AuthorizationClaim.AuthorizationConfigure);

            using (var transaction = await ClaimMappingRepository.BeginCreateTransactionAsync())
            {
                if (await ClaimMappingRepository.AnyAsync(new ClaimMappingSearchCriteria()
                {
                    Types = new[] { type },
                    GuildId = user.Guild.Id,
                    UserId = user.Id,
                    Claims = new[] { claim },
                    IsDeleted = false,
                }))
                {
                    throw new InvalidOperationException($"A claim mapping of type {type} to claim {claim} for user {user.GetFullUsername()} already exists");
                }

                await ClaimMappingRepository.CreateAsync(new ClaimMappingCreationData()
                {
                    GuildId     = user.Guild.Id,
                    Type        = type,
                    UserId      = user.Id,
                    Claim       = claim,
                    CreatedById = CurrentUserId.Value
                });

                transaction.Commit();
            }
        }
Example #2
0
        /// <inheritdoc />
        public async Task RemoveClaimMappingAsync(IRole role, ClaimMappingType type, AuthorizationClaim claim)
        {
            RequireAuthenticatedUser();
            RequireClaims(AuthorizationClaim.AuthorizationConfigure);

            using (var transaction = await ClaimMappingRepository.BeginDeleteTransactionAsync())
            {
                var mappingIds = await ClaimMappingRepository.SearchIdsAsync(new ClaimMappingSearchCriteria()
                {
                    Types     = new[] { type },
                    GuildId   = role.Guild.Id,
                    RoleIds   = new[] { role.Id },
                    Claims    = new[] { claim },
                    IsDeleted = false,
                });

                if (!mappingIds.Any())
                {
                    throw new InvalidOperationException($"A claim mapping of type {type} to claim {claim} for role {role.Name} does not exist");
                }

                await ClaimMappingRepository.TryDeleteAsync(mappingIds.First(), CurrentUserId.Value);

                transaction.Commit();
            }
        }
Example #3
0
 public Task RemoveClaimMapping(
     [Summary("The claim to be removed.")]
     AuthorizationClaim claim,
     [Summary("The type of claim mapping, E.G. granted or denied.")]
     ClaimMappingType type,
     [Summary("The user from which the claim is to be removed.")]
     IGuildUser user)
 => AuthorizationService.RemoveClaimMapping(user, type, claim);
Example #4
0
 public Task RemoveClaimMapping(
     [Summary("The claim to be removed.")]
     AuthorizationClaim claim,
     [Summary("The type of claim mapping, E.G. granted or denied.")]
     ClaimMappingType type,
     [Summary("The role from which the claim is to be removed.")]
     IRole role)
 => AuthorizationService.RemoveClaimMapping(role, type, claim);
Example #5
0
 public Task AddClaimMapping(
     [Summary("The claim to be added.")]
     AuthorizationClaim claim,
     [Summary("The type of claim mapping, E.G. granted or denied.")]
     ClaimMappingType type,
     [Summary("The role to which the claim is to be added.")]
     IRole role)
 => AuthorizationService.AddClaimMapping(role, type, claim);
Example #6
0
 public Task AddClaimMapping(
     [Summary("The claim to be added.")]
     AuthorizationClaim claim,
     [Summary("The type of claim mapping, E.G. granted or denied.")]
     ClaimMappingType type,
     [Summary("The user to which the claim is to be added.")]
     IGuildUser user)
 => AuthorizationService.AddClaimMappingAsync(user, type, claim);
Example #7
0
 public Task RemoveClaimAsync(
     [Summary("Claim to be added")]
     AuthorizationClaim claim,
     [Summary("Access of a claim, whether granted or denied")]
     ClaimMappingType type,
     [Summary("User to add the claim to")]
     IGuildUser user)
 {
     return(_authorizationService.RemoveClaimMappingAsync(user, type, claim));
 }
Example #8
0
 public Task RemoveClaimAsync(
     [Summary("Claim to be removed")]
     AuthorizationClaim claim,
     [Summary("Access of the claim, whether granted or denied")]
     ClaimMappingType type,
     [Summary("Role from which the claim is to be removed")]
     IRole role)
 {
     return(_authorizationService.RemoveClaimMappingAsync(role, type, claim));
 }
Example #9
0
 public Task AddClaimAsync(
     [Summary("Claim to be added")]
     AuthorizationClaim claim,
     [Summary("Access of a claim, whether granted or denied")]
     ClaimMappingType type,
     [Summary("Role which to add the claim to")]
     IRole role)
 {
     return(_authorizationService.AddClaimMappingAsync(role, type, claim));
 }
Example #10
0
        public async Task RemoveClaimMapping(
            [Summary("The claim to be removed.")]
            AuthorizationClaim claim,
            [Summary("The type of claim mapping, E.G. granted or denied.")]
            ClaimMappingType type,
            [Summary("The user from which the claim is to be removed.")]
            IGuildUser user)
        {
            await AuthorizationService.RemoveClaimMappingAsync(user, type, claim);

            await Context.AddConfirmation();
        }
Example #11
0
        public async Task AddClaimMapping(
            [Summary("The claim to be added.")]
            AuthorizationClaim claim,
            [Summary("The type of claim mapping, E.G. granted or denied.")]
            ClaimMappingType type,
            [Summary("The role to which the claim is to be added.")]
            IRole role)
        {
            await AuthorizationService.AddClaimMappingAsync(role, type, claim);

            await Context.AddConfirmation();
        }
        public async Task RemoveClaimAsync(
            [Summary("Claim to be removed")]
            AuthorizationClaim claim,
            [Summary("Access of the claim, whether granted or denied")]
            ClaimMappingType type,
            [Remainder]
            [Summary("Role from which the claim is to be removed")]
            IRole role)
        {
            await _authorizationService.RemoveClaimMappingAsync(role, type, claim);

            await Context.AddConfirmation();
        }
        public async Task AddClaimAsync(
            [Summary("Claim to be added")]
            AuthorizationClaim claim,
            [Summary("Access of a claim, whether granted or denied")]
            ClaimMappingType type,
            [Remainder]
            [Summary("User to add the claim to")]
            IGuildUser user)
        {
            await _authorizationService.AddClaimMappingAsync(user, type, claim);

            await Context.AddConfirmation();
        }
        /// <inheritdoc />
        public async Task RemoveClaimMapping(IGuildUser user, ClaimMappingType type, AuthorizationClaim claim)
        {
            RequireAuthenticatedUser();
            RequireClaims(AuthorizationClaim.AuthorizationConfigure);

            var mappingIds = (await ClaimMappingRepository.SearchIdsAsync(new ClaimMappingSearchCriteria()
            {
                Types = new[] { type },
                GuildId = user.Guild.Id,
                UserId = user.Id,
                Claims = new[] { claim },
                IsDeleted = false,
            }));

            if (!mappingIds.Any())
            {
                throw new InvalidOperationException($"A claim mapping of type {type} to claim {claim} for user {user.GetDisplayName()} does not exist");
            }

            await ClaimMappingRepository.TryDeleteAsync(mappingIds.First(), CurrentUserId.Value);
        }