Skip to content

Commit

Permalink
don't rely only on latestStatus to set license as trial
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Oct 4, 2024
1 parent ec3e55e commit 2310bc7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/constants.subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ export const enum SubscriptionState {
ProTrialReactivationEligible = 5,
/** Indicates a Pro/Teams/Enterprise paid user */
Paid = 6,
/** Indicates a Paid user who's license has expired */
PaidExpired = 7,
}
2 changes: 1 addition & 1 deletion src/git/gitProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { AccessDeniedError, CancellationError, ProviderNotFoundError, ProviderNo
import type { FeatureAccess, Features, PlusFeatures, RepoFeatureAccess } from '../features';
import { getApplicablePromo } from '../plus/gk/account/promos';
import type { Subscription } from '../plus/gk/account/subscription';
import { isSubscriptionExpired, isSubscriptionPaidPlan, SubscriptionPlanId } from '../plus/gk/account/subscription';
import { isSubscriptionExpired, isSubscriptionPaidPlan } from '../plus/gk/account/subscription';
import type { SubscriptionChangeEvent } from '../plus/gk/account/subscriptionService';
import type { HostingIntegration } from '../plus/integrations/integration';
import type { RepoComparisonKey } from '../repositories';
Expand Down
28 changes: 18 additions & 10 deletions src/plus/gk/checkin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { SubscriptionPlanId } from '../../constants.subscription';
import type { Organization } from './account/organization';
import type { Subscription } from './account/subscription';
import {
getSubscriptionPlan,
getSubscriptionPlanPriority,
isSubscriptionExpired,
SubscriptionPlanId,
} from './account/subscription';
import { getSubscriptionPlan, getSubscriptionPlanPriority, isSubscriptionExpired } from './account/subscription';

export type GKLicenses = Partial<Record<GKLicenseType, GKLicense>>;

Expand Down Expand Up @@ -136,14 +131,21 @@ export function getSubscriptionFromCheckIn(
organizationId != null ? paidLicensesByOrganizationId.get(organizationId) ?? bestPaidLicense : bestPaidLicense;
if (chosenPaidLicense != null) {
const [licenseType, license] = chosenPaidLicense;
const latestStartDate = new Date(license.latestStartDate);
const latestEndDate = new Date(license.latestEndDate);
const today = new Date();
actual = getSubscriptionPlan(
convertLicenseTypeToPlanId(licenseType),
isBundleLicenseType(licenseType),
license.reactivationCount ?? 0,
license.organizationId,
new Date(license.latestStartDate),
new Date(license.latestEndDate),
license.latestStatus === 'trial' || license.latestStatus === 'in_trial',
latestStartDate,
latestEndDate,
undefined,
undefined,
(license.latestStatus === 'in_trial' || license.latestStatus === 'trial') &&
latestEndDate > today &&
today > latestStartDate,
);
}

Expand All @@ -161,6 +163,7 @@ export function getSubscriptionFromCheckIn(
undefined,
undefined,
data.nextOptInDate,
false,
);
}

Expand All @@ -171,6 +174,9 @@ export function getSubscriptionFromCheckIn(
: bestEffectiveLicense;
if (chosenEffectiveLicense != null) {
const [licenseType, license] = chosenEffectiveLicense;
const latestStartDate = new Date(license.latestStartDate);
const latestEndDate = new Date(license.latestEndDate);
const today = new Date();
effective = getSubscriptionPlan(
convertLicenseTypeToPlanId(licenseType),
isBundleLicenseType(licenseType),
Expand All @@ -180,7 +186,9 @@ export function getSubscriptionFromCheckIn(
new Date(license.latestEndDate),
license.latestStatus === 'cancelled',
license.nextOptInDate ?? data.nextOptInDate,
license.latestStatus === 'trial' || license.latestStatus === 'in_trial',
(license.latestStatus === 'in_trial' || license.latestStatus === 'trial') &&
latestEndDate > today &&
today > latestStartDate,
);
}

Expand Down

0 comments on commit 2310bc7

Please sign in to comment.