/// <inheritdoc /> public async Task DeleteInfractionAsync(long infractionId) { AuthorizationService.RequireAuthenticatedUser(); AuthorizationService.RequireClaims(AuthorizationClaim.ModerationDelete); var infraction = await InfractionRepository.ReadSummaryAsync(infractionId); if (infraction == null) { throw new InvalidOperationException($"Infraction {infractionId} does not exist"); } await InfractionRepository.TryDeleteAsync(infraction.Id, AuthorizationService.CurrentUserId.Value); var guild = await GuildService.GetGuildAsync(infraction.GuildId); var subject = await UserService.GetGuildUserAsync(guild.Id, infraction.Subject.Id); switch (infraction.Type) { case InfractionType.Mute: await subject.RemoveRoleAsync( await GetOrCreateMuteRoleInGuildAsync(guild)); break; case InfractionType.Ban: await guild.RemoveBanAsync(subject); break; } }
public async Task <bool> UpdateInfractionAsync(long infractionId, string newReason, ulong currentUserId) { var infraction = await InfractionRepository.ReadSummaryAsync(infractionId); var editCutoff = DateTimeOffset.Now.AddDays(-1); if (infraction.CreateAction.Created <= editCutoff) { return(false); } AuthorizationService.RequireClaims(_createInfractionClaimsByType[infraction.Type]); // Allow users who created the infraction to bypass any further // validation and update their own infraction if (infraction.CreateAction.CreatedBy.Id == currentUserId) { return(await InfractionRepository.TryUpdateAync(infractionId, newReason, currentUserId)); } // Else we know it's not the user's infraction AuthorizationService.RequireClaims(AuthorizationClaim.ModerationUpdateInfraction); return(await InfractionRepository.TryUpdateAync(infractionId, newReason, currentUserId)); }
/// <inheritdoc /> public async Task RescindInfractionAsync(long infractionId) { AuthorizationService.RequireAuthenticatedUser(); AuthorizationService.RequireClaims(AuthorizationClaim.ModerationRescind); await DoRescindInfractionAsync( await InfractionRepository.ReadSummaryAsync(infractionId)); }
/// <inheritdoc /> public async Task RescindInfractionAsync(long infractionId, string reason = null, bool isAutoRescind = false) { AuthorizationService.RequireAuthenticatedUser(); AuthorizationService.RequireClaims(AuthorizationClaim.ModerationRescind); await DoRescindInfractionAsync( await InfractionRepository.ReadSummaryAsync(infractionId), reason, isAutoRescind); }
/// <inheritdoc /> public async Task <ServiceResult> RescindInfractionAsync(long infractionId, bool isAutoRescind = false) { var authResult = AuthorizationService.CheckClaims(AuthorizationClaim.ModerationRescind); if (authResult.IsFailure) { return(authResult); } await DoRescindInfractionAsync( await InfractionRepository.ReadSummaryAsync(infractionId), isAutoRescind); return(ServiceResult.FromSuccess()); }
/// <inheritdoc /> public async Task DeleteInfractionAsync(long infractionId) { AuthorizationService.RequireAuthenticatedUser(); AuthorizationService.RequireClaims(AuthorizationClaim.ModerationDeleteInfraction); var infraction = await InfractionRepository.ReadSummaryAsync(infractionId); if (infraction == null) { throw new InvalidOperationException($"Infraction {infractionId} does not exist"); } await RequireSubjectRankLowerThanModeratorRankAsync(infraction.GuildId, AuthorizationService.CurrentUserId.Value, infraction.Subject.Id); await InfractionRepository.TryDeleteAsync(infraction.Id, AuthorizationService.CurrentUserId.Value); var guild = await DiscordClient.GetGuildAsync(infraction.GuildId); switch (infraction.Type) { case InfractionType.Mute: if (await UserService.GuildUserExistsAsync(guild.Id, infraction.Subject.Id)) { var subject = await UserService.GetGuildUserAsync(guild.Id, infraction.Subject.Id); await subject.RemoveRoleAsync(await GetDesignatedMuteRoleAsync(guild)); } else { Log.Warning("Tried to unmute {User} while deleting mute infraction, but they weren't in the guild: {Guild}", infraction.Subject.Id, guild.Id); } break; case InfractionType.Ban: //If the infraction has already been rescinded, we don't need to actually perform the unmute/unban //Doing so will return a 404 from Discord (trying to remove a nonexistant ban) if (infraction.RescindAction == null) { await guild.RemoveBanAsync(infraction.Subject.Id); } break; } }
/// <inheritdoc /> public async Task <ServiceResult> DeleteInfractionAsync(long infractionId) { var authResult = AuthorizationService.CheckClaims(AuthorizationClaim.ModerationDeleteInfraction); if (authResult.IsFailure) { return(authResult); } var infraction = await InfractionRepository.ReadSummaryAsync(infractionId); if (infraction == null) { return(ServiceResult.FromError($"Infraction {infractionId} does not exist")); } var rankResult = await RequireSubjectRankLowerThanModeratorRankAsync(AuthorizationService.CurrentGuildId.Value, infraction.Subject.Id); if (rankResult.IsFailure) { return(rankResult); } await InfractionRepository.TryDeleteAsync(infraction.Id, AuthorizationService.CurrentUserId.Value); var guild = await DiscordClient.GetGuildAsync(infraction.GuildId); var subject = await UserService.GetGuildUserAsync(guild.Id, infraction.Subject.Id); switch (infraction.Type) { case InfractionType.Mute: await subject.RemoveRoleAsync( await GetDesignatedMuteRoleAsync(guild)); break; case InfractionType.Ban: await guild.RemoveBanAsync(subject); break; } return(ServiceResult.FromSuccess()); }
/// <inheritdoc /> public async Task DeleteInfractionAsync(long infractionId) { AuthorizationService.RequireAuthenticatedUser(); AuthorizationService.RequireClaims(AuthorizationClaim.ModerationDeleteInfraction); var infraction = await InfractionRepository.ReadSummaryAsync(infractionId); if (infraction == null) { throw new InvalidOperationException($"Infraction {infractionId} does not exist"); } await RequireSubjectRankLowerThanModeratorRankAsync(infraction.GuildId, infraction.Subject.Id); await InfractionRepository.TryDeleteAsync(infraction.Id, AuthorizationService.CurrentUserId.Value); var guild = await DiscordClient.GetGuildAsync(infraction.GuildId); switch (infraction.Type) { case InfractionType.Mute: if (await UserService.GuildUserExistsAsync(guild.Id, infraction.Subject.Id)) { var subject = await UserService.GetGuildUserAsync(guild.Id, infraction.Subject.Id); await subject.RemoveRoleAsync(await GetDesignatedMuteRoleAsync(guild)); } else { Log.Warning("Tried to unmute {User} while deleting mute infraction, but they weren't in the guild: {Guild}", infraction.Subject.Id, guild.Id); } break; case InfractionType.Ban: await guild.RemoveBanAsync(infraction.Subject.Id); break; } }