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

Commit

Permalink
make FileService.isDocumentUploadAllowed and .checkValidSourceUploadT…
Browse files Browse the repository at this point in the history
…ype static (mikado method)
  • Loading branch information
davidmason committed Jul 16, 2013
1 parent 44cebb1 commit 8c1533f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions zanata-war/src/main/java/org/zanata/rest/service/FileService.java
Expand Up @@ -268,23 +268,30 @@ private void checkSourceUploadPreconditions(String projectSlug, String iteration
{
throw new ChunkUploadException(Status.UNAUTHORIZED, e.getMessage());
}
checkValidSourceUploadType(uploadForm);
checkValidSourceUploadType(uploadForm, translationFileServiceImpl);
}

private void checkSourceUploadAllowed(String projectSlug, String iterationSlug)
{
if (!isDocumentUploadAllowed(projectSlug, iterationSlug))
if (!isDocumentUploadAllowed(projectSlug, iterationSlug, identity, projectIterationDAO))
{
throw new ChunkUploadException(Status.FORBIDDEN,
"You do not have permission to upload source documents to project-version \""
+ projectSlug + ":" + iterationSlug + "\".");
}
}

private void checkValidSourceUploadType(DocumentFileUploadForm uploadForm)
private static boolean isDocumentUploadAllowed(String projectSlug, String iterationSlug, ZanataIdentity identity, ProjectIterationDAO projIterDAO)
{
HProjectIteration projectIteration = projIterDAO.getBySlug(projectSlug, iterationSlug);
return projectIteration.getStatus() == EntityStatus.ACTIVE && projectIteration.getProject().getStatus() == EntityStatus.ACTIVE
&& identity != null && identity.hasPermission("import-template", projectIteration);
}

private static void checkValidSourceUploadType(DocumentFileUploadForm uploadForm, TranslationFileService transFileService)
{
if (!uploadForm.getFileType().equals(".pot")
&& !translationFileServiceImpl.hasAdapterFor(DocumentType.typeFor(uploadForm.getFileType())))
&& !transFileService.hasAdapterFor(DocumentType.typeFor(uploadForm.getFileType())))
{
throw new ChunkUploadException(Status.BAD_REQUEST,
"The type \"" + uploadForm.getFileType() + "\" specified in form parameter 'type' "
Expand Down Expand Up @@ -578,13 +585,6 @@ private void checkUploadPreconditions(String projectSlug, String iterationSlug,
}
}

private boolean isDocumentUploadAllowed(String projectSlug, String iterationSlug)
{
HProjectIteration projectIteration = projectIterationDAO.getBySlug(projectSlug, iterationSlug);
return projectIteration.getStatus() == EntityStatus.ACTIVE && projectIteration.getProject().getStatus() == EntityStatus.ACTIVE
&& identity != null && identity.hasPermission("import-template", projectIteration);
}

private void parsePotFile(InputStream potStream, String projectSlug, String iterationSlug, String docId, DocumentFileUploadForm uploadForm)
{
parsePotFile(potStream, docId, uploadForm.getFileType(), projectSlug, iterationSlug, useOfflinePo(projectSlug, iterationSlug, docId));
Expand Down

0 comments on commit 8c1533f

Please sign in to comment.