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
Add permissions so that traslators can push translations.
Add the appropriate permissions so that translators can both push translations and also upload PO files from the GUI.
Rename the TranslatedDocService tp TranslatedDocResourceService to be in line with the other REST service names.
  • Loading branch information
Carlos Munoz committed Apr 26, 2012
1 parent 1a7380a commit ce9ad19
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
Expand Up @@ -24,6 +24,7 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.faces.FacesMessages;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
Expand All @@ -36,10 +37,12 @@
import org.zanata.exception.ZanataServiceException;
import org.zanata.model.HDocument;
import org.zanata.model.HLocale;
import org.zanata.model.HProjectIteration;
import org.zanata.rest.StringSet;
import org.zanata.rest.dto.extensions.ExtensionType;
import org.zanata.rest.dto.resource.TextFlowTarget;
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.security.ZanataIdentity;
import org.zanata.service.TranslationFileService;
import org.zanata.service.TranslationService;

Expand All @@ -58,7 +61,10 @@ public class ProjectIterationFilesAction
private String iterationSlug;

private String localeId;


@In
private ZanataIdentity identity;

@In
private DocumentDAO documentDAO;

Expand Down Expand Up @@ -112,6 +118,7 @@ public TransUnitWords getTransUnitWordsForDocument(HDocument doc)
return documentStats.getWordCount();
}

