Migrate PrestaShop config to Config API blocks and add permissions.

Replace custom ShopConfig pages/models with registerConfigBlocks, load config from Config store, and enforce RBAC on methods.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
fatequod
2026-07-22 12:20:30 +02:00
co-authored by Cursor
parent 139ac5cb52
commit 5a1e6ffbdd
27 changed files with 341 additions and 1206 deletions
+6 -11
View File
@@ -1,20 +1,15 @@
const { Core } = require('@orbito/api-lib');
const ShopConfig = require('../src/models/ShopConfig');
const PrestashopApi = require('../src/PrestaApi');
const { importFromPSOrder } = require('../src/OrderImporter');
const { isLegacyApi } = require('../src/utils');
const { loadConfig, isConfigured, setLastOrderId } = require('../src/module-config');
const { PERMISSIONS, requirePermission } = require('../src/register-permissions');
module.exports = async function(params, ctx) {
const configs = await ShopConfig.find({ isRemoved: { $ne: true } });
const active = configs.filter(c => c.apiUrl && c.apiKey);
requirePermission(PERMISSIONS.ORDERS_IMPORT, ctx);
if (active.length === 0) return { error: 'No active shop configs found' };
const config = params.configId
? active.find(c => String(c._id) === String(params.configId))
: active[0];
if (!config) return { error: 'Config not found' };
const config = await loadConfig();
if (!isConfigured(config)) return { error: 'No active shop configs found' };
const api = new PrestashopApi(config.apiUrl, config.apiKey, isLegacyApi(config.versionCode));
@@ -49,7 +44,7 @@ module.exports = async function(params, ctx) {
}
}
const maxId = Math.max(...orders.map(o => parseInt(o.id)));
await ShopConfig.update({ _id: config._id }, { lastOrderId: maxId });
await setLastOrderId(maxId);
return { shopName: config.shopName, imported, errors, newLastOrderId: maxId };
}