Merge pull request 'fix: branding reset buttons + admin icons' (#192) from rc/05.03.00 into main
This commit was merged in pull request #192.
This commit is contained in:
@@ -165,6 +165,40 @@ func BrandingUpload(ctx *context.Context) {
|
||||
ctx.Redirect(setting.AppSubURL + "/-/admin/branding")
|
||||
}
|
||||
|
||||
// BrandingReset removes a custom branding image, reverting to the built-in default.
|
||||
func BrandingReset(ctx *context.Context) {
|
||||
imageType := ctx.FormString("type")
|
||||
|
||||
var filename string
|
||||
switch imageType {
|
||||
case "nav-icon":
|
||||
filename = "logo-small.png"
|
||||
case "logo":
|
||||
filename = "logo.png"
|
||||
case "favicon":
|
||||
filename = "favicon.png"
|
||||
default:
|
||||
ctx.Flash.Error("Invalid image type")
|
||||
ctx.Redirect(setting.AppSubURL + "/-/admin/branding")
|
||||
return
|
||||
}
|
||||
|
||||
path := filepath.Join(brandingImageDir(), filename)
|
||||
if fileExists(path) {
|
||||
if err := os.Remove(path); err != nil {
|
||||
ctx.Flash.Error("Failed to remove custom image")
|
||||
log.Error("Remove %s: %v", path, err)
|
||||
} else {
|
||||
ctx.Flash.Success("Reset to default: " + imageType)
|
||||
log.Info("Branding reset to default: %s", filename)
|
||||
}
|
||||
} else {
|
||||
ctx.Flash.Info("Already using default: " + imageType)
|
||||
}
|
||||
|
||||
ctx.Redirect(setting.AppSubURL + "/-/admin/branding")
|
||||
}
|
||||
|
||||
func fileExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil
|
||||
|
||||
@@ -769,6 +769,7 @@ func registerWebRoutes(m *web.Router, webAuth *AuthMiddleware) {
|
||||
m.Get("", admin.Branding)
|
||||
m.Post("/upload", admin.BrandingUpload)
|
||||
m.Post("/settings", admin.BrandingSettings)
|
||||
m.Get("/reset", admin.BrandingReset)
|
||||
})
|
||||
|
||||
m.Group("/monitor", func() {
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
<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>
|
||||
{{if .HasNavIcon}}<a href="{{AppSubUrl}}/-/admin/branding/reset?type=nav-icon" class="ui mini button tw-ml-2">{{svg "octicon-sync" 12}} Reset</a>{{end}}
|
||||
</form>
|
||||
</td>
|
||||
<td class="tw-text-center" style="background: var(--color-secondary); border-radius: var(--border-radius);">
|
||||
@@ -81,6 +82,7 @@
|
||||
<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>
|
||||
{{if .HasLogo}}<a href="{{AppSubUrl}}/-/admin/branding/reset?type=logo" class="ui mini button tw-ml-2">{{svg "octicon-sync" 12}} Reset</a>{{end}}
|
||||
</form>
|
||||
</td>
|
||||
<td class="tw-text-center" style="background: var(--color-secondary); border-radius: var(--border-radius);">
|
||||
@@ -100,6 +102,7 @@
|
||||
<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>
|
||||
{{if .HasFavicon}}<a href="{{AppSubUrl}}/-/admin/branding/reset?type=favicon" class="ui mini button tw-ml-2">{{svg "octicon-sync" 12}} Reset</a>{{end}}
|
||||
</form>
|
||||
</td>
|
||||
<td class="tw-text-center" style="background: var(--color-secondary); border-radius: var(--border-radius);">
|
||||
|
||||
Reference in New Issue
Block a user