Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz978666 - prevent blank comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Jul 23, 2013
1 parent 4211ab3 commit 37074d2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
Expand Up @@ -40,6 +40,7 @@
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.validator.constraints.NotEmpty;
import org.zanata.common.ContentState;

import lombok.AccessLevel;
Expand Down Expand Up @@ -73,7 +74,7 @@ public class HTextFlowTargetReviewComment extends ModelEntityBase
@Getter
private HTextFlowTarget textFlowTarget;

@NotNull
@NotEmpty
@Type(type = "text")
@Getter
private String comment;
Expand Down
Expand Up @@ -554,6 +554,6 @@ public interface WebTransMessages extends Messages
@DefaultMessage("Remove from comparison")
String removeFromComparison();

@DefaultMessage("Enter reject reason or close to cancel")
@DefaultMessage("Why is this translation rejected?")
String rejectCommentTitle();
}
Expand Up @@ -50,7 +50,10 @@ public ReviewCommentInputWidget()
@UiHandler("addCommentButton")
public void onAddCommentButtonClick(ClickEvent event)
{
listener.addComment(commentTextArea.getText());
if (!commentTextArea.getValue().trim().isEmpty())
{
listener.addComment(commentTextArea.getText());
}
}

public void setListener(ForceReviewCommentDisplay.Listener listener)
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.ui.DialogBoxCloseButton;
import org.zanata.webtrans.client.ui.ReviewCommentInputWidget;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.inject.Inject;
Expand All @@ -50,7 +51,9 @@ public ForceReviewCommentWidget(WebTransMessages messages)
panel.setStyleName("new-zanata");
panel.setWidth("800px");
panel.add(inputWidget);
panel.add(new DialogBoxCloseButton(this));
DialogBoxCloseButton button = new DialogBoxCloseButton(this);
button.setText(messages.cancel());
panel.add(button);
setWidget(panel);
}

Expand Down
Expand Up @@ -21,6 +21,7 @@

package org.zanata.webtrans.server.rpc;

import org.apache.commons.lang.StringUtils;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
Expand All @@ -42,6 +43,8 @@
import org.zanata.webtrans.shared.rpc.AddReviewCommentAction;
import org.zanata.webtrans.shared.rpc.AddReviewCommentResult;
import org.zanata.webtrans.shared.rpc.TransUnitUpdated;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;

import lombok.extern.slf4j.Slf4j;
import net.customware.gwt.dispatch.server.ExecutionContext;
Expand Down Expand Up @@ -71,6 +74,8 @@ public class AddReviewCommentHandler extends AbstractActionHandler<AddReviewComm
@Override
public AddReviewCommentResult execute(AddReviewCommentAction action, ExecutionContext context) throws ActionException
{
throwExceptionIfCommentIsInvalid(action);

SecurityService.SecurityCheckResult securityCheckResult = securityServiceImpl.checkPermission(action, SecurityService.TranslationAction.MODIFY);
HLocale hLocale = securityCheckResult.getLocale();
TranslationWorkspace workspace = securityCheckResult.getWorkspace();
Expand All @@ -89,6 +94,14 @@ public AddReviewCommentResult execute(AddReviewCommentAction action, ExecutionCo
return new AddReviewCommentResult(toDTO(hComment));
}

private void throwExceptionIfCommentIsInvalid(AddReviewCommentAction action) throws ActionException
{
if (StringUtils.isBlank(action.getContent()))
{
throw new ActionException("comment can not be blank");
}
}

private void publishTransUnitUpdatedEvent(AddReviewCommentAction action, HLocale hLocale, HTextFlowTarget hTextFlowTarget, TranslationWorkspace workspace)
{
HTextFlow textFlow = hTextFlowTarget.getTextFlow();
Expand Down
Expand Up @@ -92,6 +92,15 @@ public void setUp() throws Exception
// @formatter:on
}

@Test(expectedExceptions = ActionException.class)
public void testExecuteWithBlankComment() throws ActionException
{
String blankComment = " \t \n";
AddReviewCommentAction action = new AddReviewCommentAction(new TransUnitId(1L), blankComment, documentId);

handler.execute(action, null);
}

@Test
public void testExecute() throws Exception
{
Expand Down

0 comments on commit 37074d2

Please sign in to comment.