Skip to content

Commit

Permalink
Merge branch 'main' into issue-31442-ftm-avoid-executing-ftm-logic-fo…
Browse files Browse the repository at this point in the history
…r-immediate-publish-date-in-live-mode
  • Loading branch information
valentinogiardino authored Feb 24, 2025
2 parents d7080ce + c06a29b commit 52a53a8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
DotContentletService,
DotHttpErrorManagerService,
DotLanguagesService,
DotMessageService
DotMessageService,
DotWorkflowsActionsService
} from '@dotcms/data-access';
import { ComponentStatus, DotLanguage } from '@dotcms/dotcms-models';
import { MOCK_SINGLE_WORKFLOW_ACTIONS } from '@dotcms/utils-testing';

import { contentInitialState } from './content.feature';
import { withLocales } from './locales.feature';
Expand Down Expand Up @@ -44,6 +46,7 @@ describe('LocalesFeature', () => {
let dotEditContentService: SpyObject<DotEditContentService>;
let dialogService: SpyObject<DialogService>;
let router: SpyObject<Router>;
let workflowActionService: SpyObject<DotWorkflowsActionsService>;

const withTest = () =>
signalStoreFeature(
Expand Down Expand Up @@ -71,7 +74,8 @@ describe('LocalesFeature', () => {
DialogService,
DynamicDialogConfig,
DynamicDialogRef,
Router
Router,
DotWorkflowsActionsService
]
});

Expand All @@ -83,6 +87,9 @@ describe('LocalesFeature', () => {
dotEditContentService = spectator.inject(DotEditContentService);
dialogService = spectator.inject(DialogService);
router = spectator.inject(Router);
workflowActionService = spectator.inject(DotWorkflowsActionsService);

workflowActionService.getDefaultActions.mockReturnValue(of(MOCK_SINGLE_WORKFLOW_ACTIONS));
});

it('should load locales when a new contentlet is loaded', fakeAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import { Router } from '@angular/router';

import { DialogService } from 'primeng/dynamicdialog';

import { filter, switchMap, take } from 'rxjs/operators';
import { filter, switchMap, take, map } from 'rxjs/operators';

import {
DotContentletService,
DotHttpErrorManagerService,
DotLanguagesService,
DotMessageService
DotMessageService,
DotWorkflowsActionsService
} from '@dotcms/data-access';
import { ComponentStatus, DotCMSContentlet, DotLanguage } from '@dotcms/dotcms-models';
import { DotEditContentSidebarUntranslatedLocaleComponent } from '@dotcms/edit-content/components/dot-edit-content-sidebar/components/dot-edit-content-sidebar-untranslated-locale/dot-edit-content-sidebar-untranslated-locale.component';
Expand All @@ -35,7 +36,7 @@ import { WorkflowState } from './workflow.feature';

import { DotEditContentService } from '../../services/dot-edit-content.service';
import { EditContentRootState } from '../../store/edit-content.store';
import { parseCurrentActions } from '../../utils/workflows.utils';
import { parseCurrentActions, parseWorkflows } from '../../utils/workflows.utils';

export interface LocalesState {
locales: DotLanguage[] | null;
Expand Down Expand Up @@ -85,7 +86,8 @@ export function withLocales() {
dotHttpErrorManagerService = inject(DotHttpErrorManagerService),
dotMessageService = inject(DotMessageService),
dialogService = inject(DialogService),
router = inject(Router)
router = inject(Router),
workflowActionService = inject(DotWorkflowsActionsService)
) => ({
/**
* Loads the locales based on a content identifier and updates the state accordingly.
Expand Down Expand Up @@ -234,21 +236,28 @@ export function withLocales() {
ref.onClose
.pipe(
take(1),
filter((value) => value)
filter((value) => value),
switchMap((copyType) => {
return workflowActionService
.getDefaultActions(store.contentType()?.variable)
.pipe(map((schemes) => ({ copyType, schemes })));
})
)
.subscribe((copyType) => {
const schemes = store.schemes();
const schemeIds = Object.keys(schemes);
.subscribe(({ copyType, schemes }) => {
// Convert the schemes to an object with the schemeId as the key
const parsedSchemes = parseWorkflows(schemes);
const schemeIds = Object.keys(parsedSchemes);
// If we have only one scheme, we set it as the default one
const defaultSchemeId =
schemeIds.length === 1 ? schemeIds[0] : null;
// Parse the actions as an object with the schemeId as the key
const parsedCurrentActions = parseCurrentActions(
schemes[defaultSchemeId]?.actions || []
parsedSchemes[defaultSchemeId]?.actions || []
);

patchState(store, {
currentLocale: locale,
schemes: parsedSchemes,
currentSchemeId: defaultSchemeId,
currentContentActions: parsedCurrentActions,
state: ComponentStatus.LOADED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.dotmarketing.cms.urlmap.UrlMapContext;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.htmlpageasset.business.HTMLPageAssetAPI;
import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset;
import com.dotmarketing.portlets.htmlpageasset.model.IHTMLPage;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;
Expand Down Expand Up @@ -73,17 +74,17 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa
.onFailure(e -> Logger.error(this, String.format("Error finding detail page " +
"'%s': %s", urlMapContentType.detailPage(), getErrorMessage(e)), e))
.getOrNull();

final HTMLPageAsset detailPageAsset = (HTMLPageAsset) detailPageContent;
final HashMap<String, String> pageObject = new HashMap<>();
pageObject.put(ID, detailPageContent.getIdentifier());
pageObject.put(TITLE, detailPageContent.getTitle());
pageObject.put(URL, uri);
pageObject.put(CONTENT_TYPE_ID, urlMapContentlet.getContentType().id());
pageObject.put(CONTENT_TYPE_NAME, urlMapContentlet.getContentType().name());
pageObject.put(CONTENT_TYPE_VAR_NAME, urlMapContentlet.getContentType().variable());
pageObject.put(CONTENT_TYPE_ID, detailPageAsset.getContentTypeId());
pageObject.put(CONTENT_TYPE_NAME, detailPageAsset.getContentType().name());
pageObject.put(CONTENT_TYPE_VAR_NAME, detailPageAsset.getContentType().variable());
pageObject.put(BASE_TYPE, urlMapContentlet.getContentType().baseType().name());
pageObject.put(LIVE, String.valueOf(Try.of(()->urlMapContentlet.isLive()).getOrElse(false)));
pageObject.put(WORKING, String.valueOf(Try.of(()->urlMapContentlet.isWorking()).getOrElse(false)));
pageObject.put(LIVE, String.valueOf(Try.of(urlMapContentlet::isLive).getOrElse(false)));
pageObject.put(WORKING, String.valueOf(Try.of(urlMapContentlet::isWorking).getOrElse(false)));
pageObject.put(DETAIL_PAGE_URL, Try.of(detailPageContent::getURI).getOrElse(StringPool.BLANK));
collectorPayloadBean.put(OBJECT, pageObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public void testPageDetailCollector() throws DotDataException, UnknownHostExcept
Collector.ID, testDetailPage.getIdentifier(),
Collector.TITLE, testDetailPage.getTitle(),
Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL,
Collector.CONTENT_TYPE_ID, newsTestContent.getContentType().id(),
Collector.CONTENT_TYPE_NAME, newsTestContent.getContentType().name(),
Collector.CONTENT_TYPE_VAR_NAME, newsTestContent.getContentType().variable(),
Collector.CONTENT_TYPE_ID, testDetailPage.getContentTypeId(),
Collector.CONTENT_TYPE_NAME, testDetailPage.getContentType().name(),
Collector.CONTENT_TYPE_VAR_NAME, testDetailPage.getContentType().variable(),
Collector.BASE_TYPE, newsTestContent.getContentType().baseType().name(),
Collector.LIVE, newsTestContent.isLive(),
Collector.WORKING, newsTestContent.isWorking(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ public void testPageDetailCollector() throws Exception {
Collector.ID, testDetailPage.getIdentifier(),
Collector.TITLE, testDetailPage.getTitle(),
Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL,
Collector.CONTENT_TYPE_ID, urlMappedContentType.id(),
Collector.CONTENT_TYPE_NAME, urlMappedContentType.name(),
Collector.CONTENT_TYPE_VAR_NAME, urlMappedContentType.variable(),
Collector.CONTENT_TYPE_ID, testDetailPage.getContentTypeId(),
Collector.CONTENT_TYPE_NAME, testDetailPage.getContentType().name(),
Collector.CONTENT_TYPE_VAR_NAME, testDetailPage.getContentType().variable(),
Collector.BASE_TYPE, urlMappedContentType.baseType().name(),
Collector.LIVE, testDetailPage.isLive(),
Collector.WORKING, testDetailPage.isWorking(),
Expand Down

0 comments on commit 52a53a8

Please sign in to comment.