diff --git a/src/appstore.js b/src/appstore.js index 92e9acaf2..618a78c83 100644 --- a/src/appstore.js +++ b/src/appstore.js @@ -65,17 +65,6 @@ function getFeatures() { return gFeatures; } -function isAppAllowed(appstoreId, listingConfig) { - assert.strictEqual(typeof listingConfig, 'object'); - assert.strictEqual(typeof appstoreId, 'string'); - - if (listingConfig.blacklist && listingConfig.blacklist.includes(appstoreId)) return false; - - if (listingConfig.whitelist) return listingConfig.whitelist.includes(appstoreId); - - return true; -} - async function login(email, password, totpToken) { assert.strictEqual(typeof email, 'string'); assert.strictEqual(typeof password, 'string'); @@ -407,19 +396,13 @@ async function getApps() { if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `App listing failed. ${response.status} ${JSON.stringify(response.body)}`); if (!response.body.apps) throw new BoxError(BoxError.EXTERNAL_ERROR, `Bad response: ${response.status} ${response.text}`); - const listingConfig = await settings.getAppstoreListingConfig(); - const filteredApps = response.body.apps.filter(app => isAppAllowed(app.id, listingConfig)); - return filteredApps; + return response.body.apps; } async function getAppVersion(appId, version) { assert.strictEqual(typeof appId, 'string'); assert.strictEqual(typeof version, 'string'); - const listingConfig = await settings.getAppstoreListingConfig(); - - if (!isAppAllowed(appId, listingConfig)) throw new BoxError(BoxError.FEATURE_DISABLED); - const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY); if (!token) throw new BoxError(BoxError.LICENSE_ERROR, 'Missing token'); diff --git a/src/routes/branding.js b/src/routes/branding.js index b81be730c..689af8da8 100644 --- a/src/routes/branding.js +++ b/src/routes/branding.js @@ -12,8 +12,7 @@ const assert = require('assert'), HttpError = require('connect-lastmile').HttpError, HttpSuccess = require('connect-lastmile').HttpSuccess, safe = require('safetydance'), - settings = require('../settings.js'), - _ = require('underscore'); + settings = require('../settings.js'); async function getFooter(req, res, next) { const [error, footer] = await safe(settings.getFooter()); @@ -51,37 +50,6 @@ async function getCloudronName(req, res, next) { next(new HttpSuccess(200, { name })); } -async function setAppstoreListingConfig(req, res, next) { - assert.strictEqual(typeof req.body, 'object'); - - const listingConfig = _.pick(req.body, 'whitelist', 'blacklist'); - if (Object.keys(listingConfig).length === 0) return next(new HttpError(400, 'blacklist or whitelist is required')); - - if ('whitelist' in listingConfig) { - if (listingConfig.whitelist !== null && !Array.isArray(listingConfig.whitelist)) return next(new HttpError(400, 'whitelist is null or an array of strings')); - - if (listingConfig.whitelist && !listingConfig.whitelist.every(id => typeof id === 'string')) return next(new HttpError(400, 'whitelist must be array of strings')); - } - - if ('blacklist' in listingConfig) { - if (!Array.isArray(listingConfig.blacklist)) return next(new HttpError(400, 'blacklist an array of strings')); - - if (!listingConfig.blacklist.every(id => typeof id === 'string')) return next(new HttpError(400, 'blacklist must be array of strings')); - } - - const [error] = await safe(settings.setAppstoreListingConfig(listingConfig)); - if (error) return next(BoxError.toHttpError(error)); - - next(new HttpSuccess(200, {})); -} - -async function getAppstoreListingConfig(req, res, next) { - const [error, listingConfig] = await safe(settings.getAppstoreListingConfig()); - if (error) return next(BoxError.toHttpError(error)); - - next(new HttpSuccess(200, listingConfig)); -} - async function setCloudronAvatar(req, res, next) { assert.strictEqual(typeof req.files, 'object'); @@ -110,7 +78,6 @@ async function get(req, res, next) { assert.strictEqual(typeof req.params.setting, 'string'); switch (req.params.setting) { - case settings.APPSTORE_LISTING_CONFIG_KEY: return await getAppstoreListingConfig(req, res, next); case settings.CLOUDRON_AVATAR_KEY: return await getCloudronAvatar(req, res, next); case settings.CLOUDRON_NAME_KEY: return await getCloudronName(req, res, next); case settings.FOOTER_KEY: return await getFooter(req, res, next); @@ -123,7 +90,6 @@ async function set(req, res, next) { assert.strictEqual(typeof req.body, 'object'); switch (req.params.setting) { - case settings.APPSTORE_LISTING_CONFIG_KEY: return await setAppstoreListingConfig(req, res, next); case settings.CLOUDRON_AVATAR_KEY: return await setCloudronAvatar(req, res, next); case settings.CLOUDRON_NAME_KEY: return await setCloudronName(req, res, next); case settings.FOOTER_KEY: return await setFooter(req, res, next); diff --git a/src/routes/test/branding-test.js b/src/routes/test/branding-test.js index d56a560b4..c6e8ea5ae 100644 --- a/src/routes/test/branding-test.js +++ b/src/routes/test/branding-test.js @@ -97,77 +97,6 @@ describe('Branding API', function () { }); }); - describe('appstore listing config', function () { - it('get default succeeds', async function () { - const response = await superagent.get(`${serverUrl}/api/v1/branding/appstore_listing_config`) - .query({ access_token: owner.token }); - - expect(response.statusCode).to.equal(200); - expect(response.body.whitelist).to.eql(null); - expect(response.body.blacklist).to.eql([]); - }); - - it('cannot set with no bl or wl', async function () { - const response = await superagent.post(`${serverUrl}/api/v1/branding/appstore_listing_config`) - .query({ access_token: owner.token }) - .ok(() => true); - - expect(response.statusCode).to.equal(400); - }); - - it('cannot set bad bl', async function () { - const response = await superagent.post(`${serverUrl}/api/v1/branding/appstore_listing_config`) - .query({ access_token: owner.token }) - .send({ blacklist: [ 1 ] }) - .ok(() => true); - - expect(response.statusCode).to.equal(400); - }); - - it('cannot set bad wl', async function () { - const response = await superagent.post(`${serverUrl}/api/v1/branding/appstore_listing_config`) - .query({ access_token: owner.token }) - .send({ whitelist: 4 }) - .ok(() => true); - - expect(response.statusCode).to.equal(400); - }); - - it('set bl succeeds', async function () { - const response = await superagent.post(`${serverUrl}/api/v1/branding/appstore_listing_config`) - .query({ access_token: owner.token }) - .send({ blacklist: [ 'id1', 'id2' ] }); - - expect(response.statusCode).to.equal(200); - }); - - it('get bl succeeds', async function () { - const response = await superagent.get(`${serverUrl}/api/v1/branding/appstore_listing_config`) - .query({ access_token: owner.token }); - - expect(response.statusCode).to.equal(200); - expect(response.body.blacklist).to.eql([ 'id1', 'id2' ]); - expect(response.body.whitelist).to.be(undefined); - }); - - it('set wl succeeds', async function () { - const response = await superagent.post(`${serverUrl}/api/v1/branding/appstore_listing_config`) - .query({ access_token: owner.token }) - .send({ whitelist: [ 'id1', 'id2' ] }); - - expect(response.statusCode).to.equal(200); - }); - - it('get wl succeeds', async function () { - const response = await superagent.get(`${serverUrl}/api/v1/branding/appstore_listing_config`) - .query({ access_token: owner.token }); - - expect(response.statusCode).to.equal(200); - expect(response.body.whitelist).to.eql([ 'id1', 'id2' ]); - expect(response.body.blacklist).to.be(undefined); - }); - }); - describe('footer', function () { it('get default succeeds', async function () { const response = await superagent.get(`${serverUrl}/api/v1/branding/footer`) diff --git a/src/settings.js b/src/settings.js index 91f5ad64b..b7e9d2887 100644 --- a/src/settings.js +++ b/src/settings.js @@ -52,9 +52,6 @@ exports = module.exports = { getProfileConfig, setProfileConfig, - getAppstoreListingConfig, - setAppstoreListingConfig, - getGhosts, setGhosts, @@ -97,7 +94,6 @@ exports = module.exports = { DIRECTORY_SERVER_KEY: 'user_directory_config', REGISTRY_CONFIG_KEY: 'registry_config', SYSINFO_CONFIG_KEY: 'sysinfo_config', // misnomer: ipv4 config - APPSTORE_LISTING_CONFIG_KEY: 'appstore_listing_config', SUPPORT_CONFIG_KEY: 'support_config', PROFILE_CONFIG_KEY: 'profile_config', GHOSTS_CONFIG_KEY: 'ghosts_config', @@ -213,11 +209,6 @@ const gDefaults = (function () { result[exports.CONSOLE_SERVER_ORIGIN_KEY] = 'https://console.cloudron.io'; result[exports.DEMO_KEY] = false; - result[exports.APPSTORE_LISTING_CONFIG_KEY] = { - blacklist: [], - whitelist: null // null imples nothing is whitelisted. this is an array - }; - result[exports.GHOSTS_CONFIG_KEY] = {}; result[exports.SUPPORT_CONFIG_KEY] = { @@ -582,20 +573,6 @@ async function setProfileConfig(directoryConfig) { notifyChange(exports.PROFILE_CONFIG_KEY, directoryConfig); } -async function getAppstoreListingConfig() { - const value = await get(exports.APPSTORE_LISTING_CONFIG_KEY); - if (value === null) return gDefaults[exports.APPSTORE_LISTING_CONFIG_KEY]; - - return JSON.parse(value); -} - -async function setAppstoreListingConfig(listingConfig) { - assert.strictEqual(typeof listingConfig, 'object'); - - await set(exports.APPSTORE_LISTING_CONFIG_KEY, JSON.stringify(listingConfig)); - notifyChange(exports.APPSTORE_LISTING_CONFIG_KEY, listingConfig); -} - async function getGhosts() { const value = await get(exports.GHOSTS_CONFIG_KEY); if (value === null) return gDefaults[exports.GHOSTS_CONFIG_KEY];