Skip to content

Commit

Permalink
#22385 include in 23.10.24
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Mar 5, 2024
1 parent 8f166f0 commit e5d8821
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dotCMS/hotfix_tracking.md
Expand Up @@ -67,4 +67,5 @@ This maintenance release includes the following code fixes:
60. https://github.com/dotCMS/core/issues/26853 : [UI] Implement Handle Errors from endpoint #26853
61. https://github.com/dotCMS/core/issues/25296 : Limited users cannot create content types on System Host #25296
62. https://github.com/dotCMS/core/issues/26542 : Hide the download button for bundles pushed to static environments #26542
63. https://github.com/dotCMS/core/issues/26415 : Template Builder: System Template should create layout always #26415
63. https://github.com/dotCMS/core/issues/26415 : Template Builder: System Template should create layout always #26415
64. https://github.com/dotCMS/core/issues/22385 : Custom templates should push with their page no matter the filter that is selected #22385
Expand Up @@ -461,13 +461,18 @@ public void test_Page_with_FileTemplateAdvanced_as_Dependencies()

}

private void createBundle(final PushPublisherConfig config, final Contentlet contentlet)
throws DotDataException {
createBundle(config,contentlet,"");
}

/**
* Creates a bundle with one contentlet
*/
private void createBundle(final PushPublisherConfig config, final Contentlet contentlet)
private void createBundle(final PushPublisherConfig config, final Contentlet contentlet, final String filterKey)
throws DotDataException {
final String bundleName = "testDependencyManagerBundle" + System.currentTimeMillis();
Bundle bundle = new Bundle(bundleName, new Date(), null, user.getUserId());
Bundle bundle = new Bundle(bundleName, new Date(), null, user.getUserId(),false,filterKey);
bundleAPI.saveBundle(bundle);
bundle = bundleAPI.getBundleByName(bundleName);

Expand Down Expand Up @@ -536,4 +541,67 @@ private static void createFilter(){
APILocator.getPublisherAPI().addFilterDescriptor(filterDescriptor);
}

private static void createShallowPushFilter(){
final Map<String,Object> filtersMap =
ImmutableMap.of("dependencies",false,"relationships",false,"forcePush",false);
final FilterDescriptor filterDescriptor =
new FilterDescriptor("ShallowPush.yml","Only Selected Items",filtersMap,false,"DOTCMS_BACK_END_USER");
APILocator.getPublisherAPI().addFilterDescriptor(filterDescriptor);
}

/**
* <b>Method to test:</b> PushPublishigDependencyProcesor.tryToAdd(PusheableAsset, Object, String) <p>
* <b>Given Scenario:</b> Push publish a page with the filter 'Only Selected Items' selected.<p>
* <b>ExpectedResult:</b> The template should not be included in the dependencies.
* @throws DotSecurityException
* @throws DotBundleException
* @throws DotDataException
*/
@Test
public void test_PP_page_should_not_contain_template_in_dependencies_when_filter_set() throws DotDataException, DotBundleException, DotSecurityException {
final PushPublisherConfig config = new PushPublisherConfig();
final Template template = new TemplateDataGen().nextPersisted();
final Host host = new SiteDataGen().nextPersisted();
final HTMLPageAsset htmlPageAsset = new HTMLPageDataGen(host, template).nextPersisted();
//Create a bundle with filter 'Only Selected Items'
final String filterKey = "ShallowPush.yml";
if(!APILocator.getPublisherAPI().existsFilterDescriptor(filterKey)){
createShallowPushFilter();
}
createBundle(config, htmlPageAsset, filterKey);
DependencyManager dependencyManager = new DependencyManager(DependencyManagerTest.user, config);
dependencyManager.setDependencies();

assertFalse(APILocator.getPublisherAPI().getFilterDescriptorByKey("ShallowPush.yml").toString(),
dependencyManager.getTemplates().contains(template.getIdentifier()));
}

/**
* <b>Method to test:</b> PushPublishigDependencyProcesor.tryToAdd(PusheableAsset, Object, String) <p>
* <b>Given Scenario:</b> Custom templates be should considered part of the page. <p>
* <b>ExpectedResult:</b> The layout should be included in the dependencies regardless of the selected filter.
* @throws DotSecurityException
* @throws DotBundleException
* @throws DotDataException
*/
@Test
public void test_PP_page_should_contains_layout_in_dependencies() throws DotDataException, DotBundleException, DotSecurityException {
final PushPublisherConfig config = new PushPublisherConfig();
//Layout templates are identified by the prefix 'anonymous_layout_'
final Template template = new TemplateDataGen().title(Template.ANONYMOUS_PREFIX+"shouldBeIncluded").nextPersisted();
final Host host = new SiteDataGen().nextPersisted();
final HTMLPageAsset htmlPageAsset = new HTMLPageDataGen(host, template).nextPersisted();
//Create a bundle with filter 'Only Selected Items'
final String filterKey = "ShallowPush.yml";
if(!APILocator.getPublisherAPI().existsFilterDescriptor(filterKey)){
createShallowPushFilter();
}
createBundle(config, htmlPageAsset, filterKey);
createBundle(config, htmlPageAsset, "ShallowPush.yml");
DependencyManager dependencyManager = new DependencyManager(DependencyManagerTest.user, config);
dependencyManager.setDependencies();

assertTrue(dependencyManager.getTemplates().contains(template.getIdentifier()));
}

}
Expand Up @@ -1045,7 +1045,7 @@ private synchronized <T> TryToAddResult tryToAdd(final PusheableAsset pusheableA
return new TryToAddResult(TryToAddResult.Result.EXCLUDE, ManifestReason.EXCLUDE_SYSTEM_OBJECT);
}

if (isExcludeByFilter(pusheableAsset)) {
if (!isTemplateLayout(asset) && isExcludeByFilter(pusheableAsset)) {
config.exclude(asset, pusheableAsset, ManifestReason.EXCLUDE_BY_FILTER.getMessage());
return new TryToAddResult(TryToAddResult.Result.EXCLUDE, ManifestReason.EXCLUDE_BY_FILTER);
}
Expand Down Expand Up @@ -1073,6 +1073,17 @@ private synchronized <T> TryToAddResult tryToAdd(final PusheableAsset pusheableA
}
}

/**
* Determines if the provided asset is a template layout.
* We can identify it by the title, it always contains the acronym Template.ANONYMOUS_PREFIX
* @param asset The asset to check
* @return If the Asset is a {@link Template} object and the title
* contains {@code Template.ANONYMOUS_PREFIX}, return {@code true}.
*/
private boolean isTemplateLayout(final Object asset){
return asset instanceof Template && Template.class.cast(asset).getTitle().contains(Template.ANONYMOUS_PREFIX);
}

private <T> boolean isExcludeByFilter(final PusheableAsset pusheableAsset) {
return !isRelationshipObject(pusheableAsset) && (!publisherFilter.isDependencies() ||
publisherFilter.doesExcludeDependencyClassesContainsType(pusheableAsset.getType()));
Expand Down

0 comments on commit e5d8821

Please sign in to comment.