Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/admin-test-utils/lib/setup/strapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ global.strapi = {
isEE: false,
features: {
SSO: 'sso',
allFeatures: [],
isEnabled: () => false,
},
projectType: 'Community',
Expand Down
7 changes: 3 additions & 4 deletions packages/core/admin/admin/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ReactDOM from 'react-dom';
import appCustomisations from './app';
import { Components, Fields, Middlewares, Reducers } from './core/apis';
import { axiosInstance } from './core/utils';
import appCustomisations from './app';
// eslint-disable-next-line import/extensions
import plugins from './plugins';
import appReducers from './reducers';
Expand All @@ -12,7 +12,7 @@ window.strapi = {
telemetryDisabled: process.env.STRAPI_TELEMETRY_DISABLED ?? false,
features: {
SSO: 'sso',
auditLogs: 'audit-logs',
AUDIT_LOGS: 'audit-logs',
},
projectType: 'Community',
};
Expand All @@ -39,8 +39,7 @@ const run = async () => {
window.strapi.isEE = isEE;
window.strapi.features = {
...window.strapi.features,
allFeatures: features,
isEnabled: (f) => features.includes(f),
isEnabled: (featureName) => features.some((feature) => feature.name === featureName),
};

window.strapi.projectType = isEE ? 'Enterprise' : 'Community';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import adminPermissions from '../../../../../admin/src/permissions';

const auditLogsRoutes = strapi.features.isEnabled(strapi.features.auditLogs)
const auditLogsRoutes = strapi.features.isEnabled(strapi.features.AUDIT_LOGS)
? [
{
intlLabel: { id: 'global.auditLogs', defaultMessage: 'Audit Logs' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (strapi.features.isEnabled(strapi.features.SSO)) {
});
}

if (strapi.features.isEnabled(strapi.features.auditLogs)) {
if (strapi.features.isEnabled(strapi.features.AUDIT_LOGS)) {
routes.push({
async Component() {
const component = await import(
Expand Down
2 changes: 2 additions & 0 deletions packages/core/admin/ee/server/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ module.exports = async () => {
await actionProvider.registerMany(actions.auditLogs);
}

// TODO: check admin seats

await executeCEBootstrap();
};
80 changes: 0 additions & 80 deletions packages/core/admin/ee/server/routes/features-routes.js

This file was deleted.

104 changes: 94 additions & 10 deletions packages/core/admin/ee/server/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
'use strict';

// eslint-disable-next-line node/no-extraneous-require
const { features } = require('@strapi/strapi/lib/utils/ee');
const featuresRoutes = require('./features-routes');

const getFeaturesRoutes = () => {
return Object.entries(featuresRoutes).flatMap(([featureName, featureRoutes]) => {
if (features.isEnabled(featureName)) {
return featureRoutes;
}
const enableFeatureMiddleware = (featureName) => (ctx, next) => {
if (features.isEnabled(featureName)) {
return next();
}

return [];
});
ctx.status = 404;
};

module.exports = [
Expand Down Expand Up @@ -63,5 +59,93 @@ module.exports = [
],
},
},
...getFeaturesRoutes(),

// SSO
{
method: 'GET',
path: '/providers',
handler: 'authentication.getProviders',
config: {
middlewares: [enableFeatureMiddleware('sso')],
auth: false,
},
},
{
method: 'GET',
path: '/connect/:provider',
handler: 'authentication.providerLogin',
config: {
middlewares: [enableFeatureMiddleware('sso')],
auth: false,
},
},
{
method: 'POST',
path: '/connect/:provider',
handler: 'authentication.providerLogin',
config: {
middlewares: [enableFeatureMiddleware('sso')],
auth: false,
},
},
{
method: 'GET',
path: '/providers/options',
handler: 'authentication.getProviderLoginOptions',
config: {
middlewares: [enableFeatureMiddleware('sso')],
policies: [
'admin::isAuthenticatedAdmin',
{ name: 'admin::hasPermissions', config: { actions: ['admin::provider-login.read'] } },
],
},
},
{
method: 'PUT',
path: '/providers/options',
handler: 'authentication.updateProviderLoginOptions',
config: {
middlewares: [enableFeatureMiddleware('sso')],
policies: [
'admin::isAuthenticatedAdmin',
{ name: 'admin::hasPermissions', config: { actions: ['admin::provider-login.update'] } },
],
},
},

// Audit logs
{
method: 'GET',
path: '/audit-logs',
handler: 'auditLogs.findMany',
config: {
middlewares: [enableFeatureMiddleware('audit-logs')],
policies: [
'admin::isAuthenticatedAdmin',
{
name: 'admin::hasPermissions',
config: {
actions: ['admin::audit-logs.read'],
},
},
],
},
},
{
method: 'GET',
path: '/audit-logs/:id',
handler: 'auditLogs.findOne',
config: {
middlewares: [enableFeatureMiddleware('audit-logs')],
policies: [
'admin::isAuthenticatedAdmin',
{
name: 'admin::hasPermissions',
config: {
actions: ['admin::audit-logs.read'],
},
},
],
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe('Audit logs service', () => {
features: {
// We only enabled audit logs
isEnabled: (feature) => feature === 'audit-logs',
get: () => ({ name: 'audit-logs', options: { retentionDays: 90 } }),
},
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 9 additions & 15 deletions packages/core/admin/ee/server/services/__tests__/sso.test.js
Original file line number Diff line number Diff line change
@@ -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;
});
list() {
return [{ name: 'sso' }];
},
},
}));

const {
syncProviderRegistryWithConfig,
Expand Down
7 changes: 5 additions & 2 deletions packages/core/admin/ee/server/services/audit-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

const localProvider = require('@strapi/provider-audit-logs-local');
const { scheduleJob } = require('node-schedule');
const { features } = require('@strapi/strapi/lib/utils/ee');

const RETENTION_DAYS = 90;
const DEFAULT_RETENTION_DAYS = 90;

const defaultEvents = [
'entry.create',
Expand Down Expand Up @@ -88,10 +89,12 @@ const createAuditLogsService = (strapi) => {

return {
async register() {
const retentionDays =
features.get('audit-logs')?.options.retentionDays ?? DEFAULT_RETENTION_DAYS;
this._provider = await localProvider.register({ strapi });
this._eventHubUnsubscribe = strapi.eventHub.subscribe(handleEvent.bind(this));
this._deleteExpiredJob = scheduleJob('0 0 * * *', () => {
const expirationDate = new Date(Date.now() - RETENTION_DAYS * 24 * 60 * 60 * 1000);
const expirationDate = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000);
this._provider.deleteExpiredEvents(expirationDate);
});

Expand Down
5 changes: 1 addition & 4 deletions packages/core/admin/ee/server/services/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ const getPassportStrategies = () => {

module.exports = {
getPassportStrategies,
...sso,
};

if (features.isEnabled('sso')) {
Object.assign(module.exports, sso);
}
14 changes: 13 additions & 1 deletion packages/core/admin/ee/server/services/passport/sso.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
'use strict';

const ee = require('@strapi/strapi/ee');
const { authEventsMapper } = require('../../../../server/services/passport');
const createProviderRegistry = require('./provider-registry');

const providerRegistry = createProviderRegistry();
const errorMessage = 'SSO is disabled. Its functionnalities cannot be accessed.';

const getStrategyCallbackURL = (providerName) => `/admin/connect/${providerName}`;
const getStrategyCallbackURL = (providerName) => {
if (!ee.features.isEnabled('sso')) {
throw new Error(errorMessage);
}

return `/admin/connect/${providerName}`;
};

const syncProviderRegistryWithConfig = () => {
if (!ee.features.isEnabled('sso')) {
throw new Error(errorMessage);
}

const { providers = [] } = strapi.config.get('admin.auth', {});

providerRegistry.registerMany(providers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('@strapi/strapi/lib/utils/ee', () => {
isEnabled() {
return false;
},
getEnabled() {
list() {
return [];
},
},
Expand Down
Loading