Skip to content

Commit

Permalink
Merge branch 'main' into 169-webhooks-should-support-authorization
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/resources/webapp/pdf-exporter-admin/pages/webhooks.jsp
  • Loading branch information
grigoriev committed Sep 2, 2024
2 parents 33e787d + c2f3b69 commit 792c662
Show file tree
Hide file tree
Showing 32 changed files with 225 additions and 722 deletions.
8 changes: 2 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ch.sbb.polarion.extensions</groupId>
<artifactId>ch.sbb.polarion.extension.generic</artifactId>
<version>6.7.0</version>
<version>7.0.0</version>
</parent>

<artifactId>ch.sbb.polarion.extension.pdf-exporter</artifactId>
Expand Down Expand Up @@ -59,6 +59,7 @@

<maven-jar-plugin.Extension-Context>pdf-exporter</maven-jar-plugin.Extension-Context>
<maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.pdf_exporter</maven-jar-plugin.Automatic-Module-Name>
<maven-jar-plugin.Discover-Base-Package>ch.sbb.polarion.extension.pdf.exporter</maven-jar-plugin.Discover-Base-Package>
<web.app.name>${maven-jar-plugin.Extension-Context}</web.app.name>

<!--suppress UnresolvedMavenProperty -->
Expand Down Expand Up @@ -109,11 +110,6 @@
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
</dependency>
<dependency>
<groupId>com.google.re2j</groupId>
<artifactId>re2j</artifactId>
<version>${re2j.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ch.sbb.polarion.extension.pdf.exporter;

import ch.sbb.polarion.extension.generic.GenericUiServlet;
import ch.sbb.polarion.extension.generic.properties.CurrentExtensionConfiguration;
import ch.sbb.polarion.extension.pdf.exporter.properties.PdfExporterExtensionConfiguration;

import java.io.Serial;

Expand All @@ -13,6 +11,5 @@ public class PdfExporterAdminUiServlet extends GenericUiServlet {

public PdfExporterAdminUiServlet() {
super("pdf-exporter-admin");
CurrentExtensionConfiguration.getInstance().setExtensionConfiguration(PdfExporterExtensionConfiguration.getInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private String adjustWebhooks(String scope, String form, StylePackageModel style
Collection<SettingName> webhooksNames = getSettingNames(WebhooksSettings.FEATURE_NAME, scope);
boolean noHooks = StringUtils.isEmpty(stylePackage.getWebhooks());
String webhooksOptions = generateSelectOptions(webhooksNames, noHooks ? NamedSettings.DEFAULT_NAME : stylePackage.getWebhooks());
form = form.replace("{WEBHOOKS_DISPLAY}", PdfExporterExtensionConfiguration.getInstance().areWebhooksEnabled() ? "" : "hidden");
form = form.replace("{WEBHOOKS_DISPLAY}", PdfExporterExtensionConfiguration.getInstance().getWebhooksEnabled() ? "" : "hidden");
form = form.replace("{WEBHOOKS_OPTIONS}", webhooksOptions);
form = form.replace("{WEBHOOKS_SELECTOR_DISPLAY}", noHooks ? "none" : "inline-block");
return form.replace("{WEBHOOKS_SELECTED}", noHooks ? "" : "checked");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ch.sbb.polarion.extension.pdf.exporter.util.PdfExporterFileResourceProvider;
import ch.sbb.polarion.extension.pdf.exporter.util.PdfTemplateProcessor;
import ch.sbb.polarion.extension.pdf.exporter.util.html.HtmlLinksHelper;
import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher;
import ch.sbb.polarion.extension.generic.regex.RegexMatcher;
import ch.sbb.polarion.extension.pdf.exporter.weasyprint.WeasyPrintOptions;
import ch.sbb.polarion.extension.pdf.exporter.weasyprint.service.WeasyPrintServiceConnector;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public byte[] convertToPdf(@NotNull ExportParams exportParams, @Nullable ExportM

private @NotNull String applyWebhooks(@NotNull ExportParams exportParams, @NotNull String htmlContent) {
// Skip webhooks processing among other if this functionality is not enabled by system administrator
if (!PdfExporterExtensionConfiguration.getInstance().areWebhooksEnabled() || exportParams.getWebhooks() == null) {
if (!PdfExporterExtensionConfiguration.getInstance().getWebhooksEnabled() || exportParams.getWebhooks() == null) {
return htmlContent;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package ch.sbb.polarion.extension.pdf.exporter.properties;

import ch.sbb.polarion.extension.generic.properties.CurrentExtensionConfiguration;
import ch.sbb.polarion.extension.generic.properties.ExtensionConfiguration;
import ch.sbb.polarion.extension.generic.util.Discoverable;
import com.polarion.core.config.impl.SystemValueReader;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

@Discoverable
public class PdfExporterExtensionConfiguration extends ExtensionConfiguration {

public static final String WEASYPRINT_SERVICE = "weasyprint.service";
Expand All @@ -28,7 +31,7 @@ public Boolean getInternalizeExternalCss() {
}

@NotNull
public Boolean areWebhooksEnabled() {
public Boolean getWebhooksEnabled() {
return SystemValueReader.getInstance().readBoolean(getPropertyPrefix() + WEBHOOKS_ENABLED, false);
}

Expand All @@ -42,16 +45,7 @@ public Boolean areWebhooksEnabled() {
return supportedProperties;
}

public PdfExporterExtensionConfiguration() {
super();
}

public static PdfExporterExtensionConfiguration getInstance() {
return PdfExporterExtensionConfigurationHolder.INSTANCE;
return (PdfExporterExtensionConfiguration) CurrentExtensionConfiguration.getInstance().getExtensionConfiguration();
}

private static class PdfExporterExtensionConfigurationHolder {
private static final PdfExporterExtensionConfiguration INSTANCE = new PdfExporterExtensionConfiguration();
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ch.sbb.polarion.extension.pdf.exporter.rest.controller;

import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus;
import ch.sbb.polarion.extension.generic.rest.filter.Secured;
import ch.sbb.polarion.extension.generic.service.PolarionService;
import ch.sbb.polarion.extension.pdf.exporter.rest.model.configuration.ConfigurationStatus;
import org.jetbrains.annotations.NotNull;

import javax.ws.rs.Path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package ch.sbb.polarion.extension.pdf.exporter.rest.controller;

import ch.sbb.polarion.extension.pdf.exporter.rest.model.configuration.ConfigurationStatus;
import ch.sbb.polarion.extension.pdf.exporter.util.configuration.ConfigurationStatusUtils;
import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus;
import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatusProvider;
import ch.sbb.polarion.extension.pdf.exporter.util.configuration.CORSStatusProvider;
import ch.sbb.polarion.extension.pdf.exporter.util.configuration.DefaultSettingsStatusProvider;
import ch.sbb.polarion.extension.pdf.exporter.util.configuration.DleToolbarStatusProvider;
import ch.sbb.polarion.extension.pdf.exporter.util.configuration.DocumentPropertiesPaneStatusProvider;
import ch.sbb.polarion.extension.pdf.exporter.util.configuration.LiveReportMainHeadStatusProvider;
import ch.sbb.polarion.extension.pdf.exporter.util.configuration.WeasyPrintStatusProvider;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import org.jetbrains.annotations.NotNull;
Expand All @@ -23,46 +29,46 @@ public class ConfigurationInternalController {
@Path("/configuration/default-settings")
@Operation(summary = "Checks default settings configuration")
public @NotNull ConfigurationStatus checkDefaultSettings(@QueryParam("scope") @DefaultValue("") String scope) {
return ConfigurationStatusUtils.getSettingsStatus(scope);
return new DefaultSettingsStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().scope(scope).build());
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/configuration/document-properties-pane-config")
@Operation(summary = "Checks document properties pane configuration")
public @NotNull ConfigurationStatus checkDocumentPropertiesPaneConfig(@QueryParam("scope") @DefaultValue("") String scope) {
return ConfigurationStatusUtils.getDocumentPropertiesPaneStatus(scope);
return new DocumentPropertiesPaneStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().scope(scope).build());
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/configuration/dle-toolbar-config")
@Operation(summary = "Checks DLE Toolbar configuration")
public @NotNull ConfigurationStatus checkDleToolbarConfig() {
return ConfigurationStatusUtils.getDleToolbarStatus();
return new DleToolbarStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().build());
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/configuration/live-report-config")
@Operation(summary = "Checks Live Report configuration")
public @NotNull ConfigurationStatus checkLiveReportConfig() {
return ConfigurationStatusUtils.getLiveReportMainHeadStatus();
return new LiveReportMainHeadStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().build());
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/configuration/cors-config")
@Operation(summary = "Checks CORS configuration")
public @NotNull ConfigurationStatus checkCORSConfig() {
return ConfigurationStatusUtils.getCORSStatus();
return new CORSStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().build());
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/configuration/weasyprint")
@Operation(summary = "Checks WeasyPrint configuration")
public @NotNull List<ConfigurationStatus> checkWeasyPrint() {
return ConfigurationStatusUtils.getWeasyPrintStatus();
return new WeasyPrintStatusProvider().getStatuses(ConfigurationStatusProvider.Context.builder().build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ public String getFileName(@QueryParam("locationPath") String locationPath, @Quer
@Tag(name = "Utility resources")
@Operation(summary = "Gets webhooks status - if they are enabled or not")
public WebhooksStatus getWebhooksStatus() {
return WebhooksStatus.builder().enabled(PdfExporterExtensionConfiguration.getInstance().areWebhooksEnabled()).build();
return WebhooksStatus.builder().enabled(PdfExporterExtensionConfiguration.getInstance().getWebhooksEnabled()).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ch.sbb.polarion.extension.pdf.exporter.rest.model;

import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher;
import ch.sbb.polarion.extension.generic.regex.RegexMatcher;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ch.sbb.polarion.extension.pdf.exporter.rest.model.settings.coverpage.CoverPageModel;
import ch.sbb.polarion.extension.pdf.exporter.service.PdfExporterPolarionService;
import ch.sbb.polarion.extension.pdf.exporter.util.MediaUtils;
import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher;
import ch.sbb.polarion.extension.generic.regex.RegexMatcher;
import com.polarion.core.util.logging.Logger;
import com.polarion.platform.service.repository.IRepositoryReadOnlyConnection;
import com.polarion.subterra.base.location.ILocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import ch.sbb.polarion.extension.pdf.exporter.settings.LocalizationSettings;
import ch.sbb.polarion.extension.pdf.exporter.util.exporter.CustomPageBreakPart;
import ch.sbb.polarion.extension.pdf.exporter.util.html.HtmlLinksHelper;
import ch.sbb.polarion.extension.pdf.exporter.util.regex.IRegexEngine;
import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher;
import ch.sbb.polarion.extension.generic.regex.IRegexEngine;
import ch.sbb.polarion.extension.generic.regex.RegexMatcher;
import com.polarion.alm.shared.util.StringUtils;
import com.polarion.core.util.xml.CSSStyle;
import lombok.SneakyThrows;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.sbb.polarion.extension.pdf.exporter.util;

import ch.sbb.polarion.extension.pdf.exporter.model.LiveDocComment;
import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher;
import ch.sbb.polarion.extension.generic.regex.RegexMatcher;
import com.polarion.alm.server.api.model.document.ProxyDocument;
import com.polarion.alm.shared.api.model.comment.CommentBase;
import com.polarion.alm.shared.api.model.comment.CommentBaseFields;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ch.sbb.polarion.extension.pdf.exporter.util.configuration;

import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus;
import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatusProvider;
import ch.sbb.polarion.extension.generic.configuration.Status;
import ch.sbb.polarion.extension.generic.util.Discoverable;
import com.polarion.core.config.Configuration;
import org.jetbrains.annotations.NotNull;

import java.util.Set;

@Discoverable
public class CORSStatusProvider extends ConfigurationStatusProvider {

public static final String CORS = "CORS (Cross-Origin Resource Sharing)";

@Override
public @NotNull ConfigurationStatus getStatus(@NotNull Context context) {
boolean restEnabled = Configuration.getInstance().rest().enabled();
if (restEnabled) {
Set<String> corsAllowedOrigins = Configuration.getInstance().rest().corsAllowedOrigins();
if (corsAllowedOrigins.isEmpty()) {
return new ConfigurationStatus(CORS, Status.WARNING, "CORS allowed origins are not configured");
} else {
return new ConfigurationStatus(CORS, Status.OK, "CORS allowed origins: %s".formatted(corsAllowedOrigins.stream().toList()));
}
} else {
return new ConfigurationStatus(CORS, Status.WARNING, "Polarion REST API is not enabled, so CORS is not enabled");
}
}
}
Loading

0 comments on commit 792c662

Please sign in to comment.