mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 22:54:31 +00:00
Apply Alex's missing feedback
This commit is contained in:
parent
c43369165c
commit
5f86716429
@ -3,7 +3,6 @@
|
||||
const { features } = require('@strapi/strapi/lib/utils/ee');
|
||||
|
||||
const enableFeatureMiddleware = (featureName) => (ctx, next) => {
|
||||
console.log(featureName, features.isEnabled(featureName));
|
||||
if (features.isEnabled(featureName)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@ -13,13 +13,13 @@ describe('Passport', () => {
|
||||
afterEach(() => {
|
||||
// Reset the mock on passport.use.toHaveBeenCalledTimes
|
||||
jest.resetAllMocks();
|
||||
// Reset the mock on strapi/lib/utils/ee so we can change its behavior
|
||||
// Reset the mock on strapi/ee so we can change its behavior
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
describe('Init (SSO disabled)', () => {
|
||||
beforeAll(() => {
|
||||
jest.mock('@strapi/strapi/lib/utils/ee', () => ({
|
||||
jest.mock('@strapi/strapi/ee', () => ({
|
||||
features: {
|
||||
// Disable the SSO feature
|
||||
isEnabled: (feature) => feature !== 'sso',
|
||||
@ -57,7 +57,7 @@ describe('Passport', () => {
|
||||
|
||||
describe('Init (SSO enabled)', () => {
|
||||
beforeAll(() => {
|
||||
jest.mock('@strapi/strapi/lib/utils/ee', () => ({
|
||||
jest.mock('@strapi/strapi/ee', () => ({
|
||||
features: {
|
||||
// Enable all the features (including SSO)
|
||||
isEnabled: () => true,
|
||||
|
||||
@ -1,21 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
jest.mock('@strapi/strapi/lib/utils/ee', () => {
|
||||
const eeModule = () => true;
|
||||
|
||||
Object.assign(eeModule, {
|
||||
features: {
|
||||
isEnabled() {
|
||||
return true;
|
||||
},
|
||||
getEnabled() {
|
||||
return ['sso'];
|
||||
},
|
||||
jest.mock('@strapi/strapi/ee', () => ({
|
||||
features: {
|
||||
isEnabled() {
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
return eeModule;
|
||||
});
|
||||
getEnabled() {
|
||||
return ['sso'];
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
const {
|
||||
syncProviderRegistryWithConfig,
|
||||
|
||||
@ -6,28 +6,6 @@ const { features } = require('@strapi/strapi/lib/utils/ee');
|
||||
const createLocalStrategy = require('../../../server/services/passport/local-strategy');
|
||||
const sso = require('./passport/sso');
|
||||
|
||||
// wrap functions with feature flag to allow execute code lazyly
|
||||
// Looking at the code wrapped we probably can just add a condition in the functions
|
||||
const wrapWithFeatureFlag = (flag, obj) => {
|
||||
const newObj = {};
|
||||
|
||||
Object.keys(obj).forEach((key) => {
|
||||
if (typeof obj[key] === 'function') {
|
||||
newObj[key] = (...args) => {
|
||||
if (!features.isEnabled(flag)) {
|
||||
throw new Error(`${key} cannot be executed`);
|
||||
}
|
||||
|
||||
return obj[key].apply(newObj, ...args);
|
||||
};
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
});
|
||||
|
||||
return newObj;
|
||||
};
|
||||
|
||||
const getPassportStrategies = () => {
|
||||
const localStrategy = createLocalStrategy(strapi);
|
||||
|
||||
@ -47,5 +25,5 @@ const getPassportStrategies = () => {
|
||||
|
||||
module.exports = {
|
||||
getPassportStrategies,
|
||||
...wrapWithFeatureFlag('sso', sso),
|
||||
...sso,
|
||||
};
|
||||
|
||||
@ -1,13 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const ee = require('@strapi/strapi/ee');
|
||||
const { authEventsMapper } = require('../../../../server/services/passport');
|
||||
const createProviderRegistry = require('./provider-registry');
|
||||
|
||||
const providerRegistry = createProviderRegistry();
|
||||
|
||||
const getStrategyCallbackURL = (providerName) => `/admin/connect/${providerName}`;
|
||||
const getStrategyCallbackURL = (providerName) => {
|
||||
if (!ee.features.isEnabled('sso')) {
|
||||
throw new Error(`Cannot be executed`);
|
||||
}
|
||||
|
||||
return `/admin/connect/${providerName}`;
|
||||
};
|
||||
|
||||
const syncProviderRegistryWithConfig = () => {
|
||||
if (!ee.features.isEnabled('sso')) {
|
||||
throw new Error(`Cannot be executed`);
|
||||
}
|
||||
|
||||
const { providers = [] } = strapi.config.get('admin.auth', {});
|
||||
|
||||
providerRegistry.registerMany(providers);
|
||||
|
||||
@ -56,7 +56,6 @@ const onlineUpdate = async ({ strapi }) => {
|
||||
const transaction = await strapi.db.transaction();
|
||||
|
||||
try {
|
||||
// TODO: Use the core store interface instead, it does not support transactions and "FOR UPDATE" at the moment
|
||||
const eeInfo = await strapi.db
|
||||
.queryBuilder(eeStoreModel.uid)
|
||||
.where({ key: 'ee_information' })
|
||||
|
||||
@ -123,7 +123,10 @@ class Strapi {
|
||||
createUpdateNotifier(this).notify();
|
||||
|
||||
Object.defineProperty(this, 'EE', {
|
||||
get: () => ee.isEE,
|
||||
get: () => {
|
||||
ee.init(this.dirs.app.root, this.log);
|
||||
return ee.isEE;
|
||||
},
|
||||
configurable: false,
|
||||
});
|
||||
}
|
||||
@ -371,8 +374,6 @@ class Strapi {
|
||||
}
|
||||
|
||||
async register() {
|
||||
ee.init(this.dirs.app.root, this.log);
|
||||
|
||||
await Promise.all([
|
||||
this.loadApp(),
|
||||
this.loadSanitizers(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user