Answer what we may do in one place: Permissions
The rules were spread over ServerSession's can* methods, ServerModel's permits/mayHavePower/canDelete*, TeamspeakConnection and AvatarAdmin, and Swing dialogs and Android's ServerController passed raw permission names. Permissions now holds the server's permission table and the rules (offered until the server says, unreported powers unknown until asked) and answers one named question per capability. ServerSession.permissions() is the gate for frontends: Permissions.NONE, allowing nothing, while disconnected. ServerController's forwarding properties go the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.config.BanReasonPresets;
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.net.Permissions;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.net.ban.BanEntry;
|
||||
import eu.lixko.ts3j.client.net.ban.BanRule;
|
||||
@@ -417,25 +418,18 @@ final class BanListDialog extends JDialog {
|
||||
|
||||
// ---- permissions ----
|
||||
|
||||
private boolean can(String permission) {
|
||||
return conn.getModel().permits(permission);
|
||||
}
|
||||
|
||||
private boolean canDelete(List<BanEntry> bans) {
|
||||
return conn.getModel().canDeleteBans(bans, conn.getSelfUniqueId());
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
Permissions permissions = conn.getModel().permissions();
|
||||
List<BanEntry> selected = selectedBans();
|
||||
addButton.setEnabled(can("b_client_ban_create"));
|
||||
removeButton.setEnabled(!selected.isEmpty() && canDelete(selected));
|
||||
editButton.setEnabled(selected.size() == 1 && conn.getModel().canEditBan(selected.get(0), conn.getSelfUniqueId()));
|
||||
addButton.setEnabled(permissions.canCreateBans());
|
||||
removeButton.setEnabled(!selected.isEmpty() && permissions.canDeleteBans(selected, conn.getSelfUniqueId()));
|
||||
editButton.setEnabled(selected.size() == 1 && permissions.canEditBan(selected.get(0), conn.getSelfUniqueId()));
|
||||
}
|
||||
|
||||
// ---- actions ----
|
||||
|
||||
private long maxBanSeconds() {
|
||||
return conn.getModel().maxBanSeconds();
|
||||
return conn.getModel().permissions().maxBanSeconds();
|
||||
}
|
||||
|
||||
private void addBan() {
|
||||
|
||||
@@ -355,7 +355,7 @@ final class ComplaintsDialog extends JDialog {
|
||||
|
||||
private void updateButtons() {
|
||||
Selection sel = selection();
|
||||
removeButton.setEnabled(!sel.isEmpty() && conn.getModel().canDeleteComplaints(sel.affected(), selfDbId()));
|
||||
removeButton.setEnabled(!sel.isEmpty() && conn.getModel().permissions().canDeleteComplaints(sel.affected(), selfDbId()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -366,7 +366,7 @@ final class ComplaintsDialog extends JDialog {
|
||||
int[] rows = table.getSelectedRows();
|
||||
if (rows.length != 1) return null;
|
||||
ServerModel model = conn.getModel();
|
||||
if (!model.mayHavePower("i_client_ban_power")) return null;
|
||||
if (!model.permissions().canBanClients()) return null;
|
||||
Row row = tableModel.get(rows[0]);
|
||||
ClientEntry client = model.findClientByDatabaseId(row.isTarget() ? row.target().dbId() : row.complaint().fromDbId());
|
||||
return client == null || client.id == conn.getSelfClientId() ? null : client;
|
||||
|
||||
@@ -295,7 +295,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
|
||||
@Override
|
||||
public boolean canSetAvatar() {
|
||||
return selected != null && selected.session().canSetAvatar();
|
||||
return selected != null && selected.session().permissions().canSetAvatar();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -350,7 +350,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
|
||||
@Override
|
||||
public boolean canViewBanList() {
|
||||
return selected != null && selected.session().canViewBanList();
|
||||
return selected != null && selected.session().permissions().canViewBanList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -360,7 +360,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
|
||||
@Override
|
||||
public boolean canViewComplaints() {
|
||||
return selected != null && selected.session().canViewComplaints();
|
||||
return selected != null && selected.session().permissions().canViewComplaints();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -370,7 +370,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
|
||||
@Override
|
||||
public boolean canViewServerLog() {
|
||||
return selected != null && selected.session().canViewServerLog();
|
||||
return selected != null && selected.session().permissions().canViewServerLog();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -380,7 +380,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
|
||||
@Override
|
||||
public boolean canListPrivilegeKeys() {
|
||||
return selected != null && selected.session().canListPrivilegeKeys();
|
||||
return selected != null && selected.session().permissions().canListPrivilegeKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -363,7 +363,7 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
boolean canSend = conn.canSendOfflineMessages();
|
||||
boolean canSend = conn.getModel().permissions().canSendOfflineMessages();
|
||||
composeButton.setEnabled(canSend);
|
||||
replyButton.setEnabled(canSend && singleSelected() != null);
|
||||
deleteButton.setEnabled(table.getSelectedRowCount() > 0);
|
||||
|
||||
@@ -235,8 +235,8 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
|
||||
private void updateButtons() {
|
||||
ServerModel model = conn.getModel();
|
||||
createButton.setEnabled(model.permits("b_virtualserver_token_add"));
|
||||
removeButton.setEnabled(!selectedKeys().isEmpty() && model.permits("b_virtualserver_token_delete"));
|
||||
createButton.setEnabled(model.permissions().canAddPrivilegeKeys());
|
||||
removeButton.setEnabled(!selectedKeys().isEmpty() && model.permissions().canDeletePrivilegeKeys());
|
||||
}
|
||||
|
||||
// ---- actions ----
|
||||
|
||||
@@ -129,12 +129,12 @@ final class ServerTab {
|
||||
|
||||
@Override
|
||||
public boolean canSet() {
|
||||
return session.canSetAvatar();
|
||||
return session.permissions().canSetAvatar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDeleteOthers() {
|
||||
return session.canDeleteOtherAvatars();
|
||||
return session.permissions().canDeleteOtherAvatars();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,7 +236,7 @@ final class ServerTab {
|
||||
}
|
||||
|
||||
void composeOfflineMessage() {
|
||||
if (!session.isConnected() || !conn.canSendOfflineMessages()) return;
|
||||
if (!session.permissions().canSendOfflineMessages()) return;
|
||||
Window owner = offlineMessages != null && offlineMessages.isShowing() ? offlineMessages : host;
|
||||
OfflineMessageComposeDialog.compose(owner, conn, contacts).setVisible(true);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
public void banClient(ClientEntry client) {
|
||||
if (!conn.isConnected()) return;
|
||||
BanDialog dialog = new BanDialog(host, client.nickname,
|
||||
conn.getModel().maxBanSeconds());
|
||||
conn.getModel().permissions().maxBanSeconds());
|
||||
dialog.setVisible(true);
|
||||
if (dialog.isConfirmed()) conn.banClient(client.id, dialog.getSeconds(), dialog.getReason());
|
||||
}
|
||||
@@ -229,12 +229,12 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
*/
|
||||
@Override
|
||||
public boolean canDeleteOtherAvatars() {
|
||||
return tab.session().canDeleteOtherAvatars();
|
||||
return tab.session().permissions().canDeleteOtherAvatars();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrantTalkPower() {
|
||||
return tab.session().canGrantTalkPower();
|
||||
return tab.session().permissions().canGrantTalkPower();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -346,7 +346,7 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
@Override
|
||||
public boolean canBrowseFiles() {
|
||||
return tab.session().canBrowseFiles();
|
||||
return tab.session().permissions().canBrowseFiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user