-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from ckeditor/ck/6773
Feature: Check minimum supported editor version before injecting cloud files.
- Loading branch information
Showing
9 changed files
with
138 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { type CKCdnVersion, isCKCdnTestingVersion } from '../cdn/ck/isCKCdnVersion.js'; | ||
import { destructureSemanticVersion } from '../utils/version/destructureSemanticVersion.js'; | ||
import type { LicenseKeyVersion } from './LicenseKey.js'; | ||
|
||
/** | ||
* Returns the license version that is supported by the given CKEditor version. | ||
* | ||
* @param version The CKEditor version (semantic version or testing version). | ||
* @returns The supported license version. | ||
*/ | ||
export function getLicenseVersionFromEditorVersion( version: CKCdnVersion ): LicenseKeyVersion { | ||
// Assume that the testing version is always the newest one | ||
// so we can return the highest supported license version. | ||
if ( isCKCdnTestingVersion( version ) ) { | ||
return 3; | ||
} | ||
|
||
const { major } = destructureSemanticVersion( version ); | ||
|
||
switch ( true ) { | ||
case major >= 44: | ||
return 3; | ||
|
||
case major >= 38: | ||
return 2; | ||
|
||
default: | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { destructureSemanticVersion } from '../utils/version/destructureSemanticVersion.js'; | ||
import { isCKCdnTestingVersion, type CKCdnVersion } from '../cdn/ck/isCKCdnVersion.js'; | ||
import { getLicenseVersionFromEditorVersion } from './getLicenseVersionFromEditorVersion.js'; | ||
|
||
/** | ||
* Checks if the CKEditor CDN is supported by the given editor version. | ||
* | ||
* @param version The CKEditor version. | ||
* @returns `true` if the CDN is supported, `false` otherwise. | ||
*/ | ||
export function isCKCdnSupportedByEditorVersion( version: CKCdnVersion ): boolean { | ||
if ( isCKCdnTestingVersion( version ) ) { | ||
return true; | ||
} | ||
|
||
const { major } = destructureSemanticVersion( version ); | ||
const licenseVersion = getLicenseVersionFromEditorVersion( version ); | ||
|
||
switch ( licenseVersion ) { | ||
// For newer license versions, we support all newer versions. | ||
case 3: | ||
return true; | ||
|
||
// For the license v1-v2, we support only the 43 version. | ||
default: | ||
return major === 43; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { describe, it, expect } from 'vitest'; | ||
import { isCKCdnSupportedByEditorVersion } from '@/license/isCKCdnSupportedByEditorVersion.js'; | ||
|
||
describe( 'isCKCdnSupportedByEditorVersion', () => { | ||
it( 'should return true for testing versions', () => { | ||
expect( isCKCdnSupportedByEditorVersion( 'alpha' ) ).toBe( true ); | ||
expect( isCKCdnSupportedByEditorVersion( 'nightly' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return true for version 44.x.x (license v3)', () => { | ||
expect( isCKCdnSupportedByEditorVersion( '44.0.0' ) ).toBe( true ); | ||
expect( isCKCdnSupportedByEditorVersion( '44.1.0' ) ).toBe( true ); | ||
expect( isCKCdnSupportedByEditorVersion( '44.1.1' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return true for version 43.x.x (license v1-v2)', () => { | ||
expect( isCKCdnSupportedByEditorVersion( '43.0.0' ) ).toBe( true ); | ||
expect( isCKCdnSupportedByEditorVersion( '43.1.0' ) ).toBe( true ); | ||
expect( isCKCdnSupportedByEditorVersion( '43.2.1' ) ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return false for versions below 43.x.x', () => { | ||
expect( isCKCdnSupportedByEditorVersion( '42.0.0' ) ).toBe( false ); | ||
expect( isCKCdnSupportedByEditorVersion( '41.1.0' ) ).toBe( false ); | ||
expect( isCKCdnSupportedByEditorVersion( '40.0.0' ) ).toBe( false ); | ||
} ); | ||
} ); |