Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cms-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.condation.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>7.4.2</version>
<version>7.5.0</version>
</parent>
<artifactId>cms-api</artifactId>
<packaging>jar</packaging>
Expand All @@ -16,7 +16,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.condation.cms.module.framework</groupId>
<groupId>com.condation.modules.framework</groupId>
<artifactId>modules-api</artifactId>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class TemplateModelExtendingExtensionPoint extends AbstractExten
public abstract void extendModel (TemplateEngine.Model model);

public Map<String, Object> getModel () {
TemplateEngine.Model model = new TemplateEngine.Model(null, null);
TemplateEngine.Model model = new TemplateEngine.Model(null, null, null);
extendModel(model);
return model.values;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*
* @author t.marx
*/
@Deprecated(since = "6.5.0")
@FeatureScope({FeatureScope.Scope.GLOBAL, FeatureScope.Scope.MODULE, FeatureScope.Scope.REQUEST})
public record ServerPropertiesFeature(ServerProperties serverProperties) implements Feature {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*
* @author t.marx
*/
@Deprecated(since = "6.5.0")
@FeatureScope({FeatureScope.Scope.GLOBAL, FeatureScope.Scope.MODULE, FeatureScope.Scope.REQUEST})
public record SitePropertiesFeature(SiteProperties siteProperties) implements Feature {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.condation.cms.api.featureflags;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 - 2024 CondationCMS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/


import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class FeatureFlags {
private static final Map<String, Boolean> flags = new ConcurrentHashMap<>();

private FeatureFlags() {}

/**
* Initialize Feature-Flags.
* @param initialFlags Map of features
*/
public static void initialize(Map<String, Boolean> initialFlags) {
flags.clear();
flags.putAll(initialFlags);
}

/**
* Checks if a feature is activated
* @param featureName Name of the feature.
* @return true, if the feature is activated; otherwise false.
*/
public static boolean isEnabled(String featureName) {
return flags.getOrDefault(featureName, false);
}

/**
* sets or updates a feature
* @param featureName Name of the feature.
* @param enabled true if activated, false if deactivated.
*/
public static void setFlag(String featureName, boolean enabled) {
flags.put(featureName, enabled);
}

/**
* returns an unmodifiable view of the feature flags
* @return Map of the current feature flags.
*/
public static Map<String, Boolean> getFlags() {
return Collections.unmodifiableMap(flags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.condation.cms.api.db.ContentNode;
import com.condation.cms.api.db.cms.ReadOnlyFile;
import com.condation.cms.api.request.RequestContext;
import com.condation.cms.api.theme.Theme;
import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -51,5 +52,6 @@ public static class Model {
public final Map<String, Object> values = new HashMap<>();
public final ReadOnlyFile contentFile;
public final ContentNode contentNode;
public final RequestContext requestContext;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit5TestClass.java to edit this template
*/
package com.condation.cms.api.featureflags;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 - 2024 CondationCMS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class FeatureFlagsTest {

@BeforeEach
void setup() {
// Initialisiere die FeatureFlags vor jedem Test
FeatureFlags.initialize(Map.of(
"featureX", true,
"newDashboard", false
));
}

@Test
void testFeatureIsEnabled() {
// Prüfe, dass ein aktives Feature korrekt erkannt wird
assertThat(FeatureFlags.isEnabled("featureX")).isTrue();
}

@Test
void testFeatureIsDisabled() {
// Prüfe, dass ein inaktives Feature korrekt erkannt wird
assertThat(FeatureFlags.isEnabled("newDashboard")).isFalse();
}

@Test
void testDefaultFlagIsDisabled() {
// Prüfe, dass ein nicht initialisiertes Feature false zurückgibt
assertThat(FeatureFlags.isEnabled("nonExistentFeature")).isFalse();
}

@Test
void testSetFlag() {
// Aktiviere ein neues Feature und prüfe den Status
FeatureFlags.setFlag("betaFeature", true);
assertThat(FeatureFlags.isEnabled("betaFeature")).isTrue();

// Deaktiviere es wieder und prüfe den Status
FeatureFlags.setFlag("betaFeature", false);
assertThat(FeatureFlags.isEnabled("betaFeature")).isFalse();
}

@Test
void testGetFlags() {
// Prüfe, dass die initialisierten Flags korrekt zurückgegeben werden
Map<String, Boolean> flags = FeatureFlags.getFlags();

assertThat(flags).containsEntry("featureX", true)
.containsEntry("newDashboard", false)
.doesNotContainKey("nonExistentFeature");

// Prüfe, dass die Map unveränderlich ist
assertThatThrownBy(() -> flags.put("shouldFail", true))
.isInstanceOf(UnsupportedOperationException.class);
}
}

4 changes: 2 additions & 2 deletions cms-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.condation.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>7.4.2</version>
<version>7.5.0</version>
</parent>
<artifactId>cms-auth</artifactId>
<packaging>jar</packaging>
Expand All @@ -19,7 +19,7 @@
<artifactId>cms-filesystem</artifactId>
</dependency>
<dependency>
<groupId>com.condation.cms.module.framework</groupId>
<groupId>com.condation.modules.framework</groupId>
<artifactId>modules-api</artifactId>
<scope>provided</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion cms-content/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.condation.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>7.4.2</version>
<version>7.5.0</version>
</parent>
<artifactId>cms-content</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.condation.cms.api.db.taxonomy.Taxonomy;
import com.condation.cms.api.extensions.ContentQueryOperatorExtensionPoint;
import com.condation.cms.api.extensions.TemplateModelExtendingExtensionPoint;
import com.condation.cms.api.extensions.TemplateModelExtendingExtentionPoint;
import com.condation.cms.api.feature.features.AuthFeature;
import com.condation.cms.api.feature.features.HookSystemFeature;
import com.condation.cms.api.feature.features.InjectorFeature;
Expand Down Expand Up @@ -136,12 +135,13 @@ public String render(final ReadOnlyFile contentFile, final RequestContext contex

Optional<ContentNode> contentNode = db.getContent().byUri(uri);

TemplateEngine.Model model = new TemplateEngine.Model(contentFile, contentNode.isPresent() ? contentNode.get() : null);
TemplateEngine.Model model = new TemplateEngine.Model(
contentFile,
contentNode.isPresent() ? contentNode.get() : null,
context);

modelExtending.accept(model);

//model.values.put("cms", Namespace.create("cms", meta));

Namespace namespace = new Namespace();

model.values.put("meta", new MapAccess(meta));
Expand All @@ -151,8 +151,8 @@ public String render(final ReadOnlyFile contentFile, final RequestContext contex
namespace.add("node", "sections", sections);

ShortCodeTemplateFunction shortCodeFunction = createShortCodeFunction(context);
model.values.put("shortCodes", shortCodeFunction);
namespace.add("cms", "shortCodes", shortCodeFunction);
model.values.put(ShortCodeTemplateFunction.KEY, shortCodeFunction);
namespace.add("cms", ShortCodeTemplateFunction.KEY, shortCodeFunction);

NavigationFunction navigationFunction = createNavigationFunction(contentFile, context);
model.values.put("navigation", navigationFunction);
Expand Down Expand Up @@ -252,16 +252,6 @@ private boolean isDevMode(final RequestContext context) {
}

private void extendModel(final TemplateEngine.Model model, Namespace namespace) {
moduleManager.extensions(TemplateModelExtendingExtentionPoint.class).forEach(extensionPoint -> {
var modModel = extensionPoint.getModel();
// deprecated: module extensions on root will be remove in 8.0.0
model.values.putAll(modModel);
modModel.entrySet().forEach(entry -> namespace.add(
extensionPoint.getNamespace(),
entry.getKey(),
entry.getValue()
));
});
moduleManager.extensions(TemplateModelExtendingExtensionPoint.class).forEach(extensionPoint -> {
var modModel = extensionPoint.getModel();
// deprecated: module extensions on root will be remove in 8.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.condation.cms.api.model.Parameter;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -47,6 +48,10 @@ public ShortCodes (Map<String, Function<Parameter, String>> codes, TagParser tag
this.tagMap.putAll(codes);
}

public Set<String> getShortCodeNames () {
return tagMap.names();
}

public String replace (final String content) {
return replace(content, Collections.emptyMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
*/

import com.condation.cms.api.model.Parameter;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

/**
Expand All @@ -35,6 +37,10 @@ public class TagMap {

private final Map<String, Function<Parameter, String>> tags = new HashMap<>();

public Set<String> names () {
return Collections.unmodifiableSet(tags.keySet());
}

public void put(String codeName, Function<Parameter, String> function) {
tags.put(codeName, function);
}
Expand Down
Loading