Skip to content

Commit 413783e

Browse files
committed
Adds access check to integrations
Enforces access check
1 parent 62a9f14 commit 413783e

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/autolinks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export class Autolinks implements Disposable {
188188
await Promise.allSettled(
189189
supportedAutolinkIntegrations.map(async integrationId => {
190190
const integration = await this.container.integrations.get(integrationId);
191+
// Don't check for integration access, as we want to allow autolinks to always be generated
191192
const autoLinks = await integration.autolinks();
192193
if (autoLinks.length) {
193194
refsets.push([integration, autoLinks]);
@@ -198,6 +199,7 @@ export class Autolinks implements Disposable {
198199
// Remote-specific autolinks and remote integration autolinks
199200
if (remote?.provider != null) {
200201
const autoLinks = [];
202+
// Don't check for integration access, as we want to allow autolinks to always be generated
201203
const integrationAutolinks = await (await remote.getIntegration())?.autolinks();
202204
if (integrationAutolinks?.length) {
203205
autoLinks.push(...integrationAutolinks);
@@ -293,7 +295,7 @@ export class Autolinks implements Disposable {
293295
let integration = await remote?.getIntegration();
294296
if (integration != null) {
295297
const connected = integration.maybeConnected ?? (await integration.isConnected());
296-
if (!connected) {
298+
if (!connected || !(await integration.access())) {
297299
integration = undefined;
298300
}
299301
}
@@ -305,7 +307,7 @@ export class Autolinks implements Disposable {
305307
: undefined;
306308
if (linkIntegration != null) {
307309
const connected = linkIntegration.maybeConnected ?? (await linkIntegration.isConnected());
308-
if (!connected) {
310+
if (!connected || !(await linkIntegration.access())) {
309311
linkIntegration = undefined;
310312
}
311313
}

src/plus/integrations/integration.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Logger } from '../../system/logger';
2525
import type { LogScope } from '../../system/logger.scope';
2626
import { getLogScope } from '../../system/logger.scope';
2727
import { configuration } from '../../system/vscode/configuration';
28+
import { isSubscriptionStatePaidOrTrial } from '../gk/account/subscription';
2829
import type {
2930
IntegrationAuthenticationProviderDescriptor,
3031
IntegrationAuthenticationService,
@@ -107,6 +108,11 @@ export abstract class IntegrationBase<
107108
return this.id;
108109
}
109110

111+
async access(): Promise<boolean> {
112+
const subscription = await this.container.subscription.getSubscription();
113+
return isSubscriptionStatePaidOrTrial(subscription.state);
114+
}
115+
110116
autolinks():
111117
| (AutolinkReference | DynamicAutolinkReference)[]
112118
| Promise<(AutolinkReference | DynamicAutolinkReference)[]> {

src/plus/integrations/providers/github.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationI
265265
return 'https://api.github.com';
266266
}
267267

268+
override access(): Promise<boolean> {
269+
// Always allow GitHub cloud integration access
270+
return Promise.resolve(true);
271+
}
272+
268273
// This is a special case for GitHub because we use VSCode's GitHub session, and it can be disconnected
269274
// outside of the extension.
270275
override async refresh() {

src/plus/integrations/providers/gitlab.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ export class GitLabIntegration extends GitLabIntegrationBase<HostingIntegrationI
322322
protected get apiBaseUrl(): string {
323323
return 'https://gitlab.com/api';
324324
}
325+
326+
override access(): Promise<boolean> {
327+
// Always allow GitHub cloud integration access
328+
return Promise.resolve(true);
329+
}
325330
}
326331

327332
export class GitLabSelfHostedIntegration extends GitLabIntegrationBase<SelfHostedIntegrationId.GitLabSelfHosted> {

0 commit comments

Comments
 (0)