Skip to content

Commit

Permalink
Implement audit log reasons for more endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Dec 16, 2021
1 parent 44daf24 commit dad00fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Rest.Core;
using Remora.Results;
Expand All @@ -33,6 +34,7 @@ namespace Remora.Discord.API.Abstractions.Rest;
/// <summary>
/// Represents the Discord Guild Scheduled Event API.
/// </summary>
[PublicAPI]
public interface IDiscordRestGuildScheduledEventAPI
{
/// <summary>
Expand Down Expand Up @@ -63,6 +65,7 @@ Task<Result<IReadOnlyList<IGuildScheduledEvent>>> ListScheduledEventsForGuildAsy
/// <param name="scheduledEndTime">The time at which the event is scheduled to end, if any.</param>
/// <param name="description">The description of the event, if any (1-100 characters).</param>
/// <param name="entityType">The entity type of the event.</param>
/// <param name="reason">The reason to mark the action in the audit log with.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A creation result which may or may not have succeeded.</returns>
Task<Result<IGuildScheduledEvent>> CreateGuildScheduledEventAsync
Expand All @@ -76,6 +79,7 @@ Task<Result<IGuildScheduledEvent>> CreateGuildScheduledEventAsync
Optional<DateTimeOffset> scheduledEndTime,
Optional<string> description,
GuildScheduledEventEntityType entityType,
Optional<string> reason = default,
CancellationToken ct = default
);

Expand Down Expand Up @@ -109,6 +113,7 @@ Task<Result<IGuildScheduledEvent>> GetGuildScheduledEventAsync
/// <param name="description">The new description of the event (1-100 characters).</param>
/// <param name="entityType">The new entity type associated with the event.</param>
/// <param name="status">The new status of the event.</param>
/// <param name="reason">The reason to mark the action in the audit log with.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A modification result which may or may not have succeeded.</returns>
Task<Result<IGuildScheduledEvent>> ModifyGuildScheduledEventAsync
Expand All @@ -124,6 +129,7 @@ Task<Result<IGuildScheduledEvent>> ModifyGuildScheduledEventAsync
Optional<string> description = default,
Optional<GuildScheduledEventEntityType> entityType = default,
Optional<GuildScheduledEventStatus> status = default,
Optional<string> reason = default,
CancellationToken ct = default
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public async Task<Result<IGuildScheduledEvent>> CreateGuildScheduledEventAsync
Optional<DateTimeOffset> scheduledEndTime,
Optional<string> description,
GuildScheduledEventEntityType entityType,
Optional<string> reason = default,
CancellationToken ct = default
)
{
Expand Down Expand Up @@ -139,6 +140,7 @@ entityMetadata.Value.Location.Value.Length is < 1 or > 100
}
);

b.AddAuditLogReason(reason);
b.WithRateLimitContext();
},
ct: ct
Expand Down Expand Up @@ -184,6 +186,7 @@ public async Task<Result<IGuildScheduledEvent>> ModifyGuildScheduledEventAsync
Optional<string> description = default,
Optional<GuildScheduledEventEntityType> entityType = default,
Optional<GuildScheduledEventStatus> status = default,
Optional<string> reason = default,
CancellationToken ct = default
)
{
Expand Down Expand Up @@ -240,6 +243,7 @@ entityMetadata.Value.Location.Value.Length is < 1 or > 100
}
);

b.AddAuditLogReason(reason);
b.WithRateLimitContext();
},
ct: ct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public async Task PerformsRequestCorrectly()
var scheduledEndTime = scheduledStartTime.AddHours(1);
var description = "booga";
var entityType = GuildScheduledEventEntityType.StageInstance;
var reason = "aaa";

var api = CreateAPI
(
Expand All @@ -116,6 +117,7 @@ public async Task PerformsRequestCorrectly()
.WithProperty("entity_type", p => p.Is((int)entityType))
)
)
.WithHeaders(Constants.AuditLogHeaderName, reason)
.Respond("application/json", SampleRepository.Samples[typeof(IGuildScheduledEvent)])
);

Expand All @@ -129,7 +131,8 @@ public async Task PerformsRequestCorrectly()
scheduledStartTime,
scheduledEndTime,
description,
entityType
entityType,
reason
);

ResultAssert.Successful(result);
Expand Down Expand Up @@ -189,6 +192,7 @@ public async Task PerformsRequestCorrectly()
var description = "booga";
var entityType = GuildScheduledEventEntityType.StageInstance;
var status = GuildScheduledEventStatus.Completed;
var reason = "aaa";

var api = CreateAPI
(
Expand All @@ -214,6 +218,7 @@ public async Task PerformsRequestCorrectly()
.WithProperty("status", p => p.Is((int)status))
)
)
.WithHeaders(Constants.AuditLogHeaderName, reason)
.Respond("application/json", SampleRepository.Samples[typeof(IGuildScheduledEvent)])
);

Expand All @@ -229,7 +234,8 @@ public async Task PerformsRequestCorrectly()
scheduledEndTime,
description,
entityType,
status
status,
reason
);

ResultAssert.Successful(result);
Expand Down

0 comments on commit dad00fe

Please sign in to comment.