From f59571a4139a162a09576568a333e43bd8dfc778 Mon Sep 17 00:00:00 2001 From: Tami Takamiya Date: Tue, 28 Nov 2023 13:15:29 -0500 Subject: [PATCH] Show content matches' licenses only for licensed users --- src/features/lightspeed/base.ts | 3 ++- .../lightspeed/contentMatchesWebview.ts | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/features/lightspeed/base.ts b/src/features/lightspeed/base.ts index 71bff639e..f7f5d83a5 100644 --- a/src/features/lightspeed/base.ts +++ b/src/features/lightspeed/base.ts @@ -69,7 +69,8 @@ export class LightSpeedManager { this.context, this.client, this.settingsManager, - this.apiInstance + this.apiInstance, + this.lightSpeedAuthenticationProvider ); // create a new project lightspeed status bar item that we can manage diff --git a/src/features/lightspeed/contentMatchesWebview.ts b/src/features/lightspeed/contentMatchesWebview.ts index 4efafd5ec..0f6f13ae0 100644 --- a/src/features/lightspeed/contentMatchesWebview.ts +++ b/src/features/lightspeed/contentMatchesWebview.ts @@ -1,6 +1,7 @@ import * as vscode from "vscode"; import { LanguageClient } from "vscode-languageclient/node"; import { LightSpeedAPI } from "./api"; +import { LightSpeedAuthenticationProvider } from "./lightSpeedOAuthProvider"; import { SettingsManager } from "../../settings"; import { ContentMatchesRequestParams, @@ -17,6 +18,7 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider { private _view?: vscode.WebviewView; private _extensionUri: vscode.Uri; private context; + private lightSpeedAuthProvider: LightSpeedAuthenticationProvider; public client; public settingsManager: SettingsManager; public apiInstance: LightSpeedAPI; @@ -26,13 +28,15 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider { context: vscode.ExtensionContext, client: LanguageClient, settingsManager: SettingsManager, - apiInstance: LightSpeedAPI + apiInstance: LightSpeedAPI, + lightSpeedAuthProvider: LightSpeedAuthenticationProvider ) { this.context = context; this.client = client; this.settingsManager = settingsManager; this.apiInstance = apiInstance; this._extensionUri = context.extensionUri; + this.lightSpeedAuthProvider = lightSpeedAuthProvider; } public async resolveWebviewView( @@ -150,6 +154,7 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider { return noContentMatchesFoundHtml; } + const rhUserHasSeat = await this.lightSpeedAuthProvider.rhUserHasSeat(); for (let taskIndex = 0; taskIndex < suggestedTasks.length; taskIndex++) { let taskNameDescription = suggestedTasks[taskIndex].name; if (!taskNameDescription) { @@ -159,7 +164,8 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider { const contentMatchValue = contentMatchResponses.contentmatches[taskIndex]; contentMatchesHtml += this.renderContentMatchWithTasKDescription( (contentMatchValue).contentmatch, - taskNameDescription || "" + taskNameDescription || "", + rhUserHasSeat === true ); } const html = ` @@ -172,8 +178,12 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider { } private renderContentMatches( - contentMatchResponse: IContentMatchParams + contentMatchResponse: IContentMatchParams, + rhUserHasSeat: boolean ): string { + const licenseLine = rhUserHasSeat + ? `
  • License: ${contentMatchResponse.license}
  • ` + : ""; return `
    ${contentMatchResponse.repo_name} @@ -181,7 +191,7 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider {
  • URL: ${contentMatchResponse.repo_url}
  • Path: ${contentMatchResponse.path}
  • Data Source: ${contentMatchResponse.data_source_description}
  • -
  • License: ${contentMatchResponse.license}
  • + ${licenseLine}
  • Score: ${contentMatchResponse.score}
  • @@ -190,12 +200,14 @@ export class ContentMatchesWebview implements vscode.WebviewViewProvider { private renderContentMatchWithTasKDescription( contentMatchesResponse: IContentMatchParams[], - taskDescription: string + taskDescription: string, + rhUserHasSeat: boolean ): string { let taskContentMatch = ""; for (let index = 0; index < contentMatchesResponse.length; index++) { taskContentMatch += `${this.renderContentMatches( - contentMatchesResponse[index] + contentMatchesResponse[index], + rhUserHasSeat )}`; }