Skip to content

Commit

Permalink
Merge pull request #3106 from HenrikJannsen/republish-data-of-bonded-…
Browse files Browse the repository at this point in the history
…roles

Republish data of bonded roles
  • Loading branch information
HenrikJannsen authored Jan 17, 2025
2 parents 32c87de + 8031593 commit 4413ddc
Show file tree
Hide file tree
Showing 17 changed files with 422 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public SettableErrorValidator() {
isInvalid.addListener(new WeakChangeListener<>(isInvalidListener));
}

public SettableErrorValidator(String message) {
super(message);

isInvalid.addListener(new WeakChangeListener<>(isInvalidListener));
}

@Override
protected void eval() {
hasErrors.set(getIsInvalid());
Expand All @@ -49,7 +55,6 @@ public BooleanProperty isInvalidProperty() {
}

public void setIsInvalid(boolean isInvalid) {
log.error("setInvalid {}", isInvalid);
this.isInvalid.set(isInvalid);
eval();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import bisq.support.moderator.ReportToModeratorMessage;
import bisq.user.profile.UserProfile;
import bisq.user.profile.UserProfileService;
import de.jensd.fx.fontawesome.AwesomeIcon;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
Expand Down Expand Up @@ -296,7 +297,7 @@ protected void updateItem(ListItem item, boolean empty) {
private Callback<TableColumn<ListItem, ListItem>, TableCell<ListItem, ListItem>> getMessageCellFactory() {
return column -> new TableCell<>() {
private final Label message = new Label();
private final Button icon = BisqIconButton.createCopyIconButton();
private final Button icon = BisqIconButton.createIconButton(AwesomeIcon.EXTERNAL_LINK);
private final HBox hBox = new HBox(message, icon);
private final BisqTooltip tooltip = new BisqTooltip(BisqTooltip.Style.DARK);

Expand All @@ -317,7 +318,13 @@ protected void updateItem(ListItem item, boolean empty) {
tooltip.setText(item.getMessage());
message.setTooltip(tooltip);

icon.setOnAction(e -> ClipboardUtil.copyToClipboard(item.getMessage()));
// icon.setOnAction(e -> ClipboardUtil.copyToClipboard(item.getMessage()));
icon.setOnAction(e -> new Popup()
.headline(Res.get("authorizedRole.moderator.table.message.popup.headline"))
.information(item.getMessage())
.actionButtonText(Res.get("action.copyToClipboard"))
.onAction(()-> ClipboardUtil.copyToClipboard(item.getMessage()))
.show());
setGraphic(hBox);
} else {
icon.setOnAction(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.security.KeyPair;

@Slf4j
public class ReleaseManagerController implements Controller {
@Getter
Expand Down Expand Up @@ -63,6 +65,11 @@ public void onActivate() {
.to(releaseNotificationsService.getReleaseNotifications());

model.getActionButtonDisabled().bind(model.getReleaseNotes().isEmpty().or(model.getVersion().isEmpty()));


KeyPair keyPair = userIdentityService.getSelectedUserIdentity().getIdentity().getKeyBundle().getKeyPair();
releaseNotificationsService.getReleaseNotifications().forEach(releaseNotification ->
releaseManagerService.republishReleaseNotification(releaseNotification, keyPair));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public ReleaseManagerView(ReleaseManagerModel model, ReleaseManagerController co
isPreReleaseCheckBox = new CheckBox(Res.get("authorizedRole.releaseManager.isPreRelease"));
isLauncherUpdateCheckBox = new CheckBox(Res.get("authorizedRole.releaseManager.isLauncherUpdate"));

// For now there is no support for jar based updates so we hide that checkbox
isLauncherUpdateCheckBox.setManaged(false);
isLauncherUpdateCheckBox.setVisible(false);

sendButton = new Button(Res.get("authorizedRole.releaseManager.send"));
sendButton.setDefaultButton(true);
sendButton.setAlignment(Pos.BOTTOM_RIGHT);
Expand All @@ -77,7 +81,7 @@ public ReleaseManagerView(ReleaseManagerModel model, ReleaseManagerController co
VBox.setMargin(sendButton, new Insets(10, 0, 0, 0));
VBox.setMargin(isPreReleaseCheckBox, new Insets(10, 0, 0, 0));
VBox.setMargin(roleInfo, new Insets(20, 0, 0, 0));
this.root.getChildren().addAll(headline,
root.getChildren().addAll(headline,
releaseNotes,
version,
isPreReleaseCheckBox,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;

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

Expand All @@ -62,7 +63,7 @@ public class SecurityManagerController implements Controller {
private final DifficultyAdjustmentService difficultyAdjustmentService;
private Pin userIdentityPin, alertsPin, bondedRoleSetPin, difficultyAdjustmentListItemsPin;
private Subscription messagePin, requireVersionForTradingPin, minVersionPin, selectedBondedRolePin,
difficultyAdjustmentPin;
difficultyAdjustmentPin, bannedAccountDataPin;

public SecurityManagerController(ServiceProvider serviceProvider) {
securityManagerService = serviceProvider.getSupportService().getSecurityManagerService();
Expand Down Expand Up @@ -102,10 +103,20 @@ public void onActivate() {
.map(SecurityManagerView.DifficultyAdjustmentListItem::new)
.to(difficultyAdjustmentService.getAuthorizedDifficultyAdjustmentDataSet());

model.getDifficultyAdjustmentFactor().set(difficultyAdjustmentService.getMostRecentValueOrDefault().get());
difficultyAdjustmentPin = EasyBind.subscribe(model.getDifficultyAdjustmentFactor(), difficultyAdjustmentFactor ->
model.getDifficultyAdjustmentFactorButtonDisabled().set(difficultyAdjustmentFactor == null ||
!isValidDifficultyAdjustmentFactor(difficultyAdjustmentFactor.doubleValue())));
double difficultyAdjustmentFactor = difficultyAdjustmentService.getMostRecentValueOrDefault().get();
model.getDifficultyAdjustmentFactor().set(difficultyAdjustmentFactor);
difficultyAdjustmentPin = EasyBind.subscribe(model.getDifficultyAdjustmentFactor(), factor ->
model.getDifficultyAdjustmentFactorButtonDisabled().set(factor == null ||
!isValidDifficultyAdjustmentFactor(factor.doubleValue())));
bannedAccountDataPin = EasyBind.subscribe(model.getBannedAccountData(), e -> updateSendButtonDisabled());

KeyPair keyPair = userIdentityService.getSelectedUserIdentity().getIdentity().getKeyBundle().getKeyPair();
alertService.getAuthorizedAlertDataSet().forEach(authorizedAlert ->
securityManagerService.rePublishAlert(authorizedAlert, keyPair));

if (difficultyAdjustmentFactor != NetworkLoad.DEFAULT_DIFFICULTY_ADJUSTMENT) {
securityManagerService.publishDifficultyAdjustment(difficultyAdjustmentFactor);
}
}

@Override
Expand All @@ -119,6 +130,7 @@ public void onDeactivate() {
minVersionPin.unsubscribe();
selectedBondedRolePin.unsubscribe();
difficultyAdjustmentPin.unsubscribe();
bannedAccountDataPin.unsubscribe();
}

void onSelectAlertType(AlertType alertType) {
Expand All @@ -140,6 +152,12 @@ void onSendAlert() {
new Popup().warning(Res.get("authorizedRole.securityManager.alert.message.tooLong")).show();
return;
}
String bannedAccountData = model.getBannedAccountData().get();
if (bannedAccountData != null && bannedAccountData.length() > AuthorizedAlertData.MAX_BANNED_ACCOUNT_DATA_LENGTH) {
new Popup().warning(Res.get("authorizedRole.securityManager.bannedAccounts.data.tooLong")).show();
return;
}

SecurityManagerView.BondedRoleListItem bondedRoleListItem = model.getSelectedBondedRoleListItem().get();
Optional<AuthorizedBondedRole> bannedRole = bondedRoleListItem == null ? Optional.empty() :
Optional.ofNullable(bondedRoleListItem.getBondedRole().getAuthorizedBondedRole());
Expand All @@ -149,58 +167,29 @@ void onSendAlert() {
model.getHaltTrading().get(),
model.getRequireVersionForTrading().get(),
StringUtils.toOptional(model.getMinVersion().get()),
bannedRole)
bannedRole,
StringUtils.toOptional(bannedAccountData))
.whenComplete((result, throwable) -> UIThread.run(() -> {
if (throwable != null) {
new Popup().error(throwable).show();
} else {
model.getSelectedAlertType().set(null);
model.getHeadline().set(null);
model.getMessage().set(null);
model.getHaltTrading().set(false);
model.getRequireVersionForTrading().set(false);
model.getMinVersion().set(null);
model.getSelectedBondedRoleListItem().set(null);
}
}));
}

boolean isRemoveDifficultyAdjustmentButtonVisible(AuthorizedAlertData authorizedAlertData) {
return userIdentityService.getSelectedUserIdentity().getId().equals(authorizedAlertData.getSecurityManagerProfileId());
model.getSelectedAlertType().set(null);
model.getHeadline().set(null);
model.getMessage().set(null);
model.getHaltTrading().set(false);
model.getRequireVersionForTrading().set(false);
model.getMinVersion().set(null);
model.getSelectedBondedRoleListItem().set(null);
model.getBannedAccountData().set(null);
}));
}

void onRemoveAlert(AuthorizedAlertData authorizedAlertData) {
UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity();
securityManagerService.removeAlert(authorizedAlertData, userIdentity.getNetworkIdWithKeyPair().getKeyPair());
}

String getBondedRoleDisplayString(BondedRole bondedRole) {
AuthorizedBondedRole authorizedBondedRole = bondedRole.getAuthorizedBondedRole();
String roleType = authorizedBondedRole.getBondedRoleType().getDisplayString().toUpperCase();
String profileId = authorizedBondedRole.getProfileId();
String nickNameOrBondName = userProfileService.findUserProfile(profileId)
.map(UserProfile::getNickName)
.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 getBannedBondedRoleDisplayString(AuthorizedBondedRole authorizedBondedRole) {
String roleType = authorizedBondedRole.getBondedRoleType().getDisplayString();
String profileId = authorizedBondedRole.getProfileId();
String nickNameOrBondName = userProfileService.findUserProfile(profileId)
.map(UserProfile::getNickName)
.orElse(authorizedBondedRole.getBondUserName());
return Res.get("authorizedRole.securityManager.alert.table.bannedRole.value", roleType, nickNameOrBondName, profileId);
}

void onPublishDifficultyAdjustmentFactor() {
double difficultyAdjustmentFactor = model.getDifficultyAdjustmentFactor().get();
if (isValidDifficultyAdjustmentFactor(difficultyAdjustmentFactor)) {
Expand All @@ -215,21 +204,50 @@ void onPublishDifficultyAdjustmentFactor() {
}
}

private static boolean isValidDifficultyAdjustmentFactor(double difficultyAdjustmentFactor) {
return difficultyAdjustmentFactor >= 0 && difficultyAdjustmentFactor <= NetworkLoad.MAX_DIFFICULTY_ADJUSTMENT;
void onRemoveDifficultyAdjustmentListItem(SecurityManagerView.DifficultyAdjustmentListItem item) {
UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity();
securityManagerService.removeDifficultyAdjustment(item.getData(), userIdentity.getNetworkIdWithKeyPair().getKeyPair());
model.getDifficultyAdjustmentFactor().set(difficultyAdjustmentService.getMostRecentValueOrDefault().get());
}


boolean isRemoveDifficultyAdjustmentButtonVisible(AuthorizedDifficultyAdjustmentData data) {
return userIdentityService.getSelectedUserIdentity().getId().equals(data.getSecurityManagerProfileId());
}

void onRemoveDifficultyAdjustmentListItem(SecurityManagerView.DifficultyAdjustmentListItem item) {
UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity();
securityManagerService.removeDifficultyAdjustment(item.getData(), userIdentity.getNetworkIdWithKeyPair().getKeyPair());
model.getDifficultyAdjustmentFactor().set(difficultyAdjustmentService.getMostRecentValueOrDefault().get());
boolean isRemoveDifficultyAdjustmentButtonVisible(AuthorizedAlertData authorizedAlertData) {
return userIdentityService.getSelectedUserIdentity().getId().equals(authorizedAlertData.getSecurityManagerProfileId());
}

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

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

private void applySelectAlertType(AlertType alertType) {
model.getAlertsVisible().set(false);
model.getBondedRoleSelectionVisible().set(false);
model.getBannedAccountDataVisible().set(false);

model.getSelectedAlertType().set(alertType);
switch (alertType) {
case INFO:
Expand All @@ -238,16 +256,25 @@ private void applySelectAlertType(AlertType alertType) {
model.getRequireVersionForTrading().set(false);
model.getMinVersion().set(null);
model.getSelectedBondedRoleListItem().set(null);
model.getAlertsVisible().set(true);
model.getBannedAccountData().set(null);
break;
case EMERGENCY:
model.getSelectedBondedRoleListItem().set(null);
model.getAlertsVisible().set(true);
model.getBannedAccountData().set(null);
break;
case BAN:
model.getHaltTrading().set(false);
model.getRequireVersionForTrading().set(false);
model.getMinVersion().set(null);
model.getHeadline().set(null);
model.getMessage().set(null);
model.getBondedRoleSelectionVisible().set(true);
model.getBannedAccountData().set(null);
break;
case BANNED_ACCOUNT_DATA:
model.getBannedAccountDataVisible().set(true);
break;
}
model.getActionButtonText().set(Res.get("authorizedRole.securityManager.actionButton." + alertType.name()));
Expand All @@ -273,6 +300,15 @@ private void updateSendButtonDisabled() {
case BAN:
model.getActionButtonDisabled().set(model.getSelectedBondedRoleListItem().get() == null);
break;
case BANNED_ACCOUNT_DATA:
boolean isBannedAccountDataEmpty = StringUtils.isEmpty(model.getBannedAccountData().get());
model.getActionButtonDisabled().set(isBannedAccountDataEmpty);
break;
}
}

private static boolean isValidDifficultyAdjustmentFactor(double difficultyAdjustmentFactor) {
return difficultyAdjustmentFactor >= 0 && difficultyAdjustmentFactor <= NetworkLoad.MAX_DIFFICULTY_ADJUSTMENT;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public class SecurityManagerModel implements Model {
private final StringProperty minVersion = new SimpleStringProperty();
private final BooleanProperty haltTrading = new SimpleBooleanProperty();
private final BooleanProperty requireVersionForTrading = new SimpleBooleanProperty();
private final BooleanProperty alertsVisible = new SimpleBooleanProperty();
private final BooleanProperty bondedRoleSelectionVisible = new SimpleBooleanProperty();
private final BooleanProperty bannedAccountDataVisible = new SimpleBooleanProperty();
private final StringProperty bannedAccountData = new SimpleStringProperty();

private final ObservableList<AlertListItem> alertListItems = FXCollections.observableArrayList();
private final SortedList<AlertListItem> sortedAlertListItems = new SortedList<>(alertListItems);
Expand Down
Loading

0 comments on commit 4413ddc

Please sign in to comment.