@Restrict("#{projectIterationFilesAction.fileUploadAllowed}")
public void uploadFile()
{
TranslationsResource transRes = null;
Expand Down Expand Up @@ -147,7 +154,11 @@ public void uploadFile()

public boolean isFileUploadAllowed()
{
return this.projectIterationDAO.getBySlug(projectSlug, iterationSlug).getStatus() == EntityStatus.ACTIVE;
HProjectIteration projectIteration = this.projectIterationDAO.getBySlug(projectSlug, iterationSlug);
HLocale hLocale = this.localeDAO.findByLocaleId( new LocaleId(localeId) );

return projectIteration.getStatus() == EntityStatus.ACTIVE
&& identity != null && identity.hasPermission("modify-translation", projectIteration, hLocale);
}

public List<HDocument> getIterationDocuments()
Expand Down
Expand Up @@ -62,7 +62,7 @@ public class FileService implements FileResource
private DocumentDAO documentDAO;

@In(create=true)
private TranslatedDocService translationResourcesService;
private TranslatedDocResourceService translatedDocResourceService;

@In
private FileSystemService fileSystemServiceImpl;
Expand All @@ -76,13 +76,13 @@ public FileService()

/* @formatter: off */
public FileService(DocumentDAO documentDAO,
TranslatedDocService translationResourcesService,
TranslatedDocResourceService translatedDocResourceService,
FileSystemService fileSystemServiceImpl,
ResourceUtils resourceUtils)
{
super();
this.documentDAO = documentDAO;
this.translationResourcesService = translationResourcesService;
this.translatedDocResourceService = translatedDocResourceService;
this.fileSystemServiceImpl = fileSystemServiceImpl;
this.resourceUtils = resourceUtils;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public Response downloadTranslationFile( @PathParam("projectSlug") String projec

// Perform translation of Hibernate DTOs to JAXB DTOs
TranslationsResource transRes =
(TranslationsResource) this.translationResourcesService.getTranslations(docId, new LocaleId(locale), extensions, true).getEntity();
(TranslationsResource) this.translatedDocResourceService.getTranslations(docId, new LocaleId(locale), extensions, true).getEntity();
Resource res = this.resourceUtils.buildResource(document);

StreamingOutput output = new POStreamingOutput(res, transRes);
Expand Down
Expand Up @@ -245,7 +245,7 @@ public Response get(@QueryParam("ext") Set<String> extensions)
*/
@Override
@POST
@Restrict("#{s:hasPermission(translationResourcesService.securedIteration, 'import-template')}")
@Restrict("#{s:hasPermission(sourceDocResourceService.securedIteration, 'import-template')}")
public Response post(Resource resource, @QueryParam("ext") Set<String> extensions, @QueryParam("copyTrans") @DefaultValue("true") boolean copytrans)
{
HProjectIteration hProjectIteration = retrieveAndCheckIteration(true);
Expand Down Expand Up @@ -372,7 +372,7 @@ public Response getResource(@PathParam("id") String idNoSlash, @QueryParam("ext"
@Override
@PUT
@Path(RESOURCE_SLUG_TEMPLATE)
@Restrict("#{s:hasPermission(translationResourcesService.securedIteration, 'import-template')}")
@Restrict("#{s:hasPermission(sourceDocResourceService.securedIteration, 'import-template')}")
// /r/{id}
public Response putResource(@PathParam("id") String idNoSlash, Resource resource, @QueryParam("ext") Set<String> extensions, @QueryParam("copyTrans") @DefaultValue("true") boolean copytrans)
{
Expand Down Expand Up @@ -467,7 +467,7 @@ else if (document.isObsolete())
@Override
@DELETE
@Path(RESOURCE_SLUG_TEMPLATE)
@Restrict("#{s:hasPermission(translationResourcesService.securedIteration, 'import-template')}")
@Restrict("#{s:hasPermission(sourceDocResourceService.securedIteration, 'import-template')}")
// /r/{id}
public Response deleteResource(@PathParam("id") String idNoSlash)
{
Expand Down Expand Up @@ -555,7 +555,7 @@ public Response getResourceMeta(@PathParam("id") String idNoSlash, @QueryParam("
@Override
@PUT
@Path(RESOURCE_SLUG_TEMPLATE + "/meta")
@Restrict("#{s:hasPermission(translationResourcesService.securedIteration, 'import-template')}")
@Restrict("#{s:hasPermission(sourceDocResourceService.securedIteration, 'import-template')}")
// /r/{id}/meta
public Response putResourceMeta(@PathParam("id") String idNoSlash, ResourceMeta messageBody, @QueryParam("ext") Set<String> extensions)
{
Expand Down Expand Up @@ -661,4 +661,9 @@ public void copyClosestEquivalentTranslation(HDocument document)
}
}

public HProjectIteration getSecuredIteration()
{
return retrieveAndCheckIteration(false);
}

}
Expand Up @@ -82,14 +82,14 @@
import static org.zanata.service.impl.TranslationServiceImpl.validateExtensions;

@Name("translationResourcesService")
@Path(TranslatedDocService.SERVICE_PATH)
@Path(TranslatedDocResourceService.SERVICE_PATH)
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Transactional
/**
* This service allows clients to push and pull both source documents and translations.
*/
public class TranslatedDocService implements TranslatedDocResource
public class TranslatedDocResourceService implements TranslatedDocResource
{

// security actions
Expand Down Expand Up @@ -149,20 +149,20 @@ public class TranslatedDocService implements TranslatedDocResource
@In
private TranslationService translationServiceImpl;

private final Log log = Logging.getLog(TranslatedDocService.class);
private final Log log = Logging.getLog(TranslatedDocResourceService.class);

@In
private LocaleService localeServiceImpl;


public TranslatedDocService()
public TranslatedDocResourceService()
{
}

// TODO break up this class (too many responsibilities)

// @formatter:off
public TranslatedDocService(
public TranslatedDocResourceService(
ApplicationConfiguration applicationConfiguration,
ProjectIterationDAO projectIterationDAO,
ProjectDAO projectDAO,
Expand Down Expand Up @@ -298,7 +298,7 @@ public Response getTranslations(
@Override
@DELETE
@Path(RESOURCE_SLUG_TEMPLATE + "/translations/{locale}")
@Restrict("#{s:hasPermission(translationResourcesService.securedIteration, 'import-translation')}")
@Restrict("#{s:hasPermission(translatedDocResourceService.securedIteration, 'modify-translation')}")
// /r/{id}/translations/{locale}
public Response deleteTranslations(@PathParam("id") String idNoSlash, @PathParam("locale") LocaleId locale)
{
Expand Down Expand Up @@ -358,7 +358,7 @@ public Response deleteTranslations(@PathParam("id") String idNoSlash, @PathParam
@Override
@PUT
@Path(RESOURCE_SLUG_TEMPLATE + "/translations/{locale}")
@Restrict("#{s:hasPermission(translationResourcesService.securedIteration, 'import-translation')}")
@Restrict("#{s:hasPermission(translatedDocResourceService.securedIteration.project, 'modify-translation')}")
// /r/{id}/translations/{locale}
public Response putTranslations(@PathParam("id") String idNoSlash, @PathParam("locale") LocaleId locale, TranslationsResource messageBody, @QueryParam("ext") Set<String> extensions, @QueryParam("merge") @DefaultValue("auto") String merge)
{
Expand Down
Expand Up @@ -42,7 +42,7 @@
import org.zanata.model.HSimpleComment;
import org.zanata.model.HTextFlow;
import org.zanata.model.HTextFlowTarget;
import org.zanata.rest.service.TranslatedDocService;
import org.zanata.rest.service.TranslatedDocResourceService;
import org.zanata.service.CopyTransService;
import org.zanata.service.LocaleService;

Expand Down Expand Up @@ -81,7 +81,7 @@ public CopyTransServiceImpl(LocaleService localeServiceImpl,
}
// @formatter:off

@Observer(TranslatedDocService.EVENT_COPY_TRANS)
@Observer(TranslatedDocResourceService.EVENT_COPY_TRANS)
public void execute(Long docId, String project, String iterationSlug)
{
HDocument document = documentDAO.findById(docId, true);
Expand Down
4 changes: 2 additions & 2 deletions zanata-war/src/main/resources/security.drl
Expand Up @@ -145,7 +145,7 @@ when
)
check: PermissionCheck(
target == $iter,
action == "insert" || action == "update" || action == "import-template" || action == "import-translation",
action == "insert" || action == "update" || action == "import-template",
granted == false)
then
check.grant();
Expand Down Expand Up @@ -209,7 +209,7 @@ when
then
check.grant();
end




Expand Down
Expand Up @@ -215,7 +215,7 @@ public boolean tryLogin()
eTagUtils
);

TranslatedDocService translatedDocService = new TranslatedDocService(
TranslatedDocResourceService translatedDocResourceService = new TranslatedDocResourceService(
applicationConfiguration,
projectIterationDAO,
projectDAO,
Expand All @@ -231,7 +231,7 @@ public boolean tryLogin()
// @formatter:on

resources.add(sourceDocResourceService);
resources.add(translatedDocService);
resources.add(translatedDocResourceService);
}

@BeforeMethod(dependsOnMethods = "prepareRestEasyFramework")
Expand Down

0 comments on commit ce9ad19

Please sign in to comment.