feat: Add demo mode with restricted user actions

This commit is contained in:
Maksim Eltyshev
2026-01-14 14:11:21 +01:00
parent 5636c2bb79
commit 1f4f439f4c
9 changed files with 19 additions and 5 deletions
+1
View File
@@ -44,6 +44,7 @@ services:
# - STORAGE_LIMIT= # - STORAGE_LIMIT=
# - ACTIVE_USER_LIMIT= # - ACTIVE_USER_LIMIT=
# - CUSTOMER_PANEL_URL= # - CUSTOMER_PANEL_URL=
# - DEMO_MODE=true
# Set to true to show more detailed authentication error messages. # Set to true to show more detailed authentication error messages.
# It should not be enabled without a rate limiter for security reasons. # It should not be enabled without a rate limiter for security reasons.
+1
View File
@@ -58,6 +58,7 @@ services:
# - STORAGE_LIMIT= # - STORAGE_LIMIT=
# - ACTIVE_USER_LIMIT= # - ACTIVE_USER_LIMIT=
# - CUSTOMER_PANEL_URL= # - CUSTOMER_PANEL_URL=
# - DEMO_MODE=true
# Set to true to show more detailed authentication error messages. # Set to true to show more detailed authentication error messages.
# It should not be enabled without a rate limiter for security reasons. # It should not be enabled without a rate limiter for security reasons.
+1
View File
@@ -35,6 +35,7 @@ SECRET_KEY=notsecretkey
# STORAGE_LIMIT= # STORAGE_LIMIT=
# ACTIVE_USER_LIMIT= # ACTIVE_USER_LIMIT=
# CUSTOMER_PANEL_URL= # CUSTOMER_PANEL_URL=
# DEMO_MODE=true
# Set to true to show more detailed authentication error messages. # Set to true to show more detailed authentication error messages.
# It should not be enabled without a rate limiter for security reasons. # It should not be enabled without a rate limiter for security reasons.
+5 -1
View File
@@ -134,7 +134,11 @@ module.exports = {
throw Errors.USER_NOT_FOUND; throw Errors.USER_NOT_FOUND;
} }
if (user.email === sails.config.custom.defaultAdminEmail || user.isSsoUser) { if (
user.email === sails.config.custom.defaultAdminEmail ||
user.isSsoUser ||
sails.config.custom.demoMode
) {
throw Errors.NOT_ENOUGH_RIGHTS; throw Errors.NOT_ENOUGH_RIGHTS;
} }
@@ -136,7 +136,11 @@ module.exports = {
throw Errors.USER_NOT_FOUND; throw Errors.USER_NOT_FOUND;
} }
if (user.email === sails.config.custom.defaultAdminEmail || user.isSsoUser) { if (
user.email === sails.config.custom.defaultAdminEmail ||
user.isSsoUser ||
sails.config.custom.demoMode
) {
throw Errors.NOT_ENOUGH_RIGHTS; throw Errors.NOT_ENOUGH_RIGHTS;
} }
@@ -132,7 +132,7 @@ module.exports = {
throw Errors.USER_NOT_FOUND; throw Errors.USER_NOT_FOUND;
} }
if (user.email === sails.config.custom.defaultAdminEmail) { if (user.email === sails.config.custom.defaultAdminEmail || sails.config.custom.demoMode) {
throw Errors.NOT_ENOUGH_RIGHTS; throw Errors.NOT_ENOUGH_RIGHTS;
} }
+1 -1
View File
@@ -244,7 +244,7 @@ module.exports = {
} }
// TODO: refactor // TODO: refactor
if (user.email === sails.config.custom.defaultAdminEmail) { if (user.email === sails.config.custom.defaultAdminEmail || sails.config.custom.demoMode) {
if (inputs.role || inputs.name) { if (inputs.role || inputs.name) {
throw Errors.NOT_ENOUGH_RIGHTS; throw Errors.NOT_ENOUGH_RIGHTS;
} }
+3 -1
View File
@@ -53,7 +53,9 @@ module.exports = {
const isDefaultAdmin = inputs.record.email === sails.config.custom.defaultAdminEmail; const isDefaultAdmin = inputs.record.email === sails.config.custom.defaultAdminEmail;
const lockedFieldNames = []; const lockedFieldNames = [];
if (isDefaultAdmin || inputs.record.isSsoUser) { if (sails.config.custom.demoMode) {
lockedFieldNames.push('email', 'password', 'role', 'name', 'username');
} else if (isDefaultAdmin || inputs.record.isSsoUser) {
lockedFieldNames.push('email', 'password', 'name'); lockedFieldNames.push('email', 'password', 'name');
if (isDefaultAdmin) { if (isDefaultAdmin) {
+1
View File
@@ -63,6 +63,7 @@ module.exports.custom = {
storageLimit: envToBytes(process.env.STORAGE_LIMIT), storageLimit: envToBytes(process.env.STORAGE_LIMIT),
activeUserLimit: envToNumber(process.env.ACTIVE_USER_LIMIT), activeUserLimit: envToNumber(process.env.ACTIVE_USER_LIMIT),
customerPanelUrl: process.env.CUSTOMER_PANEL_URL, customerPanelUrl: process.env.CUSTOMER_PANEL_URL,
demoMode: process.env.DEMO_MODE === 'true',
showDetailedAuthErrors: process.env.SHOW_DETAILED_AUTH_ERRORS === 'true', showDetailedAuthErrors: process.env.SHOW_DETAILED_AUTH_ERRORS === 'true',