SHA256
UI и API: экран серверов доступа и фильтр SearchUsers
This commit is contained in:
@@ -154,6 +154,11 @@ public final class CurrentUsersDAO {
|
||||
|
||||
/** Поиск по префиксу с внешним соединением. Соединение НЕ закрывает. */
|
||||
public List<CurrentUserEntry> searchByLoginPrefix(Connection c, String prefix) throws SQLException {
|
||||
return searchByLoginPrefix(c, prefix, null);
|
||||
}
|
||||
|
||||
/** Поиск по префиксу с optional-фильтром server PDA. Соединение НЕ закрывает. */
|
||||
public List<CurrentUserEntry> searchByLoginPrefix(Connection c, String prefix, Boolean isServer) throws SQLException {
|
||||
String sql = """
|
||||
SELECT
|
||||
login,
|
||||
@@ -163,6 +168,7 @@ public final class CurrentUsersDAO {
|
||||
client_key
|
||||
FROM %s
|
||||
WHERE LOWER(login) LIKE ?
|
||||
AND (? IS NULL OR is_server = ?)
|
||||
ORDER BY login
|
||||
LIMIT 5
|
||||
""".formatted(CurrentUsersSql.usersSubquery("su"));
|
||||
@@ -171,6 +177,13 @@ public final class CurrentUsersDAO {
|
||||
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
ps.setString(1, prefix.toLowerCase() + "%");
|
||||
if (isServer == null) {
|
||||
ps.setNull(2, Types.BOOLEAN);
|
||||
ps.setNull(3, Types.BOOLEAN);
|
||||
} else {
|
||||
ps.setBoolean(2, isServer);
|
||||
ps.setBoolean(3, isServer);
|
||||
}
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) result.add(mapRow(rs));
|
||||
}
|
||||
@@ -181,8 +194,13 @@ public final class CurrentUsersDAO {
|
||||
|
||||
/** Поиск по префиксу без внешнего соединения. Сам открывает/закрывает. */
|
||||
public List<CurrentUserEntry> searchByLoginPrefix(String prefix) throws SQLException {
|
||||
return searchByLoginPrefix(prefix, null);
|
||||
}
|
||||
|
||||
/** Поиск по префиксу без внешнего соединения с optional-фильтром server PDA. */
|
||||
public List<CurrentUserEntry> searchByLoginPrefix(String prefix, Boolean isServer) throws SQLException {
|
||||
try (Connection c = db.getConnection()) {
|
||||
return searchByLoginPrefix(c, prefix);
|
||||
return searchByLoginPrefix(c, prefix, isServer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ public final class CurrentUsersSql {
|
||||
current_users.blockchain_name AS blockchain_name,
|
||||
current_users.client_key AS solana_key,
|
||||
current_users.blockchain_key AS blockchain_key,
|
||||
current_users.client_key AS client_key
|
||||
current_users.client_key AS client_key,
|
||||
current_users.is_server AS is_server
|
||||
FROM solana_user_pda_current current_users
|
||||
) %s
|
||||
""".formatted(alias);
|
||||
|
||||
+3
-2
@@ -35,10 +35,11 @@ public class Net_SearchUsers_Handler implements JsonMessageHandler {
|
||||
}
|
||||
|
||||
String prefix = req.getPrefix().trim();
|
||||
Boolean isServer = req.getIsServer();
|
||||
|
||||
try {
|
||||
CurrentUsersDAO dao = CurrentUsersDAO.getInstance();
|
||||
List<CurrentUserEntry> users = dao.searchByLoginPrefix(prefix); // case-insensitive + LIMIT 5
|
||||
List<CurrentUserEntry> users = dao.searchByLoginPrefix(prefix, isServer); // case-insensitive + LIMIT 5
|
||||
|
||||
List<String> logins = new ArrayList<>();
|
||||
for (CurrentUserEntry u : users) {
|
||||
@@ -53,7 +54,7 @@ public class Net_SearchUsers_Handler implements JsonMessageHandler {
|
||||
resp.setStatus(WireCodes.Status.OK);
|
||||
resp.setLogins(logins);
|
||||
|
||||
log.info("✅ SearchUsers ok: prefix='{}' -> {}", prefix, logins.size());
|
||||
log.info("✅ SearchUsers ok: prefix='{}', isServer={} -> {}", prefix, isServer, logins.size());
|
||||
return resp;
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
||||
+4
-1
@@ -18,7 +18,10 @@ import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||
public class Net_SearchUsers_Request extends Net_Request {
|
||||
|
||||
private String prefix;
|
||||
private Boolean isServer;
|
||||
|
||||
public String getPrefix() { return prefix; }
|
||||
public void setPrefix(String prefix) { this.prefix = prefix; }
|
||||
}
|
||||
public Boolean getIsServer() { return isServer; }
|
||||
public void setIsServer(Boolean isServer) { this.isServer = isServer; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user