Fix: Only show Add/Remove Hashtags UI elements if user has capability

The "Add #..." button is visible regardless if the user can add new
hashtags or not.

Already existing hashtags will also display a remove hashtag (×)
button when the user does not have the capability to edit hashtags.

Correct the UI to only show these elements when the user has the
necessary capability.

Change-Id: I6ad104f06f3c9ce4fffb8cdbe8a26b7f59381149
This commit is contained in:
Gustaf Lundh 2015-05-08 10:45:38 +02:00
parent 3772eb551d
commit e28ad680d8
3 changed files with 25 additions and 11 deletions

View File

@ -38,7 +38,7 @@ class Actions extends Composite {
private static final String[] CORE = {
"abandon", "restore", "revert", "topic",
"cherrypick", "submit", "rebase", "message",
"publish", "followup", "/"};
"publish", "followup", "hashtags", "/"};
interface Binder extends UiBinder<FlowPanel, Actions> {}
private static final Binder uiBinder = GWT.create(Binder.class);

View File

@ -51,6 +51,8 @@ public class Hashtags extends Composite {
private static final String REMOVE;
private static final String DATA_ID = "data-id";
private boolean canEdit;
static {
REMOVE = DOM.createUniqueId().replace('-', '_');
init(REMOVE);
@ -121,9 +123,10 @@ public class Hashtags extends Composite {
}
void set(ChangeInfo info) {
canEdit = info.has_actions() && info.actions().containsKey("hashtags");
this.changeId = info.legacy_id();
display(info);
openForm.setVisible(Gerrit.isSignedIn());
openForm.setVisible(canEdit);
}
@UiHandler("openForm")
@ -165,13 +168,15 @@ public class Hashtags extends Composite {
"#" + PageLinks.toChangeQuery("hashtag:\"" + hashtagName + "\""))
.setAttribute("role", "listitem")
.append("#").append(hashtagName)
.closeAnchor()
.openElement("button")
.setAttribute("title", "Remove hashtag")
.setAttribute("onclick", REMOVE + "(event)")
.append("×")
.closeElement("button")
.closeSpan();
.closeAnchor();
if (canEdit) {
html.openElement("button")
.setAttribute("title", "Remove hashtag")
.setAttribute("onclick", REMOVE + "(event)")
.append("×")
.closeElement("button");
}
html.closeSpan();
if (itr.hasNext()) {
html.append(' ');
}

View File

@ -20,6 +20,7 @@ import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.server.validators.ValidationException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@ -29,7 +30,8 @@ import java.io.IOException;
import java.util.Set;
@Singleton
public class PostHashtags implements RestModifyView<ChangeResource, HashtagsInput> {
public class PostHashtags implements RestModifyView<ChangeResource, HashtagsInput>,
UiAction<ChangeResource>{
private HashtagsUtil hashtagsUtil;
@Inject
@ -51,4 +53,11 @@ public class PostHashtags implements RestModifyView<ChangeResource, HashtagsInpu
throw new ResourceConflictException(e.getMessage());
}
}
}
@Override
public UiAction.Description getDescription(ChangeResource resource) {
return new UiAction.Description()
.setLabel("Edit Hashtags")
.setVisible(resource.getControl().canEditHashtags());
}
}