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

Commit

Permalink
Prevent denied access to workspace with disabled locale: https://bugz…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Oct 3, 2012
1 parent ab22e8d commit 881fc68
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
Expand Up @@ -2,6 +2,8 @@

import java.util.ArrayList;

import net.customware.gwt.presenter.client.EventBus;

import org.zanata.common.LocaleId;
import org.zanata.common.TranslationStats;
import org.zanata.webtrans.client.EventProcessor.StartCallback;
Expand All @@ -27,23 +29,19 @@
import org.zanata.webtrans.shared.rpc.GetDocumentList;
import org.zanata.webtrans.shared.rpc.GetDocumentListResult;
import org.zanata.webtrans.shared.rpc.NoOpResult;

import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Strings;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.ClosingEvent;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

import net.customware.gwt.presenter.client.EventBus;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
Expand Down Expand Up @@ -77,16 +75,14 @@ public void onFailure(Throwable caught)
else if (caught instanceof NoSuchWorkspaceException)
{
Log.error("Invalid workspace", caught);
String errorMessage, linkText, projectListUrl;
errorMessage = "Invalid Workspace. Try opening the workspace from the link on the project page.";
linkText = "Projects";
projectListUrl = getModuleParentBaseUrl() + "project/list";
showErrorWithLink(errorMessage, null, linkText, projectListUrl);
String errorMessage;
errorMessage = "Invalid Workspace. " + caught.getLocalizedMessage() + ". Try opening the workspace from the link on the project page.";
showErrorWithLink(errorMessage, caught);
}
else
{
Log.error("An unexpected Error occurred", caught);
showErrorWithLink("An unexpected Error occurred: " + caught.getMessage(), caught, null, null);
showErrorWithLink("An unexpected Error occurred: " + caught.getMessage(), caught);
}
}

Expand Down Expand Up @@ -134,7 +130,7 @@ public void onSuccess(String connectionId)
@Override
public void onFailure(Throwable e)
{
showErrorWithLink("Server communication failed...", e, null, null);
showErrorWithLink("Server communication failed...", e);
}
@Override
public void onSuccess(NoOpResult result)
Expand All @@ -147,7 +143,7 @@ public void onSuccess(NoOpResult result)
@Override
public void onFailure(Throwable e)
{
showErrorWithLink("Failed to start Event Service...", e, null, null);
showErrorWithLink("Failed to start Event Service...", e);
}
});

Expand Down Expand Up @@ -281,20 +277,13 @@ public static String getModuleParentBaseUrl()
* @param linkText text to display for link
* @param linkUrl href for link
*/
private static void showErrorWithLink(String message, Throwable e, String linkText, String linkUrl)
private static void showErrorWithLink(String message, Throwable e)
{
Label messageLabel = new Label(message);
messageLabel.getElement().addClassName(APP_LOAD_ERROR_CSS_CLASS);
FlowPanel layoutPanel = new FlowPanel();
layoutPanel.add(messageLabel);

if (!Strings.isNullOrEmpty(linkText) && !Strings.isNullOrEmpty(linkUrl))
{
Anchor a = new Anchor(linkText, linkUrl);
a.getElement().addClassName(APP_LOAD_ERROR_CSS_CLASS);
layoutPanel.add(a);
}

if (IS_DEBUG && e != null)
{
String stackTrace = "Stack trace for the error:<br/>\n";
Expand Down
Expand Up @@ -6,24 +6,22 @@

import javax.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Synchronized;
import org.jboss.seam.core.Events;
import org.jboss.seam.web.ServletContexts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zanata.ZanataInit;
import org.zanata.action.ProjectHome;
import org.zanata.action.ProjectIterationHome;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
import org.zanata.dao.AccountDAO;
import org.zanata.dao.ProjectDAO;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HIterationProject;
Expand Down Expand Up @@ -52,7 +50,6 @@

import de.novanic.eventservice.service.registry.EventRegistry;
import de.novanic.eventservice.service.registry.EventRegistryFactory;
import lombok.extern.slf4j.Slf4j;

@Scope(ScopeType.APPLICATION)
@Name("translationWorkspaceManager")
Expand Down Expand Up @@ -254,6 +251,10 @@ private WorkspaceContext validateAndGetWorkspaceContext(WorkspaceId workspaceId)
{
throw new NoSuchWorkspaceException("Invalid Workspace Locale");
}
if (!locale.isActive())
{
throw new NoSuchWorkspaceException("Locale '" + locale.retrieveDisplayName() + "' disabled in server");
}

String workspaceName = project.getName() + " (" + projectIteration.getSlug() + ")";
String localeDisplayName = ULocale.getDisplayName(workspaceId.getLocaleId().toJavaName(), ULocale.ENGLISH);
Expand Down
Expand Up @@ -6,24 +6,11 @@ body {
/*
Styling for errors when webtrans fails to load
*/
.AppLoadError {
margin-top: 20px;
margin-left: 30px;
}

div.AppLoadError {
font-weight: bold;
font-size: 1.5em;
color: #ff2222;
margin-bottom: 15px;
}

a.AppLoadError {
display: block;
font-size: 1.3em;
font-weight: bold;
margin-left: 60px;
margin-bottom: 15px;
color: #ff2222;
padding: 25px;
}

/*
Expand Down

0 comments on commit 881fc68

Please sign in to comment.