Skip to content

Commit

Permalink
Merge branch 'master' into 28645-use-treeselect-in-sitefolder-at-edit…
Browse files Browse the repository at this point in the history
…-content
  • Loading branch information
nicobytes authored Jun 7, 2024
2 parents 367bbc4 + 69c6a0f commit c85ba34
Show file tree
Hide file tree
Showing 18 changed files with 932 additions and 358 deletions.
7 changes: 7 additions & 0 deletions .github/actions/publish-npm-cli/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ inputs:
reuse-previous-build:
description: 'Indicates if the workflow should reuse the previous build'
required: false
outputs:
npm-package-version:
description: 'NPM package version'
value: ${{ steps.npm-version-tag.outputs.npm-package-version }}
npm-package-version-tag:
description: 'NPM package version tag'
value: ${{ steps.npm-version-tag.outputs.npm-package-version-tag }}

runs:
using: "composite"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-test-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
EE_REPO_PASSWORD: ${{ secrets.EE_REPO_PASSWORD }}
DEVELOPERS_SLACK_WEBHOOK: ${{ secrets.DEVELOPERS_SLACK_WEBHOOK }}
NPM_ORG_TOKEN: ${{ secrets.NPM_ORG_TOKEN }}
DEV_REQUEST_TOKEN: ${{ secrets.DEV_REQUEST_TOKEN }}
finalize:
name: Finalize
if: always()
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/reusable-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,28 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: CLI Publish
id: cli_publish
if: inputs.publish-npm-package
uses: ./.github/actions/publish-npm-cli
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
npm-token: ${{ secrets.NPM_ORG_TOKEN }}
reuse-previous-build: ${{ inputs.reuse-previous-build }}

- name: Slack Notification (dotCLI announcement)
if: inputs.publish-npm-package
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL: "log-dotcli"
SLACK_TITLE: "Important news!"
SLACK_MESSAGE: "This automated script is happy to announce that a new dotCLI version has been built for *${{ inputs.environment }}* with tags: [ ${{ steps.cli_publish.outputs.npm-package-version }}, ${{ steps.cli_publish.outputs.npm-package-version-tag }} ] is now available on the NPM registry :package:!"
SLACK_USERNAME: dotBot
SLACK_MSG_AUTHOR: " "
MSG_MINIMAL: true
SLACK_FOOTER: ""
SLACK_ICON: https://avatars.slack-edge.com/temp/2021-12-08/2830145934625_e4e464d502865ff576e4.png

# A Slack notification is sent using the 'action-slack-notify' action if the repository is 'dotcms/core'.
- name: Slack Notification
if: github.repository == 'dotcms/core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.PermissionAPI;
import com.dotmarketing.business.Theme;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.portlets.containers.business.ContainerAPI;
import com.dotmarketing.portlets.containers.model.Container;
import com.dotmarketing.portlets.containers.model.ContainerView;
Expand All @@ -14,9 +15,12 @@
import com.dotmarketing.portlets.templates.design.bean.TemplateLayoutColumn;
import com.dotmarketing.portlets.templates.design.bean.TemplateLayoutRow;
import com.dotmarketing.portlets.templates.model.Template;
import com.dotmarketing.portlets.templates.model.TemplateWrapper;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.google.common.annotations.VisibleForTesting;
import com.liferay.portal.language.LanguageException;
import com.liferay.portal.language.LanguageUtil;
import com.liferay.portal.model.User;
import io.vavr.control.Try;

