Skip to content

Commit

Permalink
WIP - AAP-18386
Browse files Browse the repository at this point in the history
  • Loading branch information
goneri committed Dec 4, 2023
1 parent 2ffcfc2 commit 31915d9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/features/lightspeed/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ export class LightSpeedAPI {
vscode.window.showErrorMessage(
`Model ID "${this.settingsManager.settings.lightSpeedService.model}" is invalid. Please contact your administrator.`
);
} else if (
responseErrorData &&
responseErrorData.hasOwnProperty("code") &&
responseErrorData.code === "permission_denied_wca_api_key_is_missing"
) {
vscode.window.showErrorMessage(
`You do not have a licensed seat for Ansible Lightspeed and your\norganization is using the paid commercial service. Contact your Red Hat Organization's administrator for more information on how to get a licensed seat.`
);
} else {
vscode.window.showErrorMessage(
`User not authorized to access Ansible Lightspeed.`
Expand Down
29 changes: 28 additions & 1 deletion src/features/lightspeed/lightSpeedOAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ export class LightSpeedAuthenticationProvider

const identifier = uuid();
const userName = userinfo.external_username || userinfo.username || "";
const rhOrgHasSubscription = userinfo.rh_org_has_subscription
? userinfo.rh_org_has_subscription
: false;
const rhUserHasSeat = userinfo.rh_user_has_seat
? userinfo.rh_user_has_seat
: false;

let label = userName;
if (rhUserHasSeat) {
label += " (licensed)";
} else if (rhOrgHasSubscription) {
label += " (no seat assigned)";
} else {
label += " (Tech Preview)";
}
Expand Down Expand Up @@ -172,7 +177,8 @@ export class LightSpeedAuthenticationProvider

lightSpeedManager.statusBarProvider.statusBar.text =
await lightSpeedManager.statusBarProvider.getLightSpeedStatusBarText(
rhUserHasSeat
rhUserHasSeat,
rhOrgHasSubscription
);

lightSpeedManager.statusBarProvider.setLightSpeedStatusBarTooltip(
Expand Down Expand Up @@ -630,4 +636,25 @@ export class LightSpeedAuthenticationProvider
return false;
}
}

public async rhOrgHasSubscription(): Promise<boolean | undefined> {
const authSession = await this.getLightSpeedAuthSession();
if (authSession === undefined) {
console.log(
"[ansible-lightspeed-oauth] User authentication session not found."
);
return undefined;
} else if (authSession?.rhOrgHasSubscription) {
console.log(
`[ansible-lightspeed-oauth] User "${authSession?.account?.label}" has an Org with a subscription.`
);
return true;
} else {
console.log(
`[ansible-lightspeed-oauth] User "${authSession?.account?.label}" does have an Org with a subscription.`
);
return false;
}
}

}
8 changes: 7 additions & 1 deletion src/features/lightspeed/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ export class LightspeedStatusBar {
}

public async getLightSpeedStatusBarText(
rhUserHasSeat?: boolean
rhUserHasSeat?: boolean,
rhOrgHasSubscription?: boolean
): Promise<string> {
let lightSpeedStatusbarText;
if (rhUserHasSeat === undefined) {
rhUserHasSeat = await this.lightSpeedAuthProvider.rhUserHasSeat();
}
if (rhOrgHasSubscription === undefined) {
rhOrgHasSubscription = await this.lightSpeedAuthProvider.rhOrgHasSubscription();
}
if (rhUserHasSeat === true) {
lightSpeedStatusbarText = "Lightspeed (licensed)";
} else if (rhOrgHasSubscription === true) {
lightSpeedStatusbarText = "Lightspeed (no seat assigned)";
} else if (rhUserHasSeat === false) {
lightSpeedStatusbarText = "Lightspeed (Tech Preview)";
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/features/lightspeed/utils/webUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export function getLoggedInSessionDetails(
const modelInfo: LightspeedSessionModelInfo = {};
if (sessionData.rhUserHasSeat) {
userInfo.userType = "Licensed";
} else if (sessionData.rhOrgHasSubscription) {
userInfo.userType = "no seat assigned";
} else {
userInfo.userType = "Tech Preview";
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/lightspeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface IAdditionalContext {
}

export interface LightspeedSessionUserInfo {
userType?: "Licensed" | "Tech Preview";
userType?: "Licensed" | "no seat assigned" | "Tech Preview";
role?: string;
subscribed?: boolean;
}
Expand Down

0 comments on commit 31915d9

Please sign in to comment.