Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Mar 27, 2023
2 parents b055eef + d5525c9 commit 2d070d4
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 33 deletions.
6 changes: 3 additions & 3 deletions bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.caconfig.editor.parent</artifactId>
<version>1.15.4</version>
<version>1.15.6</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<groupId>io.wcm</groupId>
<artifactId>io.wcm.caconfig.editor</artifactId>
<version>1.15.4</version>
<version>1.15.6</version>
<packaging>jar</packaging>

<name>Context-Aware Configuration Editor</name>
Expand All @@ -42,7 +42,7 @@
<site.url.module.prefix>caconfig/editor/bundle</site.url.module.prefix>

<!-- Enable reproducible builds -->
<project.build.outputTimestamp>2023-02-24T14:52:49Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2023-03-27T10:08:28Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
package io.wcm.caconfig.editor.model;

import javax.annotation.PostConstruct;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.security.AccessControlManager;
import javax.jcr.security.Privilege;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -30,7 +34,10 @@
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.osgi.annotation.versioning.ProviderType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.replication.Replicator;
import com.day.cq.wcm.api.components.ComponentManager;

import io.wcm.caconfig.editor.impl.ConfigDataServlet;
Expand All @@ -48,9 +55,10 @@ public class EditorConfiguration {
static final String RT_WCMIO_PATHFIELD = "wcm-io/wcm/ui/granite/components/form/pathfield";
static final String PATH_PATHFIELD_STANDARD = "/mnt/overlay/granite/ui/content/coral/foundation/form/pathfield";
static final String PATH_PATHFIELD_WCMIO = "/mnt/overlay/wcm-io/wcm/ui/granite/content/form/pathfield";

static final String PATH_TAGFIELD_CQ = "/mnt/overlay/cq/gui/content/coral/common/form/tagfield";

private static final Logger log = LoggerFactory.getLogger(EditorConfiguration.class);

@SlingObject
private Resource currentResource;
@SlingObject
Expand All @@ -69,6 +77,7 @@ public class EditorConfiguration {
private String tagfieldContentPath;
private String language;
private boolean enabled;
private boolean canReplicate;

@PostConstruct
private void activate() {
Expand All @@ -84,6 +93,7 @@ private void activate() {
this.tagfieldContentPath = buildTagfieldContentPath();
this.language = request.getLocale().getLanguage();
this.enabled = editorConfig.isEnabled();
this.canReplicate = hasPermission(Replicator.REPLICATE_PRIVILEGE);
}

private String buildServletPath(String selector) {
Expand All @@ -105,6 +115,21 @@ private String buildPathfieldContentPath() {
}
}

private boolean hasPermission(String privilegeName) {
Session session = request.getResourceResolver().adaptTo(Session.class);
if (session != null) {
try {
AccessControlManager accessControlManager = session.getAccessControlManager();
Privilege privilege = accessControlManager.privilegeFromName(privilegeName);
return accessControlManager.hasPrivileges(currentResource.getPath(), new Privilege[] { privilege });
}
catch (RepositoryException ex) {
log.warn("Failed to check permission for {}", currentResource.getPath(), ex);
}
}
return false;
}

private String buildTagfieldContentPath() {
return servletContextPathPrefix + PATH_TAGFIELD_CQ;
}
Expand Down Expand Up @@ -145,4 +170,8 @@ public boolean isEnabled() {
return this.enabled;
}

public boolean isCanReplicate() {
return this.canReplicate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Controllers used by the configuration editor scripts internally.
*/
@org.osgi.annotation.versioning.Version("2.3")
@org.osgi.annotation.versioning.Version("2.4")
package io.wcm.caconfig.editor.model;
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@

function PublishServiceProvider() {
var publishUrls = {};
var isCanReplicate = false;
var DOCUMENT_REFERRER_KEY = "document.referrer";

function PublishService($http, $httpParamSerializer, uiService, configService, modalService, restUrls) {
function PublishService($http, $httpParamSerializer, uiService, modalService, restUrls, canReplicate) {
var that = this;

var publish = function (path) {
Expand Down Expand Up @@ -91,7 +92,7 @@
})
.then(
function success(response) {
if (response.data && response.data.assets && response.data.assets.length === 0) {
if (canReplicate && response.data && response.data.assets && response.data.assets.length === 0) {
// Publish directly as there is no asset
publish(path);
}
Expand All @@ -116,9 +117,13 @@
publishUrls = restUrlsPublish;
};

this.$get = ["$http", "$httpParamSerializer", "uiService", "configService", "modalService",
function ($http, $httpParamSerializer, uiService, configService, modalService) {
return new PublishService($http, $httpParamSerializer, uiService, configService, modalService, publishUrls);
this.setCanReplicate = function(canReplicate) {
isCanReplicate = canReplicate
}

this.$get = ["$http", "$httpParamSerializer", "uiService", "modalService",
function ($http, $httpParamSerializer, uiService, modalService) {
return new PublishService($http, $httpParamSerializer, uiService, modalService, publishUrls, isCanReplicate);
}
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ <h1 class="wcm-io-editor caconfig-title" ng-bind="title">${'io.wcm.caconfig.edit
managePublicationUrl: managePublicationUrl,
currentPagePath: currentPagePath
});
publishServiceProvider.setCanReplicate(${editorConfig.canReplicate @ context='uri'});

pathbrowserServiceProvider.setUrls({
pickerSrc: pathfieldPickerSrc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
*/
package io.wcm.caconfig.editor.model;

import io.wcm.caconfig.editor.impl.ConfigDataServlet;
import io.wcm.caconfig.editor.impl.ConfigNamesServlet;
import io.wcm.caconfig.editor.impl.ConfigPersistServlet;
import io.wcm.caconfig.editor.impl.EditorConfig;
import io.wcm.sling.commons.adapter.AdaptTo;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
import static io.wcm.caconfig.editor.model.EditorConfiguration.PATH_PATHFIELD_STANDARD;
import static io.wcm.caconfig.editor.model.EditorConfiguration.PATH_PATHFIELD_WCMIO;
import static io.wcm.caconfig.editor.model.EditorConfiguration.PATH_TAGFIELD_CQ;
import static io.wcm.caconfig.editor.model.EditorConfiguration.RT_WCMIO_PATHFIELD;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.caconfig.resource.ConfigurationResourceResolver;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -34,13 +36,13 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static io.wcm.caconfig.editor.model.EditorConfiguration.PATH_PATHFIELD_STANDARD;
import static io.wcm.caconfig.editor.model.EditorConfiguration.PATH_PATHFIELD_WCMIO;
import static io.wcm.caconfig.editor.model.EditorConfiguration.PATH_TAGFIELD_CQ;
import static io.wcm.caconfig.editor.model.EditorConfiguration.RT_WCMIO_PATHFIELD;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
import io.wcm.caconfig.editor.impl.ConfigDataServlet;
import io.wcm.caconfig.editor.impl.ConfigNamesServlet;
import io.wcm.caconfig.editor.impl.ConfigPersistServlet;
import io.wcm.caconfig.editor.impl.EditorConfig;
import io.wcm.sling.commons.adapter.AdaptTo;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

@ExtendWith(AemContextExtension.class)
@ExtendWith(MockitoExtension.class)
Expand All @@ -63,7 +65,6 @@ void setUp() {
context.currentResource(contentResource);

when(configResourceResolver.getContextPath(contentResource)).thenReturn(SAMPLE_PATH);

}

@Test
Expand All @@ -79,6 +80,7 @@ void testProperties() {
assertEquals(PATH_TAGFIELD_CQ, underTest.getTagfieldContentPath());
assertEquals(DEFAULT_LANGUAGE, underTest.getLanguage());
assertTrue(underTest.isEnabled());
assertFalse(underTest.isCanReplicate());
}

@Test
Expand All @@ -95,6 +97,7 @@ void testProperties_RootContextPath() {
assertEquals(PATH_TAGFIELD_CQ, underTest.getTagfieldContentPath());
assertEquals(DEFAULT_LANGUAGE, underTest.getLanguage());
assertTrue(underTest.isEnabled());
assertFalse(underTest.isCanReplicate());
}

@Test
Expand All @@ -112,6 +115,7 @@ void testProperties_CustomServletContextPath() {
assertEquals(SERVLET_CONTEXT_PATH + PATH_TAGFIELD_CQ, underTest.getTagfieldContentPath());
assertEquals(DEFAULT_LANGUAGE, underTest.getLanguage());
assertTrue(underTest.isEnabled());
assertFalse(underTest.isCanReplicate());
}

@Test
Expand Down
6 changes: 6 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="1.15.6" date="2023-03-27">
<action type="fix" dev="sseifert" issue="13">
"Quick Publish" button should open publication wizard when user does not have crx:replicate permission (to start request for publication workflow).
</action>
</release>

<release version="1.15.4" date="2023-02-24">
<action type="update" dev="sseifert">
Switch to Java 11 as minimum version.
Expand Down
8 changes: 4 additions & 4 deletions package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.caconfig.editor.parent</artifactId>
<version>1.15.4</version>
<version>1.15.6</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<groupId>io.wcm</groupId>
<artifactId>io.wcm.caconfig.editor.package</artifactId>
<version>1.15.4</version>
<version>1.15.6</version>
<packaging>content-package</packaging>
<url>${site.url}/caconfig/editor/</url>

Expand All @@ -40,7 +40,7 @@
<contentPackage.group>wcm-io</contentPackage.group>

<!-- Enable reproducible builds -->
<project.build.outputTimestamp>2023-02-24T14:52:49Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2023-03-27T10:08:28Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand All @@ -49,7 +49,7 @@
<groupId>io.wcm</groupId>
<artifactId>io.wcm.caconfig.editor</artifactId>
<scope>compile</scope>
<version>1.15.4</version>
<version>1.15.6</version>
</dependency>

</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>io.wcm</groupId>
<artifactId>io.wcm.caconfig.editor.parent</artifactId>
<version>1.15.4</version>
<version>1.15.6</version>
<packaging>pom</packaging>

<name>Context-Aware Configuration Editor</name>
Expand All @@ -49,7 +49,7 @@

<properties>
<!-- Enable reproducible builds -->
<project.build.outputTimestamp>2023-02-24T14:52:49Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2023-03-27T10:08:28Z</project.build.outputTimestamp>
</properties>

<build>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.caconfig.editor.parent</artifactId>
<version>1.15.4</version>
<version>1.15.6</version>
<relativePath>parent/pom.xml</relativePath>
</parent>

<groupId>io.wcm</groupId>
<artifactId>io.wcm.caconfig.editor.root</artifactId>
<version>1.15.4</version>
<version>1.15.6</version>
<packaging>pom</packaging>

<name>Context-Aware Configuration Editor</name>
Expand Down
2 changes: 2 additions & 0 deletions src/site/markdown/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public @interface MyConfig {

By implementing an OSGi service for [ConfigurationCategoryProvider][caconfig-configuration-category-provider] you can provide labels for the category names. It's also possible to assign categories programmatically with this service, or apply a default category to configuration definitions which do not have a category assigned.
_To use this, you need to deploy the optional dependency `io.wcm.sling.commons`._
### Disable Editor on Publish
Expand Down
8 changes: 8 additions & 0 deletions src/site/markdown/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ By default, the Context-Aware Configuration Editor does not apply any validation

It is possible to define a validation for text-based input fields validating against predefined or custom rules.

_To use this, you need to deploy the optional dependency `io.wcm.sling.commons`._


### Configuring validation

Expand All @@ -27,6 +29,12 @@ The validator referenced via the `validation` property can be:

The `validationMessage` is displayed to the user when the validation detects an invalid value. It can be a text, or an i18n key looked up in the AEM i18n dictionaries.

Validation support is implemented for the following widget types:

* `textfield`
* `textarea`
* `pathbrowser`


### Validating with Granite UI foundation validators

Expand Down

0 comments on commit 2d070d4

Please sign in to comment.