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

Commit

Permalink
Browse files Browse the repository at this point in the history
rhbz870876 disable .po and config file download when project type is …
…not set.
  • Loading branch information
davidmason committed Apr 15, 2013
1 parent 5cd5b62 commit e2291c3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
Expand Up @@ -494,9 +494,20 @@ public void setLocaleId(String localeId)
this.localeId = localeId;
}

public boolean isPoProject()
public boolean isKnownProjectType()
{
ProjectType type = projectIterationDAO.getBySlug(projectSlug, iterationSlug).getProjectType();
return type != null;
}

public boolean isPoProject()
{
HProjectIteration projectIteration = projectIterationDAO.getBySlug(projectSlug, iterationSlug);
ProjectType type = projectIteration.getProjectType();
if (type == null)
{
type = projectIteration.getProject().getDefaultProjectType();
}
return type == ProjectType.Gettext || type == ProjectType.Podir;
}

Expand Down
Expand Up @@ -527,6 +527,10 @@ public void setStatsOption(StatUnit statsOption)
public boolean isPoProject()
{
ProjectType type = getProjectIteration().getProjectType();
if (type == null)
{
type = getProjectIteration().getProject().getDefaultProjectType();
}
return type == ProjectType.Gettext || type == ProjectType.Podir;
}
}
Expand Up @@ -145,7 +145,8 @@ public interface TranslationFileService
String extractExtension(String fileNameOrExtension);

/**
* @return true if the specified document is of type po
* @return true if the specified document is of type po, false if it is any other
* type, including null.
*/
boolean isPoDocument(String projectSlug, String iterationSlug, String docId);

Expand Down
Expand Up @@ -396,6 +396,10 @@ public boolean isPoDocument(String projectSlug, String iterationSlug, String doc
{
HProjectIteration projectIteration = projectIterationDAO.getBySlug(projectSlug, iterationSlug);
ProjectType projectType = projectIteration.getProjectType();
if (projectType == null)
{
projectType = projectIteration.getProject().getDefaultProjectType();
}
if (projectType == ProjectType.Gettext || projectType == ProjectType.Podir)
{
return true;
Expand Down
Expand Up @@ -17,6 +17,7 @@
import org.zanata.dao.TextFlowTargetDAO;
import org.zanata.model.HDocument;
import org.zanata.model.HPerson;
import org.zanata.model.HProjectIteration;
import org.zanata.security.ZanataIdentity;
import org.zanata.service.TranslationFileService;
import org.zanata.service.TranslationStateCache;
Expand Down Expand Up @@ -70,8 +71,18 @@ public GetDocumentListResult execute(GetDocumentList action, ExecutionContext co

Map<String, String> downloadExtensions = new HashMap<String, String>();

ProjectType type = hDoc.getProjectIteration().getProjectType();
if (type == ProjectType.Gettext || type == ProjectType.Podir)
HProjectIteration projectIteration = hDoc.getProjectIteration();
ProjectType type = projectIteration.getProjectType();
if (type == null)
{
type = projectIteration.getProject().getDefaultProjectType();
}

if (type == null)
{
// no .po download link
}
else if (type == ProjectType.Gettext || type == ProjectType.Podir)
{
downloadExtensions.put(".po", "po?docId=" + hDoc.getDocId());
}
Expand Down
1 change: 1 addition & 0 deletions zanata-war/src/main/resources/messages.properties
Expand Up @@ -302,6 +302,7 @@ jsf.iteration.files.DocumentPath=Document Path
jsf.ConfigFileForOfflineTranslation=Offline Translation Config File
jsf.GenerateProjectConfigSingleLocale=Generate project configuration file (zanata.xml) for this version with locale #{projectIterationFilesAction.localeId}
jsf.GenerateProjectConfigForOfflineTranslation=Generate project configuration file (zanata.xml) for this version with locale #{projectIterationFilesAction.localeId}, using special project type 'offlinepo' for use in offline translation of po files.
jsf.ConfigFileDisabledProjectNotSet=Disabled because maintainer has not set project type for this project.

jsf.iteration.files.DownloadAllFiles=Download All Files (zip)
jsf.iteration.files.DownloadAllFiles.title=Download all translated files.
Expand Down
16 changes: 14 additions & 2 deletions zanata-war/src/main/webapp/iteration/files.xhtml
Expand Up @@ -191,12 +191,15 @@
<h:outputText value="#{messages['jsf.iteration.files.dotpo']}"/>
</s:link>
<s:link styleClass="table_link"
rendered="#{!projectIterationFilesAction.isPoDocument(doc.docId)}"
rendered="#{projectIterationFilesAction.knownProjectType and !projectIterationFilesAction.isPoDocument(doc.docId)}"
view="/rest/file/translation/#{projectIterationFilesAction.projectSlug}/#{projectIterationFilesAction.iterationSlug}/#{projectIterationFilesAction.localeId}/offlinepo">
<f:param name="docId" value="#{doc.docId}"/>
<h:outputText value="#{messages['jsf.iteration.files.dotofflinepo']}"
title="#{messages['jsf.iteration.files.dotofflinepo.description']} #{messages['jsf.iteration.files.dotofflinepo.purpose']}"/>
</s:link>
<h:outputText value="#{messages['jsf.iteration.files.dotpo']}"
title="#{messages['jsf.ConfigFileDisabledProjectNotSet']}"
rendered="#{!projectIterationFilesAction.knownProjectType}" />
<h:outputText value="&#160;&#160;&#160;" />
<s:link rendered="#{projectIterationFilesAction.hasOriginal(doc.path, doc.name)}" styleClass="table_link" view="/rest/file/translation/#{projectIterationFilesAction.projectSlug}/#{projectIterationFilesAction.iterationSlug}/#{projectIterationFilesAction.localeId}/baked">
<f:param name="docId" value="#{doc.docId}"/>
Expand Down Expand Up @@ -345,6 +348,8 @@
<span class="icon-edit"/>#{messages['jsf.TranslateGWTDevMode']}
</h:outputLink>



<s:link styleClass="action_link"
rendered="#{projectIterationFilesAction.poProject}"
value="#{messages['jsf.ConfigFileForOfflineTranslation']}"
Expand All @@ -355,14 +360,21 @@
</s:link>

<s:link styleClass="action_link"
rendered="#{!projectIterationFilesAction.poProject}"
rendered="#{projectIterationFilesAction.knownProjectType and !projectIterationFilesAction.poProject}"
value="#{messages['jsf.ConfigFileForOfflineTranslation']}"
title="#{messages['jsf.GenerateProjectConfigForOfflineTranslation']}"
action="#{configurationAction.getOfflinePoConfigData(projectIterationFilesAction.locale)}">
<f:param name="projectSlug" value="#{projectIterationFilesAction.projectSlug}" />
<f:param name="iterationSlug" value="#{projectIterationFilesAction.iterationSlug}" />
</s:link>

<s:link styleClass="action_link disabled"
rendered="#{!projectIterationFilesAction.knownProjectType}"
value="#{messages['jsf.ConfigFileForOfflineTranslation']}"
title="#{messages['jsf.ConfigFileDisabledProjectNotSet']} #{messages['jsf.GenerateProjectConfigSingleLocale']}"
disabled="true">
</s:link>

<ui:param name="downloadAllAllowed" value="#{projectIterationFilesAction.zipFileDownloadAllowed}" />
<a4j:commandLink styleClass="action_link #{downloadAllAllowed ? '' : 'disabled'}"
rendered="#{projectIterationFilesAction.poProject or not downloadAllAllowed}"
Expand Down

0 comments on commit e2291c3

Please sign in to comment.