Merge changes from topic 'hashtags-fixes'

* changes:
  Clean up Actions.CORE
  Fix: Only show Add/Remove Hashtags UI elements if user has capability
This commit is contained in:
David Pursehouse
2015-05-08 09:53:42 +00:00
committed by Gerrit Code Review
3 changed files with 26 additions and 13 deletions

View File

@@ -36,9 +36,8 @@ import java.util.TreeSet;
class Actions extends Composite { class Actions extends Composite {
private static final String[] CORE = { private static final String[] CORE = {
"abandon", "restore", "revert", "topic", "abandon", "cherrypick", "followup", "hashtags", "publish",
"cherrypick", "submit", "rebase", "message", "rebase", "restore", "revert", "submit", "topic", "/"};
"publish", "followup", "/"};
interface Binder extends UiBinder<FlowPanel, Actions> {} interface Binder extends UiBinder<FlowPanel, Actions> {}
private static final Binder uiBinder = GWT.create(Binder.class); 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 REMOVE;
private static final String DATA_ID = "data-id"; private static final String DATA_ID = "data-id";
private boolean canEdit;
static { static {
REMOVE = DOM.createUniqueId().replace('-', '_'); REMOVE = DOM.createUniqueId().replace('-', '_');
init(REMOVE); init(REMOVE);
@@ -121,9 +123,10 @@ public class Hashtags extends Composite {
} }
void set(ChangeInfo info) { void set(ChangeInfo info) {
canEdit = info.has_actions() && info.actions().containsKey("hashtags");
this.changeId = info.legacy_id(); this.changeId = info.legacy_id();
display(info); display(info);
openForm.setVisible(Gerrit.isSignedIn()); openForm.setVisible(canEdit);
} }
@UiHandler("openForm") @UiHandler("openForm")
@@ -165,13 +168,15 @@ public class Hashtags extends Composite {
"#" + PageLinks.toChangeQuery("hashtag:\"" + hashtagName + "\"")) "#" + PageLinks.toChangeQuery("hashtag:\"" + hashtagName + "\""))
.setAttribute("role", "listitem") .setAttribute("role", "listitem")
.append("#").append(hashtagName) .append("#").append(hashtagName)
.closeAnchor() .closeAnchor();
.openElement("button") if (canEdit) {
html.openElement("button")
.setAttribute("title", "Remove hashtag") .setAttribute("title", "Remove hashtag")
.setAttribute("onclick", REMOVE + "(event)") .setAttribute("onclick", REMOVE + "(event)")
.append("×") .append("×")
.closeElement("button") .closeElement("button");
.closeSpan(); }
html.closeSpan();
if (itr.hasNext()) { if (itr.hasNext()) {
html.append(' '); 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.ResourceConflictException;
import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.server.validators.ValidationException; import com.google.gerrit.server.validators.ValidationException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -29,7 +30,8 @@ import java.io.IOException;
import java.util.Set; import java.util.Set;
@Singleton @Singleton
public class PostHashtags implements RestModifyView<ChangeResource, HashtagsInput> { public class PostHashtags implements RestModifyView<ChangeResource, HashtagsInput>,
UiAction<ChangeResource>{
private HashtagsUtil hashtagsUtil; private HashtagsUtil hashtagsUtil;
@Inject @Inject
@@ -51,4 +53,11 @@ public class PostHashtags implements RestModifyView<ChangeResource, HashtagsInpu
throw new ResourceConflictException(e.getMessage()); throw new ResourceConflictException(e.getMessage());
} }
} }
@Override
public UiAction.Description getDescription(ChangeResource resource) {
return new UiAction.Description()
.setLabel("Edit Hashtags")
.setVisible(resource.getControl().canEditHashtags());
}
} }