fix(service): thread request context through BanUser/UnbanUser

contextcheck (CI lint) flagged the admin handler calling BanUser without
the request context — the service opened its telemetry span from
context.Background(), detaching the ban from its request trace. Both
moderation entrypoints now take ctx; the span joins the caller's trace.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
J3vb
2026-07-19 10:18:40 +02:00
co-authored by Claude Fable 5
parent 4c2fecbf02
commit bc7d65ab29
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -117,9 +117,9 @@ func handlePatchUser(database *db.DB, hub HubBroadcaster, permInvalidator Permis
}
var actionErr error
if *req.Banned {
actionErr = mod.BanUser(actor, id, banReason, nil)
actionErr = mod.BanUser(r.Context(), actor, id, banReason, nil)
} else {
actionErr = mod.UnbanUser(actor, id)
actionErr = mod.UnbanUser(r.Context(), actor, id)
}
if actionErr != nil {
writeModerationErr(w, actionErr)
+3 -3
View File
@@ -64,8 +64,8 @@ func (s *ModerationService) requireOutranks(actorID, targetID int64) error {
// BanUser bans a target user. Validates the target exists and
// prevents self-banning.
func (s *ModerationService) BanUser(actorID, targetID int64, reason string, expires *time.Time) error {
ctx, span := telemetry.GlobalTracer("service/moderation").Start(context.Background(), "ModerationService.BanUser",
func (s *ModerationService) BanUser(ctx context.Context, actorID, targetID int64, reason string, expires *time.Time) error {
ctx, span := telemetry.GlobalTracer("service/moderation").Start(ctx, "ModerationService.BanUser",
telemetry.Int64("actor_id", actorID),
telemetry.Int64("target_id", targetID),
)
@@ -109,7 +109,7 @@ func (s *ModerationService) BanUser(actorID, targetID int64, reason string, expi
}
// UnbanUser removes a ban on a target user.
func (s *ModerationService) UnbanUser(actorID, targetID int64) error {
func (s *ModerationService) UnbanUser(_ context.Context, actorID, targetID int64) error {
if targetID <= 0 {
return fmt.Errorf("%w: user_id must be positive", ErrBadRequest)
}