Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moderation: Support appeal cooldowns #435

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MathyFurret
Copy link

@MathyFurret MathyFurret commented Oct 6, 2024

  • Adds a new field to users: a date that they are allowed to appeal their ban. Null means no appeal. Defaults to Instant.MinValue (assumes all existing banned users can appeal immediately).
  • Adds 3 commands for moderators
    • setappealcooldown - sets the time a user must wait before appealing a ban.
    • setunappealable - marks a user's ban as unappealable
    • checkappealcooldown - shows if and when a user is allowed to appeal
  • Adds a new modlog repo for appeal cooldowns

Opening for preliminary reviews as I work on the web side of this

@Felk
Copy link
Member

Felk commented Oct 11, 2024

Looks good on a first scim, thanks! I'll try to take a closer look in the upcoming days if you don't mind. Or should I wait because draft?

Copy link
Member

@Felk Felk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only some minor comments, mostly style. You may ignore individual comments if you disagree. Looks good, thanks!

Comment on lines +79 to +82
/// <summary>
/// When a user can appeal. If null, the user is never allowed to appeal.
/// </summary>
public Instant? AppealDate { get; init; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a clarification how this value should get interpreted in the case the user isn't banned? Maybe it can just be any value, but that arbitrary value should bear no meaning in that case?

Comment on lines +81 to +82
await _userRepo.SetAppealCooldown(targetUser, expiration);
await _appealCooldownLogRepo.LogAppealCooldownChange(targetUser.Id, "auto_appeal_cooldown", issuerUser.Id, now, DEFAULT_APPEAL_TIME);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make it impossible to change the appeal cooldown without logging, would it be better to put both into one call somehow? Not sure how example though

Comment on lines +76 to +83
// First ban can be appealed after 1 month by default.
// I don't want to automatically calculate how many bans the user has had, because some might be joke/mistakes
// A mod should manually set the next appeal cooldown based on the rules.
var DEFAULT_APPEAL_TIME = Duration.FromDays(30);
Instant expiration = now + DEFAULT_APPEAL_TIME;
await _userRepo.SetAppealCooldown(targetUser, expiration);
await _appealCooldownLogRepo.LogAppealCooldownChange(targetUser.Id, "auto_appeal_cooldown", issuerUser.Id, now, DEFAULT_APPEAL_TIME);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this entire section only run if isBan?

Comment on lines +208 to +210
string? issuerName = recentLog?.IssuerUserId == null
? "<automated>"
: (await _userRepo.FindById(recentLog.IssuerUserId))?.Name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be impossible since we never delete anyone from the users repo as far as I know, but as a safeguard against failing to look up a user, maybe sth. like this?

Suggested change
string? issuerName = recentLog?.IssuerUserId == null
? "<automated>"
: (await _userRepo.FindById(recentLog.IssuerUserId))?.Name;
string issuerName = recentLog?.IssuerUserId == null
? "<automated>"
: (await _userRepo.FindById(recentLog.IssuerUserId))?.Name
?? $"<unknown user id ${recentLog.IssuerUserId}>";

Comment on lines +217 to +223
return new CommandResult { Response =
targetUser.AppealDate is null
? $"{targetUser.Name} is not eligible to appeal. {infoText}"
: targetUser.AppealDate < _clock.GetCurrentInstant()
? $"{targetUser.Name} is eligible to appeal now. {infoText}"
: $"{targetUser.Name} will be eligible to appeal on {targetUser.AppealDate}. {infoText}"
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if dotnet format would like it, but making the ternary nesting a bit more visible with indentation might help a bit:

Suggested change
return new CommandResult { Response =
targetUser.AppealDate is null
? $"{targetUser.Name} is not eligible to appeal. {infoText}"
: targetUser.AppealDate < _clock.GetCurrentInstant()
? $"{targetUser.Name} is eligible to appeal now. {infoText}"
: $"{targetUser.Name} will be eligible to appeal on {targetUser.AppealDate}. {infoText}"
};
return new CommandResult { Response =
targetUser.AppealDate is null
? $"{targetUser.Name} is not eligible to appeal. {infoText}"
: targetUser.AppealDate < _clock.GetCurrentInstant()
? $"{targetUser.Name} is eligible to appeal now. {infoText}"
: $"{targetUser.Name} will be eligible to appeal on {targetUser.AppealDate}. {infoText}"
};

Or, given the infoText gets appended anyway, maybe:

Suggested change
return new CommandResult { Response =
targetUser.AppealDate is null
? $"{targetUser.Name} is not eligible to appeal. {infoText}"
: targetUser.AppealDate < _clock.GetCurrentInstant()
? $"{targetUser.Name} is eligible to appeal now. {infoText}"
: $"{targetUser.Name} will be eligible to appeal on {targetUser.AppealDate}. {infoText}"
};
return new CommandResult { Response = (
targetUser.AppealDate is null
? $"{targetUser.Name} is not eligible to appeal."
: targetUser.AppealDate < _clock.GetCurrentInstant()
? $"{targetUser.Name} is eligible to appeal now."
: $"{targetUser.Name} will be eligible to appeal on {targetUser.AppealDate}."
) + " " + infoText
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants