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:
parent
3772eb551d
commit
e28ad680d8
@ -38,7 +38,7 @@ class Actions extends Composite {
|
|||||||
private static final String[] CORE = {
|
private static final String[] CORE = {
|
||||||
"abandon", "restore", "revert", "topic",
|
"abandon", "restore", "revert", "topic",
|
||||||
"cherrypick", "submit", "rebase", "message",
|
"cherrypick", "submit", "rebase", "message",
|
||||||
"publish", "followup", "/"};
|
"publish", "followup", "hashtags", "/"};
|
||||||
|
|
||||||
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);
|
||||||
|
@ -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(' ');
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user