rc(v05.03.01): branding settings with help+support URLs #190

Merged
jmiller merged 2 commits from rc/05.03.00 into main 2026-05-26 02:50:27 +00:00
3 changed files with 160 additions and 63 deletions
+58 -5
View File
@@ -32,9 +32,66 @@ func Branding(ctx *context.Context) {
ctx.Data["HasLogo"] = fileExists(filepath.Join(imgDir, "logo.png"))
ctx.Data["HasFavicon"] = fileExists(filepath.Join(imgDir, "favicon.png"))
ctx.Data["MetaDescription"] = setting.UI.Meta.Description
ctx.Data["MetaAuthor"] = setting.UI.Meta.Author
ctx.Data["HelpURL"] = setting.HelpURL
ctx.Data["SupportURL"] = setting.SupportURL
ctx.HTML(http.StatusOK, tplBranding)
}
// BrandingSettings handles the text branding form submission.
func BrandingSettings(ctx *context.Context) {
appName := ctx.FormString("app_name")
description := ctx.FormString("description")
helpURL := ctx.FormString("help_url")
supportURL := ctx.FormString("support_url")
author := ctx.FormString("author")
// Update in-memory settings
if appName != "" {
setting.AppName = appName
}
if description != "" {
setting.UI.Meta.Description = description
}
setting.HelpURL = helpURL
setting.SupportURL = supportURL
if author != "" {
setting.UI.Meta.Author = author
}
// Persist to app.ini
cfg, err := setting.NewConfigProviderFromFile(setting.CustomConf)
if err != nil {
ctx.Flash.Error("Failed to load config: " + err.Error())
ctx.Redirect(setting.AppSubURL + "/-/admin/branding")
return
}
if appName != "" {
cfg.Section("").Key("APP_NAME").SetValue(appName)
}
if description != "" {
cfg.Section("ui.meta").Key("DESCRIPTION").SetValue(description)
}
cfg.Section("").Key("HELP_URL").SetValue(helpURL)
cfg.Section("").Key("SUPPORT_URL").SetValue(supportURL)
if author != "" {
cfg.Section("ui.meta").Key("AUTHOR").SetValue(author)
}
if err := cfg.SaveTo(setting.CustomConf); err != nil {
ctx.Flash.Error("Failed to save config: " + err.Error())
log.Error("SaveTo %s: %v", setting.CustomConf, err)
} else {
ctx.Flash.Success("Branding settings saved")
log.Info("Branding settings updated: AppName=%s, Author=%s", appName, author)
}
ctx.Redirect(setting.AppSubURL + "/-/admin/branding")
}
// BrandingUpload handles branding image uploads.
func BrandingUpload(ctx *context.Context) {
imageType := ctx.FormString("type")
@@ -66,14 +123,12 @@ func BrandingUpload(ctx *context.Context) {
}
defer file.Close()
// Validate file size (max 2MB)
if header.Size > 2*1024*1024 {
ctx.Flash.Error("File too large (max 2MB)")
ctx.Redirect(setting.AppSubURL + "/-/admin/branding")
return
}
// Ensure the custom image directory exists
imgDir := brandingImageDir()
if err := os.MkdirAll(imgDir, 0o755); err != nil {
ctx.Flash.Error("Failed to create image directory")
@@ -82,7 +137,6 @@ func BrandingUpload(ctx *context.Context) {
return
}
// Write the file
destPath := filepath.Join(imgDir, filename)
dest, err := os.Create(destPath)
if err != nil {
@@ -100,11 +154,10 @@ func BrandingUpload(ctx *context.Context) {
return
}
// Also remove SVG override if present (PNG should take priority)
// Remove SVG override if present
svgPath := filepath.Join(imgDir, filename[:len(filename)-4]+".svg")
if fileExists(svgPath) {
os.Remove(svgPath)
log.Info("Removed SVG override: %s", svgPath)
}
ctx.Flash.Success("Branding image updated: " + imageType)
+1
View File
@@ -768,6 +768,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
m.Group("/branding", func() {
m.Get("", admin.Branding)
m.Post("/upload", admin.BrandingUpload)
m.Post("/settings", admin.BrandingSettings)
})
m.Group("/monitor", func() {
+101 -58
View File
@@ -4,67 +4,110 @@
{{svg "octicon-paintbrush" 16}} Branding
</h4>
<div class="ui attached segment">
<p>Upload custom branding images. Changes take effect immediately.</p>
<!-- Nav Icon -->
<div class="ui segment">
<div class="tw-flex tw-items-center tw-gap-4 tw-mb-4">
<img src="{{AssetUrlPrefix}}/img/logo-small.png?v={{ctx.CspScriptNonce}}" style="width: 48px; height: 48px; object-fit: contain;" onerror="this.src='{{AssetUrlPrefix}}/img/logo.png'">
<div>
<strong>Nav Icon</strong>
<div class="tw-text-text-light">Top-left corner, 30x30px recommended</div>
</div>
{{if .HasNavIcon}}<span class="ui green label">Custom</span>{{else}}<span class="ui grey label">Default</span>{{end}}
</div>
<form method="post" action="{{AppSubUrl}}/-/admin/branding/upload" enctype="multipart/form-data">
{{.CsrfTokenHtml}}
<input type="hidden" name="type" value="nav-icon">
<div class="tw-flex tw-gap-2">
<input type="file" name="file" accept="image/png,image/svg+xml" required>
<button type="submit" class="ui primary small button">{{svg "octicon-upload" 14}} Upload</button>
</div>
</form>
</div>
<!-- Text Branding -->
<h5>Identity</h5>
<form method="post" action="{{AppSubUrl}}/-/admin/branding/settings">
{{.CsrfTokenHtml}}
<table class="ui very basic table">
<tbody>
<tr>
<td style="width: 30%;"><strong>Application Name</strong><div class="tw-text-text-light tw-text-sm">Shown in page titles, emails, and footer</div></td>
<td><input type="text" name="app_name" value="{{AppName}}" class="tw-w-full" placeholder="MokoGitea"></td>
</tr>
<tr>
<td><strong>Description</strong><div class="tw-text-text-light tw-text-sm">Meta description for SEO and social sharing</div></td>
<td><input type="text" name="description" value="{{.MetaDescription}}" class="tw-w-full" placeholder="Self-hosted Git service"></td>
</tr>
<tr>
<td><strong>Help URL</strong><div class="tw-text-text-light tw-text-sm">Knowledge base or documentation link shown in help menus</div></td>
<td><input type="text" name="help_url" value="{{.HelpURL}}" class="tw-w-full" placeholder="https://git.mokoconsulting.tech/MokoConsulting/MokoGitea/wiki"></td>
</tr>
<tr>
<td><strong>Support URL</strong><div class="tw-text-text-light tw-text-sm">Ticket system, email, or contact page for user support requests</div></td>
<td><input type="text" name="support_url" value="{{.SupportURL}}" class="tw-w-full" placeholder="https://mokoconsulting.tech/support"></td>
</tr>
<tr>
<td><strong>Author</strong><div class="tw-text-text-light tw-text-sm">Meta author tag</div></td>
<td><input type="text" name="author" value="{{.MetaAuthor}}" class="tw-w-full" placeholder="Moko Consulting"></td>
</tr>
</tbody>
</table>
<button type="submit" class="ui primary small button tw-mt-2">{{svg "octicon-check" 14}} Save Settings</button>
</form>
<!-- Login Logo -->
<div class="ui segment">
<div class="tw-flex tw-items-center tw-gap-4 tw-mb-4">
<img src="{{AssetUrlPrefix}}/img/logo.png?v={{ctx.CspScriptNonce}}" style="max-width: 120px; max-height: 48px; object-fit: contain;">
<div>
<strong>Login Logo</strong>
<div class="tw-text-text-light">Login page and homepage, wide format recommended</div>
</div>
{{if .HasLogo}}<span class="ui green label">Custom</span>{{else}}<span class="ui grey label">Default</span>{{end}}
</div>
<form method="post" action="{{AppSubUrl}}/-/admin/branding/upload" enctype="multipart/form-data">
{{.CsrfTokenHtml}}
<input type="hidden" name="type" value="logo">
<div class="tw-flex tw-gap-2">
<input type="file" name="file" accept="image/png,image/svg+xml" required>
<button type="submit" class="ui primary small button">{{svg "octicon-upload" 14}} Upload</button>
</div>
</form>
</div>
<div class="ui divider"></div>
<!-- Favicon -->
<div class="ui segment">
<div class="tw-flex tw-items-center tw-gap-4 tw-mb-4">
<img src="{{AssetUrlPrefix}}/img/favicon.png?v={{ctx.CspScriptNonce}}" style="width: 48px; height: 48px; object-fit: contain;">
<div>
<strong>Favicon</strong>
<div class="tw-text-text-light">Browser tab icon, 256x256px recommended</div>
</div>
{{if .HasFavicon}}<span class="ui green label">Custom</span>{{else}}<span class="ui grey label">Default</span>{{end}}
</div>
<form method="post" action="{{AppSubUrl}}/-/admin/branding/upload" enctype="multipart/form-data">
{{.CsrfTokenHtml}}
<input type="hidden" name="type" value="favicon">
<div class="tw-flex tw-gap-2">
<input type="file" name="file" accept="image/png,image/svg+xml,image/x-icon" required>
<button type="submit" class="ui primary small button">{{svg "octicon-upload" 14}} Upload</button>
</div>
</form>
</div>
<!-- Image Branding -->
<h5>Images</h5>
<p class="tw-text-text-light tw-text-sm">Changes take effect immediately.</p>
<table class="ui very basic table">
<thead>
<tr>
<th style="width: 30%;">Setting</th>
<th style="width: 40%;">Upload</th>
<th style="width: 30%;">Preview</th>
</tr>
</thead>
<tbody>
<!-- Nav Icon -->
<tr>
<td>
<strong>Nav Icon</strong> {{if .HasNavIcon}}<span class="ui mini green label">Custom</span>{{else}}<span class="ui mini grey label">Default</span>{{end}}
<div class="tw-text-text-light tw-text-sm tw-mt-1">Top-left corner across all pages. Square, 30x30px.</div>
</td>
<td>
<form method="post" action="{{AppSubUrl}}/-/admin/branding/upload" enctype="multipart/form-data">
{{.CsrfTokenHtml}}
<input type="hidden" name="type" value="nav-icon">
<input type="file" name="file" accept="image/png,image/svg+xml" required class="tw-mb-2" style="max-width: 100%;">
<br><button type="submit" class="ui primary mini button">{{svg "octicon-upload" 12}} Upload</button>
</form>
</td>
<td class="tw-text-center" style="background: var(--color-secondary); border-radius: var(--border-radius);">
<img src="{{AssetUrlPrefix}}/img/logo-small.png?v={{ctx.CspScriptNonce}}" style="max-height: 48px; max-width: 48px; object-fit: contain;" onerror="this.src='{{AssetUrlPrefix}}/img/logo.png'">
</td>
</tr>
<!-- Login Logo -->
<tr>
<td>
<strong>Login Logo</strong> {{if .HasLogo}}<span class="ui mini green label">Custom</span>{{else}}<span class="ui mini grey label">Default</span>{{end}}
<div class="tw-text-text-light tw-text-sm tw-mt-1">Login page and homepage. Wide format, max 220px display.</div>
</td>
<td>
<form method="post" action="{{AppSubUrl}}/-/admin/branding/upload" enctype="multipart/form-data">
{{.CsrfTokenHtml}}
<input type="hidden" name="type" value="logo">
<input type="file" name="file" accept="image/png,image/svg+xml" required class="tw-mb-2" style="max-width: 100%;">
<br><button type="submit" class="ui primary mini button">{{svg "octicon-upload" 12}} Upload</button>
</form>
</td>
<td class="tw-text-center" style="background: var(--color-secondary); border-radius: var(--border-radius);">
<img src="{{AssetUrlPrefix}}/img/logo.png?v={{ctx.CspScriptNonce}}" style="max-height: 48px; max-width: 140px; object-fit: contain;">
</td>
</tr>
<!-- Favicon -->
<tr>
<td>
<strong>Favicon</strong> {{if .HasFavicon}}<span class="ui mini green label">Custom</span>{{else}}<span class="ui mini grey label">Default</span>{{end}}
<div class="tw-text-text-light tw-text-sm tw-mt-1">Browser tab and PWA app icon. Square, 256x256px.</div>
</td>
<td>
<form method="post" action="{{AppSubUrl}}/-/admin/branding/upload" enctype="multipart/form-data">
{{.CsrfTokenHtml}}
<input type="hidden" name="type" value="favicon">
<input type="file" name="file" accept="image/png,image/svg+xml,image/x-icon" required class="tw-mb-2" style="max-width: 100%;">
<br><button type="submit" class="ui primary mini button">{{svg "octicon-upload" 12}} Upload</button>
</form>
</td>
<td class="tw-text-center" style="background: var(--color-secondary); border-radius: var(--border-radius);">
<img src="{{AssetUrlPrefix}}/img/favicon.png?v={{ctx.CspScriptNonce}}" style="max-height: 48px; max-width: 48px; object-fit: contain;">
</td>
</tr>
</tbody>
</table>
</div>
</div>
{{template "admin/layout_footer" .}}