diff --git a/src/appstore.js b/src/appstore.js index f473fd6a6..99aaa3524 100644 --- a/src/appstore.js +++ b/src/appstore.js @@ -60,53 +60,12 @@ let gFeatures = { // attempt to load feature cache in case appstore would be down let tmp = safe.JSON.parse(safe.fs.readFileSync(paths.FEATURES_INFO_FILE, 'utf8')); -if (tmp) { - gFeatures.userMaxCount = tmp.userMaxCount; - gFeatures.externalLdap = tmp.externalLdap; - gFeatures.eventLog = tmp.eventLog; - gFeatures.privateDockerRegistry = tmp.privateDockerRegistry; - gFeatures.branding = tmp.branding; -} +if (tmp) gFeatures = tmp; function getFeatures() { return gFeatures; } -function updateFeatures(subscriptionInfo) { - assert.strictEqual(typeof subscriptionInfo, 'object'); - - if (subscriptionInfo.plan.id === '2020-03_personal') { - gFeatures.userMaxCount = 5; - gFeatures.externalLdap = false; - gFeatures.eventLog = false; - gFeatures.privateDockerRegistry = false; - gFeatures.branding = false; - } else if (subscriptionInfo.plan.id === '2020-03_business' || subscriptionInfo.plan.id === 'education' || subscriptionInfo.plan.id === 'contributor') { - gFeatures.userMaxCount = null; // unlimited - gFeatures.externalLdap = true; - gFeatures.eventLog = true; - gFeatures.privateDockerRegistry = true; - gFeatures.branding = true; - } else { - // FIXME adjust the time - if (moment(subscriptionInfo.cloudronCreatedAt).isBefore('2020-02-10')) { // previously we only had app restrictions - gFeatures.userMaxCount = null; // unlimited - gFeatures.externalLdap = true; - gFeatures.eventLog = true; - gFeatures.privateDockerRegistry = true; - gFeatures.branding = true; - } else { // this is the 2020 free tier - gFeatures.userMaxCount = 3; - gFeatures.externalLdap = false; - gFeatures.eventLog = false; - gFeatures.privateDockerRegistry = false; - gFeatures.branding = false; - } - } - - safe.fs.writeFileSync(paths.FEATURES_INFO_FILE, JSON.stringify(gFeatures), 'utf8'); -} - function isAppAllowed(appstoreId, listingConfig) { assert.strictEqual(typeof listingConfig, 'object'); assert.strictEqual(typeof appstoreId, 'string'); @@ -185,8 +144,9 @@ function getSubscription(callback) { if (result.statusCode === 502) return callback(new BoxError(BoxError.EXTERNAL_ERROR, `Stripe error: ${error.message}`)); if (result.statusCode !== 200) return callback(new BoxError(BoxError.EXTERNAL_ERROR, `Unknown error: ${error.message}`)); - // update the features - updateFeatures(result.body); + // update the features cache + gFeatures = result.body.features; + safe.fs.writeFileSync(paths.FEATURES_INFO_FILE, JSON.stringify(gFeatures), 'utf8'); callback(null, result.body); }); diff --git a/src/routes/appstore.js b/src/routes/appstore.js index e152bea49..84dc97082 100644 --- a/src/routes/appstore.js +++ b/src/routes/appstore.js @@ -66,6 +66,6 @@ function getSubscription(req, res, next) { appstore.getSubscription(function (error, result) { if (error) return next(BoxError.toHttpError(error)); - next(new HttpSuccess(200, result)); // { email, cloudronId, plan, cancel_at, status } + next(new HttpSuccess(200, result)); // { email, cloudronId, cloudronCreatedAt, plan, current_period_end, canceled_at, cancel_at, status, features } }); }