Skip to content

Commit

Permalink
use publisher displayname instead of publisher id mappings (#234650)
Browse files Browse the repository at this point in the history
#84756 use publisher displayname instead of publisher id mappings
  • Loading branch information
sandy081 authored Nov 26, 2024
1 parent e7e6dfa commit 921f7ca
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "code-oss-dev",
"version": "1.96.0",
"distro": "7ee3017d79a5ea3bc82111b770cf444010c72d3b",
"distro": "e769f8fbe1910f7c4af007cc8eeb764b7f924cfe",
"author": {
"name": "Microsoft Corporation"
},
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/common/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export interface IProductConfiguration {
readonly nlsBaseUrl: string;
};

readonly extensionPublisherMappings?: IStringDictionary<string>;
readonly extensionPublisherOrgs?: readonly string[];

readonly extensionRecommendations?: IStringDictionary<IExtensionRecommendations>;
readonly configBasedExtensionTips?: IStringDictionary<IConfigBasedExtensionTip>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export abstract class CommontExtensionManagementService extends Disposable imple
}

async canInstall(extension: IGalleryExtension): Promise<true | IMarkdownString> {
const allowedToInstall = this.allowedExtensionsService.isAllowed({ id: extension.identifier.id });
const allowedToInstall = this.allowedExtensionsService.isAllowed({ id: extension.identifier.id, publisherDisplayName: extension.publisherDisplayName });
if (allowedToInstall !== true) {
return new MarkdownString(nls.localize('not allowed to install', "This extension cannot be installed because {0}", allowedToInstall.value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class AllowedExtensionsService extends Disposable implements IAllowedExte
_serviceBrand: undefined;

private allowedExtensions: AllowedExtensionsConfigValueType | undefined;
private readonly publisherMappings: IStringDictionary<string> = {};
private readonly publisherOrgs: string[];

private _onDidChangeAllowedExtensions = this._register(new Emitter<void>());
readonly onDidChangeAllowedExtensions = this._onDidChangeAllowedExtensions.event;
Expand All @@ -43,9 +43,7 @@ export class AllowedExtensionsService extends Disposable implements IAllowedExte
@IConfigurationService protected readonly configurationService: IConfigurationService
) {
super();
for (const key in productService.extensionPublisherMappings) {
this.publisherMappings[key.toLowerCase()] = productService.extensionPublisherMappings[key].toLowerCase();
}
this.publisherOrgs = productService.extensionPublisherOrgs?.map(p => p.toLowerCase()) ?? [];
this.allowedExtensions = this.getAllowedExtensionsValue();
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(AllowedExtensionsConfigKey)) {
Expand All @@ -67,31 +65,34 @@ export class AllowedExtensionsService extends Disposable implements IAllowedExte
return Object.fromEntries(entries);
}

isAllowed(extension: IGalleryExtension | IExtension | { id: string; version?: string; prerelease?: boolean; targetPlatform?: TargetPlatform }): true | IMarkdownString {
isAllowed(extension: IGalleryExtension | IExtension | { id: string; publisherDisplayName: string | undefined; version?: string; prerelease?: boolean; targetPlatform?: TargetPlatform }): true | IMarkdownString {
if (!this.allowedExtensions) {
return true;
}

let id: string, version: string, targetPlatform: TargetPlatform, prerelease: boolean, publisher: string;
let id: string, version: string, targetPlatform: TargetPlatform, prerelease: boolean, publisher: string, publisherDisplayName: string | undefined;

if (isGalleryExtension(extension)) {
id = extension.identifier.id.toLowerCase();
version = extension.version;
prerelease = extension.properties.isPreReleaseVersion;
publisher = extension.publisher.toLowerCase();
publisherDisplayName = extension.publisherDisplayName.toLowerCase();
targetPlatform = extension.properties.targetPlatform;
} else if (isIExtension(extension)) {
id = extension.identifier.id.toLowerCase();
version = extension.manifest.version;
prerelease = extension.preRelease;
publisher = extension.manifest.publisher.toLowerCase();
publisherDisplayName = extension.publisherDisplayName?.toLowerCase();
targetPlatform = extension.targetPlatform;
} else {
id = extension.id.toLowerCase();
version = extension.version ?? '*';
targetPlatform = extension.targetPlatform ?? TargetPlatform.UNIVERSAL;
prerelease = extension.prerelease ?? false;
publisher = extension.id.substring(0, extension.id.indexOf('.')).toLowerCase();
publisherDisplayName = extension.publisherDisplayName?.toLowerCase();
}

const settingsCommandLink = URI.parse(`command:workbench.action.openSettings?${encodeURIComponent(JSON.stringify({ query: `@id:${AllowedExtensionsConfigKey}` }))}`).toString();
Expand Down Expand Up @@ -123,14 +124,14 @@ export class AllowedExtensionsService extends Disposable implements IAllowedExte
return true;
}

publisher = (this.publisherMappings[publisher])?.toLowerCase() ?? publisher;
const publisherValue = this.allowedExtensions[publisher];
const publisherKey = publisherDisplayName && this.publisherOrgs.includes(publisherDisplayName) ? publisherDisplayName : publisher;
const publisherValue = this.allowedExtensions[publisherKey];
if (!isUndefined(publisherValue)) {
if (isBoolean(publisherValue)) {
return publisherValue ? true : new MarkdownString(nls.localize('publisher not allowed', "the extensions from this publisher are not in the [allowed list]({1})", publisher, settingsCommandLink));
return publisherValue ? true : new MarkdownString(nls.localize('publisher not allowed', "the extensions from this publisher are not in the [allowed list]({1})", publisherKey, settingsCommandLink));
}
if (publisherValue === 'release' && prerelease) {
return new MarkdownString(nls.localize('prerelease versions from this publisher not allowed', "the pre-release versions from this publisher are not in the [allowed list]({1})", publisher, settingsCommandLink));
return new MarkdownString(nls.localize('prerelease versions from this publisher not allowed', "the pre-release versions from this publisher are not in the [allowed list]({1})", publisherKey, settingsCommandLink));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
preRelease: !!extensionInfo.preRelease,
compatible: !!options.compatible
});
if (!options.compatible || this.allowedExtensionsService.isAllowed({ id: extensionInfo.id }) === true) {
if (!options.compatible || this.allowedExtensionsService.isAllowed({ id: extensionInfo.id, publisherDisplayName: rawGalleryExtension.publisher.displayName }) === true) {
toQuery.push(extensionInfo);
}
}
Expand All @@ -806,7 +806,7 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
if (await this.isExtensionCompatible(extension, includePreRelease, targetPlatform)) {
return extension;
}
if (this.allowedExtensionsService.isAllowed({ id: extension.identifier.id }) !== true) {
if (this.allowedExtensionsService.isAllowed({ id: extension.identifier.id, publisherDisplayName: extension.publisherDisplayName }) !== true) {
return null;
}
const query = new Query()
Expand Down Expand Up @@ -861,7 +861,7 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
return areApiProposalsCompatible(enabledApiProposals);
}

private async isValidVersion(extension: string, rawGalleryExtensionVersion: IRawGalleryExtensionVersion, versionType: 'release' | 'prerelease' | 'any', compatible: boolean, allTargetPlatforms: TargetPlatform[], targetPlatform: TargetPlatform, productVersion: IProductVersion = { version: this.productService.version, date: this.productService.date }): Promise<boolean> {
private async isValidVersion(extension: string, rawGalleryExtensionVersion: IRawGalleryExtensionVersion, publisherDisplayName: string, versionType: 'release' | 'prerelease' | 'any', compatible: boolean, allTargetPlatforms: TargetPlatform[], targetPlatform: TargetPlatform, productVersion: IProductVersion = { version: this.productService.version, date: this.productService.date }): Promise<boolean> {
const targetPlatformForExtension = getTargetPlatformForExtensionVersion(rawGalleryExtensionVersion);
if (!isTargetPlatformCompatible(targetPlatformForExtension, allTargetPlatforms, targetPlatform)) {
return false;
Expand All @@ -872,7 +872,7 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
}

if (compatible) {
if (this.allowedExtensionsService.isAllowed({ id: extension, version: rawGalleryExtensionVersion.version, prerelease: versionType === 'any' ? undefined : isPreReleaseVersion(rawGalleryExtensionVersion), targetPlatform: targetPlatformForExtension }) !== true) {
if (this.allowedExtensionsService.isAllowed({ id: extension, publisherDisplayName, version: rawGalleryExtensionVersion.version, prerelease: versionType === 'any' ? undefined : isPreReleaseVersion(rawGalleryExtensionVersion), targetPlatform: targetPlatformForExtension }) !== true) {
return false;
}
try {
Expand Down Expand Up @@ -1015,7 +1015,7 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
* Skip if the extension is not allowed.
* All versions are not needed in this case
*/
if (this.allowedExtensionsService.isAllowed({ id: extensionIdentifier.id }) !== true) {
if (this.allowedExtensionsService.isAllowed({ id: extensionIdentifier.id, publisherDisplayName: rawGalleryExtension.publisher.displayName }) !== true) {
continue;
}
}
Expand Down Expand Up @@ -1081,6 +1081,7 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
if (await this.isValidVersion(
extensionIdentifier.id,
rawGalleryExtensionVersion,
rawGalleryExtension.publisher.displayName,
includePreRelease ? 'any' : 'release',
criteria.compatible,
allTargetPlatforms,
Expand Down Expand Up @@ -1416,7 +1417,9 @@ abstract class AbstractExtensionGalleryService implements IExtensionGalleryServi
if (
(await this.isValidVersion(
extensionIdentifier.id,
version, includePreRelease ? 'any' : 'release',
version,
galleryExtensions[0].publisher.displayName,
includePreRelease ? 'any' : 'release',
true,
allTargetPlatforms,
targetPlatform))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ export interface IAllowedExtensionsService {
readonly _serviceBrand: undefined;

readonly onDidChangeAllowedExtensions: Event<void>;
isAllowed(extension: IGalleryExtension | IExtension | { id: string; version?: string; prerelease?: boolean }): true | IMarkdownString;

isAllowed(extension: IGalleryExtension | IExtension): true | IMarkdownString;
isAllowed(extension: { id: string; publisherDisplayName: string | undefined; version?: string; prerelease?: boolean; targetPlatform?: TargetPlatform }): true | IMarkdownString;
}

export async function computeSize(location: URI, fileService: IFileService): Promise<number> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class ExtensionManagementService extends AbstractExtensionManagementServi
throw new Error(nls.localize('incompatible', "Unable to install extension '{0}' as it is not compatible with VS Code '{1}'.", extensionId, this.productService.version));
}

const allowedToInstall = this.allowedExtensionsService.isAllowed({ id: extensionId, version: manifest.version });
const allowedToInstall = this.allowedExtensionsService.isAllowed({ id: extensionId, version: manifest.version, publisherDisplayName: undefined });
if (allowedToInstall !== true) {
throw new Error(nls.localize('notAllowed', "This extension cannot be installed because {0}", allowedToInstall.value));
}
Expand Down
Loading

0 comments on commit 921f7ca

Please sign in to comment.