Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,24 @@ public String zeroSmallintLiteral() {
};
}

public String[] migrateScope() {
private String[] migrateScope(int varCharLen) {
return switch (this) {
case MARIADB, MYSQL -> new String[] {"", ""};
case HSQLDB, POSTGRES, COCKROACH -> new String[] {
"CAST(",
" AS CHARACTER VARYING(32))"
" AS CHARACTER VARYING(" + varCharLen + "))"
};
};
}

public String[] migrateScope() {
return migrateScope(32);
}

public String[] migrateScopePostIssue343() {
return migrateScope(255);
}

String getConnectionInitSql() {

return switch (this) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2023 Anand Beh
* Copyright © 2026 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -36,11 +36,17 @@ public ScopeIdSequenceValue(DSLContext context) {
super(context, LIBERTYBANS_SCOPE_IDS);
}

// issue 343: scope length checks are temporarily limited to insertion, pending full removal
private static final int SCOPE_VALUE_LENGTH_LIMIT = 32;

private RetrieveOrGenerate retrieveOrGenerate(ScopeType type, String value) {
return new RetrieveOrGenerate(
SCOPES, SCOPES.ID,
SCOPES.TYPE.eq(type).and(SCOPES.VALUE.eq(value)),
(newId) -> {
if (value.length() > SCOPE_VALUE_LENGTH_LIMIT) {
throw new IllegalArgumentException("Scope length must be less than " + SCOPE_VALUE_LENGTH_LIMIT);
}
context
.insertInto(SCOPES)
.columns(SCOPES.ID, SCOPES.TYPE, SCOPES.VALUE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2023 Anand Beh
* Copyright © 2026 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -85,8 +85,9 @@ private Punishment enact(PunishmentCreator creator,
DSLContext context, Transaction transaction, boolean active) {
MiscUtil.checkNoCompositeVictimWildcards(victim);

Field<Integer> escalationTrackId = new TrackIdSequenceValue(context).retrieveTrackId(escalationTrack);
// issue 343: scope length of greater than 32 will throw here (solve in 1.2.0)
Field<Integer> scopeId = new ScopeIdSequenceValue(context).retrieveScopeId(scope);
Field<Integer> escalationTrackId = new TrackIdSequenceValue(context).retrieveTrackId(escalationTrack);

SequenceValue<Long> punishmentIdSequence = new SequenceValue<>(context, LIBERTYBANS_PUNISHMENT_IDS);
context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2023 Anand Beh
* Copyright © 2026 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -133,6 +133,7 @@ var record = context.newRecord(PUNISHMENTS);
furtherModifications.put(PUNISHMENTS.TRACK, newTrack);
}
if (scope != null) {
// issue 343: scope length of greater than 32 will throw here (solve in 1.2.0)
Field<Integer> newScope = new ScopeIdSequenceValue(context).retrieveScopeId(scope);
furtherModifications.put(PUNISHMENTS.SCOPE, newScope);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2023 Anand Beh
* Copyright © 2026 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -29,7 +29,7 @@ public class ScopeParsing {

public static final String GLOBAL_SCOPE_USER_INPUT = "*";

private static final int SCOPE_VALUE_LENGTH_LIMIT = 32;
private static final int SCOPE_VALUE_LENGTH_LIMIT = 255;

static void checkScopeValue(String value) {
if (value.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2025 Anand Beh
* Copyright © 2026 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -27,7 +27,6 @@
import space.arim.libertybans.api.NetworkAddress;
import space.arim.libertybans.api.scope.ScopeManager;
import space.arim.libertybans.core.config.Configs;
import space.arim.libertybans.core.config.InternalFormatter;
import space.arim.libertybans.core.env.EnvEnforcer;
import space.arim.libertybans.core.selector.cache.MuteCache;
import space.arim.libertybans.core.service.FuturePoster;
Expand All @@ -48,20 +47,18 @@ public final class IntelligentGuardian implements Guardian {
private final FuturePoster futurePoster;
private final FactoryOfTheFuture futuresFactory;
private final ScopeManager scopeManager;
private final InternalFormatter formatter;
private final InternalSelector selector;
private final UUIDManager uuidManager;
private final MuteCache muteCache;

@Inject
public IntelligentGuardian(Configs configs, FuturePoster futurePoster, FactoryOfTheFuture futuresFactory,
ScopeManager scopeManager, InternalFormatter formatter, InternalSelector selector,
ScopeManager scopeManager, InternalSelector selector,
UUIDManager uuidManager, MuteCache muteCache) {
this.configs = configs;
this.futurePoster = futurePoster;
this.futuresFactory = futuresFactory;
this.scopeManager = scopeManager;
this.formatter = formatter;
this.selector = selector;
this.uuidManager = uuidManager;
this.muteCache = muteCache;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2025 Anand Beh
* Copyright © 2026 Anand Beh
*
* LibertyBans is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -75,7 +75,7 @@ public void setup(@Mock Configs configs, @Mock ScopeManager scopeManager,

FuturePoster futurePoster = completionStage -> completionStage.toCompletableFuture().join();
guardian = new IntelligentGuardian(
configs, futurePoster, futuresFactory, scopeManager, formatter, selector, uuidManager, muteCache
configs, futurePoster, futuresFactory, scopeManager, selector, uuidManager, muteCache
);
MainConfig mainConfig = mock(MainConfig.class);
EnforcementConfig enforcementConfig = mock(EnforcementConfig.class);
Expand Down
Loading
Loading