Skip to content

Commit

Permalink
Merge branch 'issue-28325-fix-SnakeYAML-vuln' of https://github.com/d…
Browse files Browse the repository at this point in the history
…otCMS/core into issue-28325-fix-SnakeYAML-vuln
  • Loading branch information
fabrizzio-dotCMS committed Apr 30, 2024
2 parents 5361abf + df5adea commit 34a7450
Show file tree
Hide file tree
Showing 48 changed files with 368 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Router } from '@angular/router';

import { take } from 'rxjs/operators';

import { DotContentCompareEvent } from '@components/dot-content-compare/dot-content-compare.component';
import { DotCMSEditPageEvent } from '@components/dot-contentlet-editor/components/dot-contentlet-wrapper/dot-contentlet-wrapper.component';
import { DotContentletEditorService } from '@components/dot-contentlet-editor/services/dot-contentlet-editor.service';
import {
Expand All @@ -17,7 +16,7 @@ import {
DotWorkflowEventHandlerService
} from '@dotcms/data-access';
import { DotPushPublishDialogService, DotUiColors } from '@dotcms/dotcms-js';
import { DotCMSContentType, FeaturedFlags } from '@dotcms/dotcms-models';
import { DotCMSContentType, DotContentCompareEvent, FeaturedFlags } from '@dotcms/dotcms-models';
import { DotLoadingIndicatorService } from '@dotcms/utils';
import { DotDownloadBundleDialogService } from '@services/dot-download-bundle-dialog/dot-download-bundle-dialog.service';
import { DotNavLogoService } from '@services/dot-nav-logo/dot-nav-logo.service';
Expand Down
2 changes: 1 addition & 1 deletion core-web/apps/dotcms-ui/src/app/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { TreeTableModule } from 'primeng/treetable';
import { DotDownloadBundleDialogModule } from '@components/_common/dot-download-bundle-dialog/dot-download-bundle-dialog.module';
import { DotPushPublishDialogModule } from '@components/_common/dot-push-publish-dialog';
import { DotWizardModule } from '@components/_common/dot-wizard/dot-wizard.module';
import { DotContentCompareModule } from '@components/dot-content-compare/dot-content-compare.module';
import { DotMessageDisplayModule } from '@components/dot-message-display/dot-message-display.module';
import { DotToolbarModule } from '@components/dot-toolbar/dot-toolbar.module';
import { DotContentCompareModule } from '@dotcms/portlets/dot-ema/ui';
import { DotDialogModule, DotFieldValidationMessageComponent, DotIconModule } from '@dotcms/ui';

import { DotActionButtonModule } from './view/components/_common/dot-action-button/dot-action-button.module';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
import { catchError, take } from 'rxjs/operators';

import { IframeComponent } from '@components/_common/iframe/iframe-component';
import { DotDiffPipe } from '@dotcms/app/view/pipes';
import { DotEditPageService, DotHttpErrorManagerService } from '@dotcms/data-access';
import { DotWhatChanged } from '@dotcms/dotcms-models';
import { DotDiffPipe } from '@dotcms/ui';
import { DotDOMHtmlUtilService } from '@portlets/dot-edit-page/content/services/html/dot-dom-html-util.service';

export const SHOW_DIFF_STYLES =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import { IFrameModule } from '@components/_common/iframe';
import { DotMessagePipe } from '@dotcms/ui';
import { DotDiffPipeModule } from '@pipes/dot-diff/dot-diff.pipe.module';
import { DotDiffPipe, DotMessagePipe } from '@dotcms/ui';

import { DotWhatsChangedComponent } from './dot-whats-changed.component';

@NgModule({
imports: [CommonModule, IFrameModule, DotDiffPipeModule, DotMessagePipe],
imports: [CommonModule, IFrameModule, DotDiffPipe, DotMessagePipe],
declarations: [DotWhatsChangedComponent],
exports: [DotWhatsChangedComponent]
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import { DotContentCompareModule } from '@components/dot-content-compare/dot-content-compare.module';
import { DotContentCompareModule } from '@dotcms/portlets/dot-ema/ui';
import { DotMessagePipe, DotSafeHtmlPipe } from '@dotcms/ui';

import { DotAddContentletComponent } from './components/dot-add-contentlet/dot-add-contentlet.component';
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion core-web/apps/dotcms-ui/src/app/view/pipes/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './dot-diff/dot-diff.pipe';
export * from './dot-filter/dot-filter.pipe';
1 change: 1 addition & 0 deletions core-web/libs/dotcms-models/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ export * from './lib/dot-message.model';
export * from './lib/dot-message-severity.model';
export * from './lib/dot-message-type.model';
export * from './lib/dot-dialog.model';
export * from './lib/dot-content-compare.model';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface DotContentCompareEvent {
inode: string;
identifier: string;
language: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@
-webkit-backdrop-filter: blur($blur-md);
backdrop-filter: blur($blur-md);
}

.p-dialog-mask.p-dialog-mask-transparent-nested.p-component-overlay {
background-color: transparent;
-webkit-backdrop-filter: none;
backdrop-filter: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,21 @@
data-testId="spinner"></dot-spinner>
</ng-container>
</ng-container>

<p-dialog
[visible]="this.$compareData()"
[style]="{ height: '90vh', width: '90vw' }"
[header]="'Compare'"
[draggable]="false"
[resizable]="false"
[maximizable]="true"
[modal]="true"
[maskStyleClass]="'p-dialog-mask-transparent-nested'"
(visibleChange)="closeCompareDialog()"
appendTo="body"
data-testId="dialog-compare">
<dot-content-compare
[data]="$compareData()"
(letMeBringBack)="bringBack($event)"></dot-content-compare>
</p-dialog>
</p-dialog>
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { describe, it, expect } from '@jest/globals';
import { Spectator, createComponentFactory, SpyObject, byTestId } from '@ngneat/spectator/jest';
import {
Spectator,
createComponentFactory,
SpyObject,
byTestId,
mockProvider
} from '@ngneat/spectator/jest';
import { of } from 'rxjs';

import { HttpClient } from '@angular/common/http';
Expand All @@ -9,12 +15,17 @@ import { By } from '@angular/platform-browser';
import { MessageService } from 'primeng/api';

import {
DotAlertConfirmService,
DotContentTypeService,
DotHttpErrorManagerService,
DotIframeService,
DotMessageService,
DotWorkflowActionsFireService,
PushPublishService
} from '@dotcms/data-access';
import { CoreWebService, DotcmsConfigService, DotcmsEventsService } from '@dotcms/dotcms-js';
import { DotCMSBaseTypesContentTypes, DotCMSContentlet } from '@dotcms/dotcms-models';
import { DotContentCompareComponent } from '@dotcms/portlets/dot-ema/ui';
import {
DotcmsConfigServiceMock,
DotcmsEventsServiceMock,
Expand Down Expand Up @@ -71,7 +82,6 @@ describe('DotEmaDialogComponent', () => {
HttpClient,
DotWorkflowActionsFireService,
MessageService,

{
provide: DotcmsConfigService,
useValue: new DotcmsConfigServiceMock()
Expand Down Expand Up @@ -114,7 +124,11 @@ describe('DotEmaDialogComponent', () => {
{
provide: DotMessageService,
useValue: new MockDotMessageService({})
}
},
mockProvider(DotContentTypeService),
mockProvider(DotHttpErrorManagerService),
mockProvider(DotAlertConfirmService),
mockProvider(DotIframeService)
]
});

Expand Down Expand Up @@ -337,4 +351,61 @@ describe('DotEmaDialogComponent', () => {
});
});
});

describe('Compare dialog', () => {
const renderCompareDialog = () => {
component.addContentlet(PAYLOAD_MOCK); // This is to make the dialog open
spectator.detectChanges();

triggerIframeCustomEvent();

const dialogIframe = spectator.debugElement.query(
By.css('[data-testId="dialog-iframe"]')
);

spectator.triggerEventHandler(dialogIframe, 'load', {}); // There's no way we can load the iframe, because we are setting a real src and will not load

dialogIframe.nativeElement.contentWindow.document.dispatchEvent(
new CustomEvent('ng-event', {
detail: {
name: NG_CUSTOM_EVENTS.COMPARE_CONTENTLET,
data: {
inode: '123',
identifier: 'identifier',
language: '1'
}
}
})
);
spectator.detectChanges();
};

it('should render a compare dialog', () => {
renderCompareDialog();
expect(spectator.query(byTestId('dialog-compare'))).toBeDefined();
expect(spectator.query(DotContentCompareComponent)).toBeDefined();

expect(spectator.component.$compareData()).toEqual({
inode: '123',
identifier: 'identifier',
language: '1'
});
});

it('should trigger a bring back action', () => {
const bringBackSpy = jest.spyOn(component, 'bringBack');

renderCompareDialog();

spectator.triggerEventHandler(DotContentCompareComponent, 'letMeBringBack', {
name: 'getVersionBack',
args: ['123']
});

expect(bringBackSpy).toHaveBeenCalledWith({
name: 'getVersionBack',
args: ['123']
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
NgZone,
Output,
ViewChild,
inject
inject,
signal
} from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';

Expand All @@ -23,8 +24,10 @@ import { DotMessageService } from '@dotcms/data-access';
import {
DotCMSBaseTypesContentTypes,
DotCMSContentlet,
DotCMSWorkflowActionEvent
DotCMSWorkflowActionEvent,
DotContentCompareEvent
} from '@dotcms/dotcms-models';
import { DotContentCompareModule } from '@dotcms/portlets/dot-ema/ui';
import { DotSpinnerModule, SafeUrlPipe } from '@dotcms/ui';

import {
Expand Down Expand Up @@ -52,14 +55,18 @@ import { EmaFormSelectorComponent } from '../ema-form-selector/ema-form-selector
SafeUrlPipe,
EmaFormSelectorComponent,
DialogModule,
DotSpinnerModule
DotSpinnerModule,
DotContentCompareModule
],
providers: [DotEmaDialogStore, DotEmaWorkflowActionsService]
})
export class DotEmaDialogComponent {
@ViewChild('iframe') iframe: ElementRef<HTMLIFrameElement>;

@Output() action = new EventEmitter<{ event: CustomEvent; payload: ActionPayload }>();
@Output() reloadFromDialog = new EventEmitter<void>();

$compareData = signal<DotContentCompareEvent | null>(null);

private readonly destroyRef$ = inject(DestroyRef);
private readonly store = inject(DotEmaDialogStore);
Expand Down Expand Up @@ -248,9 +255,14 @@ export class DotEmaDialogComponent {
* @param {unknown[]} args
* @memberof DotEmaDialogComponent
*/
private callEmbeddedFunction(callback: string, args: unknown[] = []) {
private callEmbeddedFunction(
callback: string,
args: unknown[] = [],
whenFinished?: () => void
) {
this.ngZone.run(() => {
this.iframe.nativeElement.contentWindow?.[callback]?.(...args);
whenFinished?.();
});
}

Expand Down Expand Up @@ -284,6 +296,12 @@ export class DotEmaDialogComponent {
.subscribe((event: CustomEvent) => {
this.action.emit({ event, payload: this.dialogState().payload });

if (event.detail.name === NG_CUSTOM_EVENTS.COMPARE_CONTENTLET) {
this.ngZone.run(() => {
this.$compareData.set(<DotContentCompareEvent>event.detail.data);
});
}

if (event.detail.name === NG_CUSTOM_EVENTS.OPEN_WIZARD) {
this.handleWorkflowEvent(event.detail.data);
} else if (
Expand Down Expand Up @@ -314,4 +332,24 @@ export class DotEmaDialogComponent {

this.action.emit({ event: customEvent, payload: this.dialogState().payload });
}

/**
* Brings back the dialog to the previous state and triggers a reload event.
* @param options - The options for bringing back the dialog.
* @param options.name - The name of the dialog.
* @param options.args - The arguments for the dialog.
*/
bringBack({ name, args }: { name: string; args: string[] } = { name: '', args: [] }) {
this.$compareData.set(null);
this.callEmbeddedFunction(name, args, () => this.reloadFromDialog.emit());
}

/**
* Close compare dialog
*
* @memberof DotEmaDialogComponent
*/
closeCompareDialog() {
this.$compareData.set(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
<dot-edit-ema-dialog
#dialog
(action)="handleNgEvent($event)"
(reloadFromDialog)="reloadFromDialog()"
data-testId="ema-dialog"></dot-edit-ema-dialog>
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,22 @@ describe('DotEmaShellComponent', () => {
'com.dotmarketing.persona.id': DEFAULT_PERSONA.identifier
});
});

it('should reload content from dialog', () => {
const reloadSpy = jest.spyOn(store, 'reload');
const queryParams = {
'com.dotmarketing.persona.id': 'modes.persona.no.persona',
language_id: 1,
url: 'index',
variantName: undefined
};

spectator.triggerEventHandler(DotEmaDialogComponent, 'reloadFromDialog', null);

expect(reloadSpy).toHaveBeenCalledWith({
params: queryParams
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export class DotEmaShellComponent implements OnInit, OnDestroy {
}
}

/**
* Reloads the component from the dialog.
*/
reloadFromDialog() {
this.store.reload({ params: this.queryParams });
}

private navigate(queryParams) {
this.router.navigate([], {
queryParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<dot-edit-ema-dialog
#dialog
(action)="onCustomEvent($event)"
(reloadFromDialog)="reloadFromDialog()"
data-testId="ema-dialog"></dot-edit-ema-dialog>
<p-confirmDialog
[style]="{
Expand Down
Loading

0 comments on commit 34a7450

Please sign in to comment.