Skip to content

Commit 2f122c9

Browse files
committed
Merge branch 'sshkey_form_feedback' into master
This brings back in a change that was implemented in a pull request from 2017, but got lost in the chaos of multiple pull requests from intermingling branches. This does not only provide feedback when a SSH key cannot be parsed, but it also does so in a way that the warning goes away when a correct key is added. Admittedly, I have no idea how to properly do this with a Wicket FeedbackMessage, all I could find on Google was highly complicated. Not only does this bring back (or really in) the fix for issue #1226, but it also fixes #984.
2 parents 646231e + 082c6a6 commit 2f122c9

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/main/java/com/gitblit/wicket/GitBlitWebApp.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ gb.emailAddressDescription = The primary email address for receiving notificatio
738738
gb.sshKeys = SSH Keys
739739
gb.sshKeysDescription = SSH public key authentication is a secure alternative to password authentication
740740
gb.addSshKey = Add SSH Key
741+
gb.addSshKeyErrorEmpty = SSH public key empty. Please provide a valid SSH public key
742+
gb.addSshKeyErrorFormat = Not a valid SSH public key format. Please provide a valid SSH public key
741743
gb.key = Key
742744
gb.sshKeyComment = Comment
743745
gb.sshKeyCommentDescription = Enter an optional comment. If blank, the comment will be extracted from the key data.

src/main/java/com/gitblit/wicket/GitBlitWebApp_de.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ gb.emailAddressDescription = Die prim\u00e4re Emailadresse f\u00fcr den Empfang
735735
gb.sshKeys = SSH Keys
736736
gb.sshKeysDescription = SSH Public Key Authentifizierung ist eine sichere Alternative zur Authentifizierung mit Passwort
737737
gb.addSshKey = SSH Key hinzuf\u00fcgen
738+
gb.addSshKeyErrorEmpty = SSH Public Key leer. Bitte geben Sie einen g\u00fltigen SSH Public Key an
739+
gb.addSshKeyErrorFormat = SSH Public Key Format ungültig. Bitte geben Sie einen g\u00fltigen SSH Public Key an
738740
gb.key = Key
739741
gb.sshKeyComment = Kommentar
740742
gb.sshKeyCommentDescription = Geben Sie optional einen Kommentar ein. Falls Sie dies nicht tun, wird der Kommentar aus dem Key extrahiert.

src/main/java/com/gitblit/wicket/panels/SshKeysPanel.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ <h4><wicket:message key="gb.addSshKey"></wicket:message></h4>
3737
<div wicket:id="addKeyData"></div>
3838
<div wicket:id="addKeyPermission"></div>
3939
<div wicket:id="addKeyComment"></div>
40-
40+
<div wicket:id="addKeyFeedback"></div>
41+
4142
<div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addKeyButton" /></div>
4243
</form>
4344
</div>

src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Arrays;
2020
import java.util.List;
2121

22+
import com.gitblit.wicket.WicketUtils;
23+
import org.apache.wicket.Component;
2224
import org.apache.wicket.ajax.AjaxRequestTarget;
2325
import org.apache.wicket.ajax.markup.html.AjaxLink;
2426
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
@@ -63,6 +65,7 @@ protected void onInitialize() {
6365

6466
setOutputMarkupId(true);
6567

68+
final IModel<String> keyFeedback = Model.of("");
6669
final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username));
6770
final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys);
6871
final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {
@@ -90,6 +93,7 @@ public void onClick(AjaxRequestTarget target) {
9093
// update the panel
9194
target.addComponent(SshKeysPanel.this);
9295
}
96+
keyFeedback.setObject("");
9397
}
9498
};
9599
if (!canWriteKeys) {
@@ -123,6 +127,10 @@ public void onClick(AjaxRequestTarget target) {
123127
"span5",
124128
keyComment));
125129

130+
Component addKeyFeedback = new Label("addKeyFeedback", keyFeedback).setOutputMarkupId(true);
131+
WicketUtils.setCssStyle(addKeyFeedback, "color: red; font-weight: bold;");
132+
addKeyForm.add(addKeyFeedback);
133+
126134
addKeyForm.add(new AjaxButton("addKeyButton") {
127135

128136
private static final long serialVersionUID = 1L;
@@ -134,6 +142,8 @@ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
134142
String data = keyData.getObject();
135143
if (StringUtils.isEmpty(data)) {
136144
// do not submit empty key
145+
keyFeedback.setObject(getString("gb.addSshKeyErrorEmpty"));
146+
target.addComponent(addKeyFeedback);
137147
return;
138148
}
139149

@@ -142,6 +152,8 @@ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
142152
key.getPublicKey();
143153
} catch (Exception e) {
144154
// failed to parse the key
155+
keyFeedback.setObject(getString("gb.addSshKeyErrorFormat"));
156+
target.addComponent(addKeyFeedback);
145157
return;
146158
}
147159

@@ -163,9 +175,12 @@ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
163175
keys.clear();
164176
keys.addAll(app().keys().getKeys(user.username));
165177

178+
keyFeedback.setObject("");
179+
166180
// update the panel
167181
target.addComponent(SshKeysPanel.this);
168182
}
183+
else keyFeedback.setObject("Key not added.");
169184
}
170185
});
171186

0 commit comments

Comments
 (0)