Skip to content

Commit

Permalink
WebUI: allow absolute URLs for disclaimers
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Murino <[email protected]>
  • Loading branch information
drakkan committed Dec 28, 2023
1 parent 3121c35 commit 259566f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/full-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ The configuration file contains the following sections:
- `logo_path`, string. Path to your logo relative to `static_files_path`. The preferred image size is 256x256 pixel
- `login_image_path`, string. Path to a custom image to show on the login screen relative to `static_files_path`. The preferred image size is 900x900 pixel
- `disclaimer_name`, string. Name for your optional disclaimer
- `disclaimer_path`, string. Path to the HTML page with the disclaimer relative to `static_files_path`
- `disclaimer_path`, string. Path to the HTML page with the disclaimer relative to `static_files_path` or an absolute URL (http or https).
- `default_css`, list of strings. Optional path to custom CSS files, relative to `static_files_path`, which replaces the default CSS
- `extra_css`, list of strings. Defines the paths, relative to `static_files_path`, to additional CSS files
- `templates_path`, string. Path to the HTML web templates. This can be an absolute path or a path relative to the config dir
Expand Down
9 changes: 7 additions & 2 deletions internal/httpd/httpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ type UIBranding struct {
FaviconPath string `json:"favicon_path" mapstructure:"favicon_path"`
// DisclaimerName defines the name for the link to your optional disclaimer
DisclaimerName string `json:"disclaimer_name" mapstructure:"disclaimer_name"`
// Path to the HTML page for your disclaimer relative to "static_files_path".
// Path to the HTML page for your disclaimer relative to "static_files_path"
// or an absolute http/https URL.
DisclaimerPath string `json:"disclaimer_path" mapstructure:"disclaimer_path"`
// Path to custom CSS files, relative to "static_files_path", which replaces
// the default CSS files
Expand All @@ -431,7 +432,9 @@ func (b *UIBranding) check(isWebClient bool) {
b.FaviconPath = "/favicon.ico"
}
if b.DisclaimerPath != "" {
b.DisclaimerPath = util.CleanPath(b.DisclaimerPath)
if !strings.HasPrefix(b.DisclaimerPath, "https://") && !strings.HasPrefix(b.DisclaimerPath, "http://") {
b.DisclaimerPath = path.Join(webStaticFilesPath, util.CleanPath(b.DisclaimerPath))
}
}
if len(b.DefaultCSS) > 0 {
for idx := range b.DefaultCSS {
Expand Down Expand Up @@ -1111,6 +1114,8 @@ func updateWebClientURLs(baseURL string) {
webClientViewPDFPath = path.Join(baseURL, webClientViewPDFPathDefault)
webClientGetPDFPath = path.Join(baseURL, webClientGetPDFPathDefault)
webClientExistPath = path.Join(baseURL, webClientExistPathDefault)
webStaticFilesPath = path.Join(baseURL, webStaticFilesPathDefault)
webOpenAPIPath = path.Join(baseURL, webOpenAPIPathDefault)
}

func updateWebAdminURLs(baseURL string) {
Expand Down
5 changes: 4 additions & 1 deletion internal/httpd/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,14 @@ func TestBrandingValidation(t *testing.T) {
assert.Equal(t, []string{"/my.css"}, b.Branding.WebAdmin.DefaultCSS)
assert.Len(t, b.Branding.WebAdmin.ExtraCSS, 0)
assert.Equal(t, "/favicon1.ico", b.Branding.WebClient.FaviconPath)
assert.Equal(t, "/path2", b.Branding.WebClient.DisclaimerPath)
assert.Equal(t, path.Join(webStaticFilesPath, "/path2"), b.Branding.WebClient.DisclaimerPath)
assert.Equal(t, "/img/login_image.png", b.Branding.WebClient.LoginImagePath)
if assert.Len(t, b.Branding.WebClient.ExtraCSS, 1) {
assert.Equal(t, "/1.css", b.Branding.WebClient.ExtraCSS[0])
}
b.Branding.WebAdmin.DisclaimerPath = "https://example.com"
b.checkBranding()
assert.Equal(t, "https://example.com", b.Branding.WebAdmin.DisclaimerPath)
}

func TestRedactedConf(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion static/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"disk": "Disk quota",
"size": "Size: {{- val}}",
"size_percentage": "Size: {{- val}} ({{percentage}}%)",
"files": "Files: {{- num}}",
"files": "Files: {{- val}}",
"files_percentage": "Files: {{- val}} ({{percentage}}%)",
"transfer": "Transfer quota",
"total": "Total: {{- val}}",
Expand Down
2 changes: 1 addition & 1 deletion templates/webadmin/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h1 class="h4 text-gray-900 mb-4">{{.Branding.ShortName}}</h1>
{{if and .Branding.DisclaimerName .Branding.DisclaimerPath}}
<hr>
<div class="text-center">
<a class="small" href="{{.StaticURL}}{{.Branding.DisclaimerPath}}" target="_blank">{{.Branding.DisclaimerName}}</a>
<a class="small" href="{{.Branding.DisclaimerPath}}" target="_blank">{{.Branding.DisclaimerName}}</a>
</div>
{{end}}
{{end}}
2 changes: 1 addition & 1 deletion templates/webclient/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ <h3 class="card-title"><span data-i18n="fs.quota_usage.title" class="text-gray-7
{{- if $files}}
{{- $percentage := .QuotaUsage.GetQuotaFilesPercentage}}
<div class="{{if .QuotaUsage.IsQuotaFilesLow}}text-warning{{else}}text-gray-700{{end}} fw-semibold fs-6">
<span {{if gt $percentage 0}}data-i18n="fs.quota_usage.files_percentage" data-i18n-options='{ "val": "{{$files}}", "percentage": {{$percentage}} }'{{else}}data-i18n="fs.quota_usage.files" data-i18n-options='{ "num": "{{$files}}" }'{{end}}></span>
<span {{if gt $percentage 0}}data-i18n="fs.quota_usage.files_percentage" data-i18n-options='{ "val": "{{$files}}", "percentage": {{$percentage}} }'{{else}}data-i18n="fs.quota_usage.files" data-i18n-options='{ "val": "{{$files}}" }'{{end}}></span>
</div>
{{- end}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/webclient/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h1 class="text-gray-900 mb-3 ms-3">
</a>
{{- end}}
{{- if and .Branding.DisclaimerName .Branding.DisclaimerPath}}
<a href="{{.StaticURL}}{{.Branding.DisclaimerPath}}" target="_blank" class="px-2">
<a href="{{.Branding.DisclaimerPath}}" target="_blank" class="px-2">
<span data-i18n="custom.disclaimer_webclient">{{.Branding.DisclaimerName}}</span>
</a>
{{- end}}
Expand Down

0 comments on commit 259566f

Please sign in to comment.