Skip to content

Commit

Permalink
Merge pull request bisq-network#2979 from HenrikJannsen/improve-secur…
Browse files Browse the repository at this point in the history
…ity-manager-bonded-role-list-item

Improve display of bonded role data in security manager/ban bonded role UI
  • Loading branch information
HenrikJannsen authored Nov 5, 2024
2 parents 57fa30b + 31d8475 commit 42d2140
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,14 @@ public final void setOnChangeConfirmed(EventHandler<Event> eventHandler) {
String inputText = editor.getText();
// Case 1: fire if input text selects (matches) an item
String selectedItemAsString = getConverter().toString(getSelectionModel().getSelectedItem());
if (selectedItemAsString != null && selectedItemAsString.equals(inputText)) {
eventHandler.handle(e);
getParent().requestFocus();
return;
if (selectedItemAsString != null) {
// editor is not multiline, new lines are swallowed, so we remove the new line before we compare
selectedItemAsString = selectedItemAsString.replace("\n", "");
if (selectedItemAsString.equals(inputText)) {
eventHandler.handle(e);
getParent().requestFocus();
return;
}
}

// Case 2: fire if the text is empty to support special "show all" case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.bonded_roles.security_manager.alert.AuthorizedAlertData;
import bisq.bonded_roles.security_manager.difficulty_adjustment.AuthorizedDifficultyAdjustmentData;
import bisq.bonded_roles.security_manager.difficulty_adjustment.DifficultyAdjustmentService;
import bisq.common.network.Address;
import bisq.common.observable.Pin;
import bisq.common.util.StringUtils;
import bisq.desktop.ServiceProvider;
Expand All @@ -46,6 +47,7 @@
import org.fxmisc.easybind.Subscription;

import java.util.Optional;
import java.util.stream.Collectors;

@Slf4j
public class SecurityManagerController implements Controller {
Expand Down Expand Up @@ -93,6 +95,9 @@ public void onActivate() {
.map(bondedRole -> new SecurityManagerView.BondedRoleListItem(bondedRole, this))
.to(authorizedBondedRolesService.getBondedRoles());

model.getBondedRoleSortedList().setComparator((o1, o2) -> getBondedRoleDisplayString(o1.getBondedRole())
.compareTo(getBondedRoleDisplayString(o2.getBondedRole())));

difficultyAdjustmentListItemsPin = FxBindings.<AuthorizedDifficultyAdjustmentData, SecurityManagerView.DifficultyAdjustmentListItem>bind(model.getDifficultyAdjustmentListItems())
.map(SecurityManagerView.DifficultyAdjustmentListItem::new)
.to(difficultyAdjustmentService.getAuthorizedDifficultyAdjustmentDataSet());
Expand Down Expand Up @@ -169,23 +174,31 @@ void onRemoveAlert(AuthorizedAlertData authorizedAlertData) {
securityManagerService.removeAlert(authorizedAlertData, userIdentity.getNetworkIdWithKeyPair().getKeyPair());
}

String getBondedRoleShortDisplayString(BondedRole bondedRole) {
String getBondedRoleDisplayString(BondedRole bondedRole) {
AuthorizedBondedRole authorizedBondedRole = bondedRole.getAuthorizedBondedRole();
String roleType = authorizedBondedRole.getBondedRoleType().getDisplayString();
String roleType = authorizedBondedRole.getBondedRoleType().getDisplayString().toUpperCase();
String profileId = authorizedBondedRole.getProfileId();
String nickName = userProfileService.findUserProfile(profileId)
String nickNameOrBondName = userProfileService.findUserProfile(profileId)
.map(UserProfile::getNickName)
.orElse(Res.get("data.na"));
return Res.get("authorizedRole.securityManager.selectedBondedRole", nickName, roleType, profileId);
.orElse(authorizedBondedRole.getBondUserName());
Optional<String> addresses = authorizedBondedRole.getAddressByTransportTypeMap()
.map(e -> e.values().stream()
.map(Address::getFullAddress)
.collect(Collectors.joining(", ")));
if (addresses.isPresent()) {
return Res.get("authorizedRole.securityManager.selectedBondedNode", roleType, nickNameOrBondName, profileId, addresses.get());
} else {
return Res.get("authorizedRole.securityManager.selectedBondedRole", roleType, nickNameOrBondName, profileId);
}
}

String getBondedRoleDisplayString(AuthorizedBondedRole authorizedBondedRole) {
String getBannedBondedRoleDisplaySString(AuthorizedBondedRole authorizedBondedRole) {
String roleType = authorizedBondedRole.getBondedRoleType().getDisplayString();
String profileId = authorizedBondedRole.getProfileId();
String nickName = userProfileService.findUserProfile(profileId)
String nickNameOrBondName = userProfileService.findUserProfile(profileId)
.map(UserProfile::getNickName)
.orElse(Res.get("data.na"));
return Res.get("authorizedRole.securityManager.alert.table.bannedRole.value", roleType, nickName, profileId);
.orElse(authorizedBondedRole.getBondUserName());
return Res.get("authorizedRole.securityManager.alert.table.bannedRole.value", roleType, nickNameOrBondName, profileId);
}

void onPublishDifficultyAdjustmentFactor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class SecurityManagerModel implements Model {
private final ObservableList<AlertType> alertTypes = FXCollections.observableArrayList();
private final ObjectProperty<BondedRoleListItem> selectedBondedRoleListItem = new SimpleObjectProperty<>();
private final ObservableList<BondedRoleListItem> bondedRoleListItems = FXCollections.observableArrayList();
private final SortedList<BondedRoleListItem> bondedRoleSortedList = new SortedList<>(bondedRoleListItems);
private final StringProperty actionButtonText = new SimpleStringProperty();
private final BooleanProperty actionButtonDisabled = new SimpleBooleanProperty();
private final StringProperty headline = new SimpleStringProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public AlertType fromString(String string) {
}
});

bondedRoleSelection = new AutoCompleteComboBox<>(model.getBondedRoleListItems(), Res.get("authorizedRole.securityManager.selectBondedRole"));
bondedRoleSelection = new AutoCompleteComboBox<>(model.getBondedRoleSortedList(), Res.get("authorizedRole.securityManager.selectBondedRole"));
bondedRoleSelection.setPrefWidth(800);
bondedRoleSelection.setConverter(new StringConverter<>() {
@Override
public String toString(BondedRoleListItem listItem) {
return listItem != null ? listItem.getDisplayString() : "";
return listItem != null ? controller.getBondedRoleDisplayString(listItem.getBondedRole()) : "";
}

@Override
Expand Down Expand Up @@ -321,6 +321,7 @@ private void configAlertTableView() {
.minWidth(150)
.comparator(Comparator.comparing(AlertListItem::getBondedRoleDisplayString))
.valueSupplier(AlertListItem::getBondedRoleDisplayString)
.tooltipSupplier(AlertListItem::getBondedRoleDisplayString)
.build());
alertTableView.getColumns().add(new BisqTableColumn.Builder<AlertListItem>()
.isSortable(false)
Expand Down Expand Up @@ -412,7 +413,7 @@ public AlertListItem(AuthorizedAlertData authorizedAlertData, SecurityManagerCon
minVersion = this.authorizedAlertData.getMinVersion().orElse("");
haltTrading = BooleanFormatter.toYesNo(this.authorizedAlertData.isHaltTrading());
requireVersionForTrading = BooleanFormatter.toYesNo(this.authorizedAlertData.isRequireVersionForTrading());
bondedRoleDisplayString = authorizedAlertData.getBannedRole().map(controller::getBondedRoleDisplayString).orElse("");
bondedRoleDisplayString = authorizedAlertData.getBannedRole().map(controller::getBannedBondedRoleDisplaySString).orElse("");
}
}

Expand All @@ -426,7 +427,7 @@ public static class BondedRoleListItem {

public BondedRoleListItem(BondedRole bondedRole, SecurityManagerController controller) {
this.bondedRole = bondedRole;
displayString = controller.getBondedRoleShortDisplayString(bondedRole);
displayString = controller.getBondedRoleDisplayString(bondedRole);
}
}
}
2 changes: 1 addition & 1 deletion chat/src/main/java/bisq/chat/ChatChannelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void addMessage(M message, C channel) {

protected boolean isValid(M message) {
if (bannedUserService.isUserProfileBanned(message.getAuthorUserProfileId())) {
log.warn("Message invalid as sender is banned");
log.warn("Message invalid as sender is banned. AuthorUserProfileId={}",message.getAuthorUserProfileId());
return false;
}
return true;
Expand Down
3 changes: 2 additions & 1 deletion i18n/src/main/resources/authorized_role.properties
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ authorizedRole.securityManager.emergency.requireVersionForTrading=Require min. v
authorizedRole.securityManager.emergency.requireVersionForTrading.version=Version
authorizedRole.securityManager.emergency.requireVersionForTrading.version.prompt=Enter min. version number (e.g.: `2.1.2`)
authorizedRole.securityManager.selectBondedRole=Select bonded role
authorizedRole.securityManager.selectedBondedRole=Nickname: {0}, Type: {1}, ProfileId: {2}
authorizedRole.securityManager.selectedBondedRole={0}: Nickname: {1}, Profile ID: {2}
authorizedRole.securityManager.selectedBondedNode={0}: Nickname: {1}, Profile ID: {2}, Address: {3}

authorizedRole.securityManager.alert.table.headline=Alerts
authorizedRole.securityManager.alert.table.alertType=Type
Expand Down
1 change: 0 additions & 1 deletion i18n/src/main/resources/authorized_role_cs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ authorizedRole.securityManager.emergency.requireVersionForTrading=Require min. v
authorizedRole.securityManager.emergency.requireVersionForTrading.version=Version
authorizedRole.securityManager.emergency.requireVersionForTrading.version.prompt=Enter min. version number (e.g.: `2.1.2`)
authorizedRole.securityManager.selectBondedRole=Select bonded role
authorizedRole.securityManager.selectedBondedRole=Nickname: {0}, Type: {1}, ProfileId: {2}

authorizedRole.securityManager.alert.table.headline=Alerts
authorizedRole.securityManager.alert.table.alertType=Type
Expand Down
1 change: 0 additions & 1 deletion i18n/src/main/resources/authorized_role_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ authorizedRole.securityManager.emergency.requireVersionForTrading=Mindestversion
authorizedRole.securityManager.emergency.requireVersionForTrading.version=Version
authorizedRole.securityManager.emergency.requireVersionForTrading.version.prompt=Geben Sie die Mindestversionsnummer ein (z. B.: `2.1.2`)
authorizedRole.securityManager.selectBondedRole=Wählen Sie die geprüfte Rolle aus
authorizedRole.securityManager.selectedBondedRole=Spitzname: {0}, Typ: {1}, Profil-ID: {2}

authorizedRole.securityManager.alert.table.headline=Warnungen
authorizedRole.securityManager.alert.table.alertType=Typ
Expand Down
1 change: 0 additions & 1 deletion i18n/src/main/resources/authorized_role_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ authorizedRole.securityManager.emergency.requireVersionForTrading=Requerir versi
authorizedRole.securityManager.emergency.requireVersionForTrading.version=Versión
authorizedRole.securityManager.emergency.requireVersionForTrading.version.prompt=Introduce el número de versión mínima (por ejemplo, `2.1.2`)
authorizedRole.securityManager.selectBondedRole=Seleccionar rol bajo fianza
authorizedRole.securityManager.selectedBondedRole=Apodo: {0}, Tipo: {1}, ID de perfil: {2}

authorizedRole.securityManager.alert.table.headline=Alertas
authorizedRole.securityManager.alert.table.alertType=Tipo
Expand Down
1 change: 0 additions & 1 deletion i18n/src/main/resources/authorized_role_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ authorizedRole.securityManager.emergency.requireVersionForTrading=Richiedi versi
authorizedRole.securityManager.emergency.requireVersionForTrading.version=Versione
authorizedRole.securityManager.emergency.requireVersionForTrading.version.prompt=Inserisci il numero di versione minima (es. '2.1.2')
authorizedRole.securityManager.selectBondedRole=Seleziona ruolo collegato
authorizedRole.securityManager.selectedBondedRole=Nickname: {0}, Tipo: {1}, ID Profilo: {2}

authorizedRole.securityManager.alert.table.headline=Avvisi
authorizedRole.securityManager.alert.table.alertType=Tipo
Expand Down
1 change: 0 additions & 1 deletion i18n/src/main/resources/authorized_role_pcm.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ authorizedRole.securityManager.emergency.requireVersionForTrading=Require min. v
authorizedRole.securityManager.emergency.requireVersionForTrading.version=Version
authorizedRole.securityManager.emergency.requireVersionForTrading.version.prompt=Enter min. version number (e.g.: `2.1.2`)
authorizedRole.securityManager.selectBondedRole=Select bonded role
authorizedRole.securityManager.selectedBondedRole=Nickname: {0}, Type: {1}, ProfileId: {2}

authorizedRole.securityManager.alert.table.headline=Alerts
authorizedRole.securityManager.alert.table.alertType=Type
Expand Down
1 change: 0 additions & 1 deletion i18n/src/main/resources/authorized_role_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ authorizedRole.securityManager.emergency.requireVersionForTrading=Exigir versão
authorizedRole.securityManager.emergency.requireVersionForTrading.version=Versão
authorizedRole.securityManager.emergency.requireVersionForTrading.version.prompt=Insira o número da versão mínima (ex.: `2.1.2`)
authorizedRole.securityManager.selectBondedRole=Selecionar função vinculada
authorizedRole.securityManager.selectedBondedRole=Apelido: {0}, Tipo: {1}, ID do Perfil: {2}

authorizedRole.securityManager.alert.table.headline=Alertas
authorizedRole.securityManager.alert.table.alertType=Tipo
Expand Down
1 change: 0 additions & 1 deletion i18n/src/main/resources/authorized_role_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ authorizedRole.securityManager.emergency.requireVersionForTrading=Требует
authorizedRole.securityManager.emergency.requireVersionForTrading.version=Версия
authorizedRole.securityManager.emergency.requireVersionForTrading.version.prompt=Введите минимальный номер версии (например: `2.1.2`)
authorizedRole.securityManager.selectBondedRole=Выберите подневольную роль
authorizedRole.securityManager.selectedBondedRole=Никнейм: {0}, Тип: {1}, ПрофильId: {2}

authorizedRole.securityManager.alert.table.headline=Оповещения
authorizedRole.securityManager.alert.table.alertType=Тип
Expand Down

0 comments on commit 42d2140

Please sign in to comment.