Skip to content

Commit

Permalink
Removing fixSiteProducts method (#1236)
Browse files Browse the repository at this point in the history
Context:
Removing an obsolete method that was fixing an issue with default site products.
Details can be found here 76d9448

Proposed solution:
Removing this method and its test.

Test plan:
not needed

#1236
  • Loading branch information
berhalak authored Oct 1, 2024
1 parent 77194dc commit 437d7e6
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 213 deletions.
62 changes: 0 additions & 62 deletions app/gen-server/lib/Housekeeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { ApiError } from 'app/common/ApiError';
import { delay } from 'app/common/delay';
import { buildUrlId } from 'app/common/gristUrls';
import { normalizedDateTimeString } from 'app/common/normalizedDateTimeString';
import { BillingAccount } from 'app/gen-server/entity/BillingAccount';
import { Document } from 'app/gen-server/entity/Document';
import { Organization } from 'app/gen-server/entity/Organization';
import { Product } from 'app/gen-server/entity/Product';
import { Workspace } from 'app/gen-server/entity/Workspace';
import { HomeDBManager, Scope } from 'app/gen-server/lib/homedb/HomeDBManager';
import { fromNow } from 'app/gen-server/sqlUtils';
Expand Down Expand Up @@ -438,63 +436,3 @@ async function forEachWithBreaks<T>(logText: string, items: T[], callback: (item
}
log.rawInfo(logText, {itemsProcesssed, itemsTotal, timeMs: Date.now() - start});
}

/**
* For a brief moment file `stubs/app/server/server.ts` was ignoring the GRIST_DEFAULT_PRODUCT
* variable, which is currently set for all deployment types to 'Free' product. As a result orgs
* created after 2024-06-12 (1.1.15) were created with 'teamFree' product instead of 'Free'.
* It only affected deployments that were using:
* - GRIST_DEFAULT_PRODUCT variable set to 'Free'
* - GRIST_SINGLE_ORG set to enforce single org mode.
*
* This method fixes the product for all orgs created with 'teamFree' product, if the default
* product that should be used is 'Free' and the deployment type is not 'saas' ('saas' deployment
* isn't using GRIST_DEFAULT_PRODUCT variable). This method should be removed after 2024.10.01.
*
* There is a corresponding test that will fail if this method (and that test) are not removed.
*
* @returns true if the method was run, false otherwise.
*/
export async function fixSiteProducts(options: {
deploymentType: string,
db: HomeDBManager
}) {
const {deploymentType, db} = options;

const hasDefaultProduct = () => Boolean(process.env.GRIST_DEFAULT_PRODUCT);
const defaultProductIsFree = () => process.env.GRIST_DEFAULT_PRODUCT === 'Free';
const notSaasDeployment = () => deploymentType !== 'saas';
const mustRun = hasDefaultProduct() && defaultProductIsFree() && notSaasDeployment();
if (!mustRun) {
return false;
}
const removeMeDate = new Date('2024-10-01');
const warningMessage = `WARNING: This method should be removed after ${removeMeDate.toDateString()}.`;
if (new Date() > removeMeDate) {
console.warn(warningMessage);
}

// Find all billing accounts on teamFree product and change them to the Free.
return await db.connection.transaction(async (t) => {
const freeProduct = await t.findOne(Product, {where: {name: 'Free'}});
const freeTeamProduct = await t.findOne(Product, {where: {name: 'teamFree'}});

if (!freeTeamProduct) {
console.warn('teamFree product not found.');
return false;
}

if (!freeProduct) {
console.warn('Free product not found.');
return false;
}

await t.createQueryBuilder()
.update(BillingAccount)
.set({product: freeProduct.id})
.where({product: freeTeamProduct.id})
.execute();

return true;
});
}
5 changes: 0 additions & 5 deletions stubs/app/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import {commonUrls} from 'app/common/gristUrls';
import {isAffirmative} from 'app/common/gutil';
import {HomeDBManager} from 'app/gen-server/lib/homedb/HomeDBManager';
import {fixSiteProducts} from 'app/gen-server/lib/Housekeeper';

const debugging = isAffirmative(process.env.DEBUG) || isAffirmative(process.env.VERBOSE);

Expand Down Expand Up @@ -132,10 +131,6 @@ export async function main() {
if (process.env.GRIST_SERVE_PLUGINS_PORT) {
await mergedServer.flexServer.startCopy('pluginServer', parseInt(process.env.GRIST_SERVE_PLUGINS_PORT, 10));
}
await fixSiteProducts({
deploymentType: mergedServer.flexServer.getDeploymentType(),
db: mergedServer.flexServer.getHomeDBManager()
});

return mergedServer.flexServer;
}
Expand Down
146 changes: 0 additions & 146 deletions test/server/fixSiteProducts.ts

This file was deleted.

0 comments on commit 437d7e6

Please sign in to comment.