feat: add option to disable ui warnings

This commit is contained in:
Stavros
2025-11-21 17:37:01 +02:00
parent 22a2ab3322
commit 6c90046343
11 changed files with 43 additions and 60 deletions

View File

@@ -236,6 +236,7 @@ func (app *BootstrapApp) Setup() error {
ForgotPasswordMessage: app.config.ForgotPasswordMessage,
BackgroundImage: app.config.BackgroundImage,
OAuthAutoRedirect: app.config.OAuthAutoRedirect,
DisableUIWarnings: app.config.DisableUIWarnings,
}, apiRouter)
oauthController := controller.NewOAuthController(controller.OAuthControllerConfig{

View File

@@ -41,6 +41,7 @@ type Config struct {
TrustedProxies string `mapstructure:"trusted-proxies"`
DisableAnalytics bool `mapstructure:"disable-analytics"`
DisableResources bool `mapstructure:"disable-resources"`
DisableUIWarnings bool `mapstructure:"disable-ui-warnings"`
SocketPath string `mapstructure:"socket-path"`
}

View File

@@ -32,6 +32,7 @@ type AppContextResponse struct {
ForgotPasswordMessage string `json:"forgotPasswordMessage"`
BackgroundImage string `json:"backgroundImage"`
OAuthAutoRedirect string `json:"oauthAutoRedirect"`
DisableUIWarnings bool `json:"disableUiWarnings"`
}
type Provider struct {
@@ -48,6 +49,7 @@ type ContextControllerConfig struct {
ForgotPasswordMessage string
BackgroundImage string
OAuthAutoRedirect string
DisableUIWarnings bool
}
type ContextController struct {
@@ -56,6 +58,10 @@ type ContextController struct {
}
func NewContextController(config ContextControllerConfig, router *gin.RouterGroup) *ContextController {
if config.DisableUIWarnings {
log.Warn().Msg("UI warnings are disabled. This may expose users to security risks. Proceed with caution.")
}
return &ContextController{
config: config,
router: router,
@@ -117,5 +123,6 @@ func (controller *ContextController) appContextHandler(c *gin.Context) {
ForgotPasswordMessage: controller.config.ForgotPasswordMessage,
BackgroundImage: controller.config.BackgroundImage,
OAuthAutoRedirect: controller.config.OAuthAutoRedirect,
DisableUIWarnings: controller.config.DisableUIWarnings,
})
}

View File

@@ -30,6 +30,7 @@ var controllerCfg = controller.ContextControllerConfig{
ForgotPasswordMessage: "Contact admin to reset your password.",
BackgroundImage: "/assets/bg.jpg",
OAuthAutoRedirect: "google",
DisableUIWarnings: false,
}
var userContext = config.UserContext{
@@ -75,6 +76,7 @@ func TestAppContextHandler(t *testing.T) {
ForgotPasswordMessage: controllerCfg.ForgotPasswordMessage,
BackgroundImage: controllerCfg.BackgroundImage,
OAuthAutoRedirect: controllerCfg.OAuthAutoRedirect,
DisableUIWarnings: controllerCfg.DisableUIWarnings,
}
router, recorder := setupContextController(nil)
@@ -102,6 +104,7 @@ func TestUserContextHandler(t *testing.T) {
Provider: userContext.Provider,
OAuth: userContext.OAuth,
TotpPending: userContext.TotpPending,
OAuthName: userContext.OAuthName,
}
// Test with context