mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user