Public/private reasons on punishments
This commit is contained in:
parent
252a18d326
commit
d3bdeb6d50
@ -39,6 +39,7 @@ public final class PunishmentConverter implements Block<Document> {
|
||||
Punishment created = new Punishment(
|
||||
new ObjectId().toString(),
|
||||
target,
|
||||
"Imported Ban; reason hidden",
|
||||
punishment.getString("reason").toString(),
|
||||
Punishment.PunishmentType.valueOf(punishment.getString("type").toUpperCase()),
|
||||
punishment.containsKey("expires") ? punishment.getDate("expires").toInstant() : null,
|
||||
|
@ -74,7 +74,7 @@ public final class IpBan {
|
||||
public IpBan(String userIp, Punishment linked) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.userIp = userIp;
|
||||
this.reason = linked.getReason();
|
||||
this.reason = linked.getPublicReason();
|
||||
this.expiresAt = linked.getExpiresAt();
|
||||
this.addedBy = linked.getAddedBy();
|
||||
this.addedAt = Instant.now();
|
||||
|
@ -26,7 +26,8 @@ public final class Punishment {
|
||||
|
||||
@Getter @Id private String id;
|
||||
@Getter private UUID user;
|
||||
@Getter private String reason;
|
||||
@Getter private String publicReason;
|
||||
@Getter private String privateReason;
|
||||
@Getter private PunishmentType type;
|
||||
@Getter private Instant expiresAt;
|
||||
@Getter private Map<String, Object> metadata;
|
||||
@ -97,10 +98,11 @@ public final class Punishment {
|
||||
|
||||
private Punishment() {} // For Jackson
|
||||
|
||||
public Punishment(User user, String reason, PunishmentType type, Instant expiresAt, User addedBy, Actor actor, Map<String, Object> metadata) {
|
||||
public Punishment(User user, String publicReason, String privateReason, PunishmentType type, Instant expiresAt, User addedBy, Actor actor, Map<String, Object> metadata) {
|
||||
this.id = new ObjectId().toString();
|
||||
this.user = user.getId();
|
||||
this.reason = reason;
|
||||
this.publicReason = publicReason;
|
||||
this.privateReason = privateReason;
|
||||
this.type = type;
|
||||
this.expiresAt = expiresAt;
|
||||
this.addedBy = addedBy == null ? null : addedBy.getId();
|
||||
|
@ -32,10 +32,16 @@ public final class POSTPunishments implements Handler<RoutingContext> {
|
||||
return;
|
||||
}
|
||||
|
||||
String reason = requestBody.getString("reason");
|
||||
String publicReason = requestBody.getString("publicReason");
|
||||
String privateReason = requestBody.getString("privateReason");
|
||||
|
||||
if (reason == null || reason.trim().isEmpty()) {
|
||||
ErrorUtils.respondRequiredInput(ctx, "reason");
|
||||
if (publicReason == null || publicReason.trim().isEmpty()) {
|
||||
ErrorUtils.respondRequiredInput(ctx, "publicReason");
|
||||
return;
|
||||
}
|
||||
|
||||
if (privateReason == null || privateReason.trim().isEmpty()) {
|
||||
ErrorUtils.respondRequiredInput(ctx, "privateReason");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -45,11 +51,11 @@ public final class POSTPunishments implements Handler<RoutingContext> {
|
||||
BlockingCallback<List<Punishment>> punishmentsCallback = new BlockingCallback<>();
|
||||
Punishment.findByUserAndType(target, ImmutableSet.of(type), punishmentsCallback);
|
||||
|
||||
for (Punishment punishment : punishmentsCallback.get()) {
|
||||
if (punishment.isActive()) {
|
||||
for (Punishment alternatePunishment : punishmentsCallback.get()) {
|
||||
if (alternatePunishment.isActive()) {
|
||||
BlockingCallback<User> addedByCallback = new BlockingCallback<>();
|
||||
User.findById(punishment.getAddedBy(), addedByCallback);
|
||||
ErrorUtils.respondGeneric(ctx, 409, "A punishment by " + addedByCallback.get().getLastUsername() + " already covers this user.");
|
||||
User.findById(alternatePunishment.getAddedBy(), addedByCallback);
|
||||
ErrorUtils.respondOther(ctx, 409, "User already covered by alternate punishment.", "alreadyCoveredByAlternatePunishment", ImmutableMap.of("alternatePunishmentBy", addedByCallback.get().getLastUsername()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -82,11 +88,11 @@ public final class POSTPunishments implements Handler<RoutingContext> {
|
||||
target.hasPermissionAnywhere(Permissions.PROTECTED_PUNISHMENT, permissionsCallback);
|
||||
|
||||
if (permissionsCallback.get()) {
|
||||
ErrorUtils.respondGeneric(ctx, 409, target.getLastSeenOn() + " is protected from punishments.");
|
||||
ErrorUtils.respondOther(ctx, 409, "User is protected from punishments.", "protectedFromPunishments", ImmutableMap.of());
|
||||
return;
|
||||
}
|
||||
|
||||
Punishment punishment = new Punishment(target, reason, type, expiresAt, addedBy, ctx.get("actor"), meta);
|
||||
Punishment punishment = new Punishment(target, publicReason, privateReason, type, expiresAt, addedBy, ctx.get("actor"), meta);
|
||||
String accessDenialReason = punishment.getAccessDenialReason();
|
||||
String userIp = requestBody.getString("userIp");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user