Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/45
Browse files Browse the repository at this point in the history
  • Loading branch information
royteeuwen committed Nov 14, 2024
2 parents 8aca2d1 + 0628b5a commit 01d52f6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Updated terminology to message entry and key instead of label [#33] [#33](https://github.com/orbinson/aem-dictionary-translator/issues/24)
- Updated terminology to message entry and key instead of label [#33]https://github.com/orbinson/aem-dictionary-translator/issues/33)
- Add option to publish to preview [#43](https://github.com/orbinson/aem-dictionary-translator/issues/43)
- Added /conf as editable root for dictionaries [#46](https://github.com/orbinson/aem-dictionary-translator/issues/46)

### Fixed

- Fix publication error on too many keys selected [#45](https://github.com/orbinson/aem-dictionary-translator/issues/45)
- Fix publication timeout error on too large dictionary [#44](https://github.com/orbinson/aem-dictionary-translator/issues/44)
- Updated terminology to message entry and key instead of label [#33](https://github.com/orbinson/aem-dictionary-translator/issues/33)

## [1.1.4] - 2024-09-16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public List<String> getLanguages() {

@Override
public boolean isEditable() {
return resource.getPath().startsWith("/content");
return dictionaryService.isEditableDictionary(resource.getPath());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

public interface DictionaryService {

boolean isEditableDictionary(String path);

List<Resource> getDictionaries(ResourceResolver resourceResolver);

void createDictionary(Resource parent, String name, String[] languages, String basename) throws PersistenceException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class DictionaryServiceImpl implements DictionaryService {

private static final Logger LOG = LoggerFactory.getLogger(DictionaryServiceImpl.class);
private static final String SLING_BASENAME = "sling:basename";
private static final List<String> EDITABLE_ROOTS = List.of("/content/", "/conf/");

@Reference
private TranslationConfig translationConfig;
Expand All @@ -42,6 +43,10 @@ public class DictionaryServiceImpl implements DictionaryService {
@Reference
private Replicator replicator;

public boolean isEditableDictionary(String path) {
return EDITABLE_ROOTS.stream().anyMatch(path::startsWith);
}

public void addLanguage(Resource dictionary, String language, String basename) throws PersistenceException {
Map<String, Object> properties = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package be.orbinson.aem.dictionarytranslator.servlets.rendercondition;

import be.orbinson.aem.dictionarytranslator.services.DictionaryService;
import com.adobe.granite.ui.components.Config;
import com.adobe.granite.ui.components.ExpressionHelper;
import com.adobe.granite.ui.components.ExpressionResolver;
import com.adobe.granite.ui.components.rendercondition.RenderCondition;
import com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
import org.jetbrains.annotations.NotNull;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;

@Component(service = Servlet.class)
@SlingServletResourceTypes(resourceTypes = "aem-dictionary-translator/components/rendercondition/editable-dictionary")
public class EditableDictionaryRenderCondition extends SlingSafeMethodsServlet {

@Reference
private DictionaryService dictionaryService;

@Reference
private ExpressionResolver expressionResolver;

@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws ServletException, IOException {
ExpressionHelper expressionHelper = new ExpressionHelper(expressionResolver, request);
String path = expressionHelper.getString(new Config(request.getResource()).get("path"));
request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(dictionaryService.isEditableDictionary(path)));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -17,7 +16,7 @@
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -73,4 +72,17 @@ void returnsCorrectLanguages() {
assertEquals("en", languages.get(1));
}


@Test
public void testIsEditableDictionary() {
// Test cases where the path should be editable
assertTrue(dictionaryService.isEditableDictionary("/content/example"), "Path starting with /content/ should be editable");
assertTrue(dictionaryService.isEditableDictionary("/conf/example"), "Path starting with /conf/ should be editable");

// Test cases where the path should not be editable
assertFalse(dictionaryService.isEditableDictionary("/other/example"), "Path not starting with /content/ or /conf/ should not be editable");
assertFalse(dictionaryService.isEditableDictionary("/configuration"), "Path starting with /configuration should not be editable");
assertFalse(dictionaryService.isEditableDictionary("/contents"), "Path starting with /contents should not be editable");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
src.uritemplate="/apps/aem-dictionary-translator/content/granite/dialog/dictionary/key/create.html${requestPathInfo.suffix}"/>
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:contains(granite:relativeParent(requestPathInfo.suffix, 0), '/content')}"/>
sling:resourceType="aem-dictionary-translator/components/rendercondition/editable-dictionary"
path="${requestPathInfo.suffix}"/>
</create-key>
</primary>
<selection jcr:primaryType="nt:unstructured">
Expand All @@ -55,8 +55,8 @@
src.uritemplate="/apps/aem-dictionary-translator/content/granite/dialog/dictionary/key/update.html{?item*}"/>
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:contains(granite:relativeParent(requestPathInfo.suffix, 0), '/content')}"/>
sling:resourceType="aem-dictionary-translator/components/rendercondition/editable-dictionary"
path="${requestPathInfo.suffix}"/>
</edit>
<delete
jcr:primaryType="nt:unstructured"
Expand All @@ -71,8 +71,8 @@
src.uritemplate="/apps/aem-dictionary-translator/content/granite/dialog/dictionary/key/delete.html{?item*}"/>
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:contains(granite:relativeParent(requestPathInfo.suffix, 0), '/content')}"/>
sling:resourceType="aem-dictionary-translator/components/rendercondition/editable-dictionary"
path="${requestPathInfo.suffix}"/>
</delete>
<publish
jcr:primaryType="nt:unstructured"
Expand All @@ -85,8 +85,8 @@
text="Publish">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:contains(granite:relativeParent(requestPathInfo.suffix, 0), '/content')}"/>
sling:resourceType="aem-dictionary-translator/components/rendercondition/editable-dictionary"
path="${requestPathInfo.suffix}"/>
</publish>
<publish-to-preview
jcr:primaryType="nt:unstructured"
Expand All @@ -98,8 +98,8 @@
text="Publish to Preview">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:contains(granite:relativeParent(requestPathInfo.suffix, 0), '/content')}"/>
sling:resourceType="aem-dictionary-translator/components/rendercondition/editable-dictionary"
path="${requestPathInfo.suffix}"/>
<data jcr:primaryType="nt:unstructured"
agentId="preview"/>
</publish-to-preview>
Expand Down

0 comments on commit 01d52f6

Please sign in to comment.