Files
MokoGitea/modules/setting/config_option_instance.go
T
Jonathan Miller 1d1482a3dc
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 2s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || 'development' }}) (pull_request) Successful in 1m6s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
feat(admin): configurable default landing page from site administration
Add a dynamic config option to set the default landing page for
unauthenticated visitors from Site Administration > Settings. Options:
- Home (default explore page)
- Explore (repository explore)
- Organizations (org explore)
- Login (redirect to login)
- Custom path (any internal URL like /MokoConsulting)

The setting takes effect immediately without restart, using the same
dynamic config system as maintenance mode and web banner. Falls back
to the static LANDING_PAGE setting from app.ini if not configured.

Closes #240

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-30 12:17:40 -05:00

87 lines
2.0 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package setting
import (
"time"
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/setting/config"
)
// WebBannerType fields are directly used in templates,
// do remember to update the template if you change the fields
type WebBannerType struct {
DisplayEnabled bool
ContentMessage string
StartTimeUnix int64
EndTimeUnix int64
}
func (b WebBannerType) ShouldDisplay() bool {
if !b.DisplayEnabled || b.ContentMessage == "" {
return false
}
now := time.Now().Unix()
if b.StartTimeUnix > 0 && now < b.StartTimeUnix {
return false
}
if b.EndTimeUnix > 0 && now > b.EndTimeUnix {
return false
}
return true
}
type MaintenanceModeType struct {
AdminWebAccessOnly bool
StartTimeUnix int64
EndTimeUnix int64
}
func (m MaintenanceModeType) IsActive() bool {
if !m.AdminWebAccessOnly {
return false
}
now := time.Now().Unix()
if m.StartTimeUnix > 0 && now < m.StartTimeUnix {
return false
}
if m.EndTimeUnix > 0 && now > m.EndTimeUnix {
return false
}
return true
}
// LandingPageType configures the default page for unauthenticated visitors.
// Mode values: "home", "explore", "organizations", "login", or "custom".
// When Mode is "custom", CustomPath holds the redirect target (e.g. "/MokoConsulting").
type LandingPageType struct {
Mode string // home, explore, organizations, login, custom
CustomPath string // only used when Mode == "custom"
}
// URL returns the redirect path for the configured landing page.
func (lp LandingPageType) URL() string {
switch lp.Mode {
case "explore":
return "/explore"
case "organizations":
return "/explore/organizations"
case "login":
return "/user/login"
case "custom":
if lp.CustomPath != "" {
return lp.CustomPath
}
return "/"
default:
return "/"
}
}
type InstanceStruct struct {
WebBanner *config.Option[WebBannerType]
MaintenanceMode *config.Option[MaintenanceModeType]
LandingPage *config.Option[LandingPageType]
}