This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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...
1 parent 1a7380a commit ce9ad1956fc34aafd8452004ab735741a1986e0e @carlosmunoz carlosmunoz committed Apr 26, 2012
@@ -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;
@@ -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;
@@ -58,7 +61,10 @@
private String iterationSlug;
private String localeId;
-
+
+ @In
+ private ZanataIdentity identity;
+
@In
private DocumentDAO documentDAO;
@@ -112,6 +118,7 @@ public TransUnitWords getTransUnitWordsForDocument(HDocument doc)
return documentStats.getWordCount();
}
+ @Restrict("#{projectIterationFilesAction.fileUploadAllowed}")
public void uploadFile()
{
TranslationsResource transRes = null;
@@ -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()
@@ -62,7 +62,7 @@
private DocumentDAO documentDAO;
@In(create=true)
- private TranslatedDocService translationResourcesService;
+ private TranslatedDocResourceService translatedDocResourceService;
@In
private FileSystemService fileSystemServiceImpl;
@@ -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;
}
@@ -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);
@@ -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);
@@ -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)
{
@@ -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)
{
@@ -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)
{
@@ -661,4 +661,9 @@ public void copyClosestEquivalentTranslation(HDocument document)
}
}
+ public HProjectIteration getSecuredIteration()
+ {
+ return retrieveAndCheckIteration(false);
+ }
+
}
@@ -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
@@ -149,20 +149,20 @@
@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,
@@ -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)
{
@@ -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)
{
@@ -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;
@@ -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);
@@ -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();
@@ -209,7 +209,7 @@ when
then
check.grant();
end
-
+
@@ -215,7 +215,7 @@ public boolean tryLogin()
eTagUtils
);
- TranslatedDocService translatedDocService = new TranslatedDocService(
+ TranslatedDocResourceService translatedDocResourceService = new TranslatedDocResourceService(
applicationConfiguration,
projectIterationDAO,
projectDAO,
@@ -231,7 +231,7 @@ public boolean tryLogin()
// @formatter:on
resources.add(sourceDocResourceService);
- resources.add(translatedDocService);
+ resources.add(translatedDocResourceService);
}
@BeforeMethod(dependsOnMethods = "prepareRestEasyFramework")

0 comments on commit ce9ad19

Please sign in to comment.