Expand Down Expand Up @@ -70,6 +74,7 @@ public Host getHost (final String hostId, final Supplier<Host> hostSupplier) {
* @return The {@link TemplateView} object with the Template data.
*/
public TemplateView toTemplateView(final Template template, final User user) {

final TemplateLayout layout = UtilMethods.isSet(template.getDrawedBody()) ?
DotTemplateTool.getTemplateLayout(template.getDrawedBody()) : null;
final Theme templateTheme =
Expand All @@ -78,7 +83,19 @@ public TemplateView toTemplateView(final Template template, final User user) {
if (null != templateTheme) {
template.setThemeName(templateTheme.getName());
}
return new TemplateView.Builder()

Host parentHost = null;
if(template instanceof TemplateWrapper) {
parentHost = ((TemplateWrapper) template).getHost();
} else {
try{
parentHost = APILocator.getTemplateAPI().getTemplateHost(template);
}catch(DotDataException e){
Logger.warn(this, "Could not find host for template = " + template.getIdentifier());
}
}

final TemplateView.Builder builder = new TemplateView.Builder()
.name(template.getName())
.friendlyName(template.getFriendlyName())
.title(template.getTitle())
Expand Down Expand Up @@ -118,8 +135,29 @@ public TemplateView toTemplateView(final Template template, final User user) {
.sortOrder(template.getSortOrder())
.layout(this.toLayoutView(layout))
.containers(this.findContainerInLayout(layout))
.themeInfo(null != templateTheme ? new ThemeView(templateTheme) : null)
.build();
.themeInfo(null != templateTheme ? new ThemeView(templateTheme) : null);

if (template.isAnonymous()){
try {
final String customLayoutTemplateLabel = LanguageUtil.get("editpage.properties.template.custom.label");
builder.fullTitle(customLayoutTemplateLabel);
builder.htmlTitle(customLayoutTemplateLabel);
} catch (LanguageException e) {
Logger.error(this.getClass(),
"Exception on toTemplateView exception message: " + e.getMessage(), e);
}
} else if(parentHost != null) {
builder.hostName(parentHost.getHostname());
builder.hostId(parentHost.getIdentifier());

builder.fullTitle(template.getTitle() + " (" + parentHost.getHostname() + ")" );
builder.htmlTitle("<div>" + template.getTitle() + "</div><small>" + parentHost.getHostname() + "</div></small>" );
} else {
builder.fullTitle(template.getTitle());
builder.htmlTitle(template.getTitle());
}

return builder.build();
}

public TemplateLayout toTemplateLayout(final TemplateLayoutView templateLayoutView) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.dotcms.rest.api.v1.template;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

/**
* TemplateImageForm
*/
public class TemplateImageForm implements Serializable {

@JsonProperty("templateId")
private String templateId;

@JsonCreator
public TemplateImageForm(@JsonProperty("templateId") final String templateId) {
this.templateId = templateId;
}

public String getTemplateId() {
return templateId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.dotcms.util.pagination.OrderDirection;
import com.dotcms.util.pagination.TemplatePaginator;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Identifier;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.Theme;
import com.dotmarketing.business.web.HostWebAPI;
Expand All @@ -20,9 +21,11 @@
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.containers.business.ContainerAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.templates.business.TemplateAPI;
import com.dotmarketing.portlets.templates.design.bean.TemplateLayout;
import com.dotmarketing.portlets.templates.design.util.DesignTemplateUtil;
import com.dotmarketing.portlets.templates.factories.TemplateFactory;
import com.dotmarketing.portlets.templates.model.Template;
import com.dotmarketing.util.ActivityLogger;
import com.dotmarketing.util.InodeUtils;
Expand Down Expand Up @@ -802,4 +805,55 @@ public final Response delete(@Context final HttpServletRequest request,
new BulkResultView(deletedTemplatesCount,0L,failedToDelete)))
.build();
}

/**
* Return the image contentlet of a template (if exists, otherwise return 404)
*
* @param httpRequest
* @param httpResponse
* @param templateId template identifier to get the live version.
* @return
* @throws DotSecurityException
* @throws DotDataException
*/
@POST
@Path("/image")
@JSONP
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
public Map<String, Object> fetchTemplateImage(@Context final HttpServletRequest httpRequest,
@Context final HttpServletResponse httpResponse,
final TemplateImageForm templateImageForm) throws DotDataException, DotSecurityException {

final InitDataObject initData = new WebResource.InitBuilder(webResource)
.requestAndResponse(httpRequest, httpResponse).rejectWhenNoUser(true).init();
final User user = initData.getUser();
final PageMode mode = PageMode.get(httpRequest);
final String templateId = templateImageForm.getTemplateId();

Logger.debug(this, ()-> "Getting the image working template by id: " + templateId);
final Template template = this.templateAPI.findWorkingTemplate(templateId, user, mode.respectAnonPerms);
if (null != template && UtilMethods.isSet(template.getIdentifier())) {

final Identifier imageIdentifier = APILocator.getIdentifierAPI().find(template.getImage());
if (UtilMethods.isSet(imageIdentifier.getAssetType()) && imageIdentifier.getAssetType().equals("contentlet")) {

final Optional<Contentlet> imageContentletOpt = templateAPI.getImageContentlet(template);
if (imageContentletOpt.isPresent()) {

final Contentlet imageContentlet = imageContentletOpt.get();
final Map<String, Object> toReturn = new HashMap<>();
toReturn.put("inode", imageContentlet.getInode());
toReturn.put("name", imageContentlet.getTitle());
toReturn.put("identifier", imageContentlet.getIdentifier());
toReturn.put("extension", UtilMethods.getFileExtension(imageContentlet.getTitle()));
return toReturn;
}
}
}

throw new DoesNotExistException("Working Version of the Template with Id: " + templateId + " does not exist");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class TemplateView {
private final Set<ContainerView> containers;
private final ThemeView themeInfo;

private final String hostName;
private final String hostId;
private final String fullTitle;
private final String htmlTitle;

private TemplateView(final Builder builder) {
this.identifier = builder.identifier;
this.inode = builder.inode;
Expand Down Expand Up @@ -94,6 +99,26 @@ private TemplateView(final Builder builder) {
this.layout = builder.layout;
this.containers = builder.containers;
this.themeInfo = builder.themeInfo;
this.hostName = builder.hostName;
this.hostId = builder.hostId;
this.fullTitle = builder.fullTitle;
this.htmlTitle = builder.htmlTitle;
}

public String getHostName() {
return hostName;
}

public String getHostId() {
return hostId;
}

public String getFullTitle() {
return fullTitle;
}

public String getHtmlTitle() {
return htmlTitle;
}

public Map<String, ContainerView> getContainers() {
Expand Down Expand Up @@ -290,6 +315,31 @@ public static final class Builder {
private Set<ContainerView> containers;
private ThemeView themeInfo;

private String hostName;
private String hostId;
private String fullTitle;
private String htmlTitle;

public Builder hostName(final String hostName) {
this.hostName = hostName;
return this;
}

public Builder hostId(final String hostId) {
this.hostId = hostId;
return this;
}

public Builder fullTitle(final String fullTitle) {
this.fullTitle = fullTitle;
return this;
}

public Builder htmlTitle(final String htmlTitle) {
this.htmlTitle = htmlTitle;
return this;
}

public Builder containers (final Set<ContainerView> containers) {

this.containers = containers;
Expand Down
Loading

0 comments on commit c85ba34

Please sign in to comment.