Browse Source

WIP new WebAdmin: remove some hard coded strings

so they can be localized

Signed-off-by: Nicola Murino <[email protected]>
Nicola Murino 1 year ago
parent
commit
1a0f734a9c
3 changed files with 11 additions and 19 deletions
  1. 6 18
      internal/httpd/webadmin.go
  2. 3 0
      internal/util/i18n.go
  3. 2 1
      internal/vfs/httpfs.go

+ 6 - 18
internal/httpd/webadmin.go

@@ -100,12 +100,9 @@ const (
 	templateMaintenance      = "maintenance.html"
 	templateMFA              = "mfa.html"
 	templateSetup            = "adminsetup.html"
-	pageUsersTitle           = "Users"
 	pageAdminsTitle          = "Admins"
 	pageConnectionsTitle     = "Connections"
 	pageStatusTitle          = "Status"
-	pageFoldersTitle         = "Folders"
-	pageGroupsTitle          = "Groups"
 	pageEventRulesTitle      = "Event rules"
 	pageEventActionsTitle    = "Event actions"
 	pageRolesTitle           = "Roles"
@@ -1380,18 +1377,9 @@ func getFilePatternsFromPostField(r *http.Request) []sdk.PatternsFilter {
 
 	for idx := range patternPaths {
 		p := patternPaths[idx]
-		filters := ""
-		patternType := ""
-		patternPolicy := ""
-		if len(patterns) > idx {
-			filters = strings.ReplaceAll(patterns[idx], " ", "")
-		}
-		if len(patternTypes) > idx {
-			patternType = patternTypes[idx]
-		}
-		if len(patternPolicies) > idx {
-			patternPolicy = policies[idx]
-		}
+		filters := strings.ReplaceAll(patterns[idx], " ", "")
+		patternType := patternTypes[idx]
+		patternPolicy := policies[idx]
 		if p != "" && filters != "" {
 			if patternType == "allowed" {
 				allowedPatterns[p] = append(allowedPatterns[p], strings.Split(filters, ",")...)
@@ -2998,7 +2986,7 @@ func (s *httpdServer) handleGetWebUsers(w http.ResponseWriter, r *http.Request)
 		s.renderBadRequestPage(w, r, errors.New("invalid token claims"))
 		return
 	}
-	data := s.getBasePageData(pageUsersTitle, webUsersPath, r)
+	data := s.getBasePageData(util.I18nUsersTitle, webUsersPath, r)
 	renderAdminTemplate(w, templateUsers, data)
 }
 
@@ -3487,7 +3475,7 @@ func (s *httpdServer) handleWebGetFolders(w http.ResponseWriter, r *http.Request
 	}
 
 	data := foldersPage{
-		basePage: s.getBasePageData(pageFoldersTitle, webFoldersPath, r),
+		basePage: s.getBasePageData(util.I18nFoldersTitle, webFoldersPath, r),
 		Folders:  folders,
 	}
 	renderAdminTemplate(w, templateFolders, data)
@@ -3529,7 +3517,7 @@ func getAllGroups(w http.ResponseWriter, r *http.Request) {
 func (s *httpdServer) handleWebGetGroups(w http.ResponseWriter, r *http.Request) {
 	r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
 
-	data := s.getBasePageData(pageGroupsTitle, webGroupsPath, r)
+	data := s.getBasePageData(util.I18nGroupsTitle, webGroupsPath, r)
 	renderAdminTemplate(w, templateGroups, data)
 }
 

+ 3 - 0
internal/util/i18n.go

@@ -29,6 +29,9 @@ const (
 	I18nShareAddTitle                  = "title.add_share"
 	I18nShareUpdateTitle               = "title.update_share"
 	I18nProfileTitle                   = "title.profile"
+	I18nUsersTitle                     = "title.users"
+	I18nGroupsTitle                    = "title.groups"
+	I18nFoldersTitle                   = "title.folders"
 	I18nChangePwdTitle                 = "title.change_password"
 	I18n2FATitle                       = "title.two_factor_auth"
 	I18nEditFileTitle                  = "title.edit_file"

+ 2 - 1
internal/vfs/httpfs.go

@@ -164,7 +164,8 @@ func (c *HTTPFsConfig) validate() error {
 
 // ValidateAndEncryptCredentials validates the config and encrypts credentials if they are in plain text
 func (c *HTTPFsConfig) ValidateAndEncryptCredentials(additionalData string) error {
-	if err := c.validate(); err != nil {
+	err := c.validate()
+	if err != nil {
 		var errI18n *util.I18nError
 		errValidation := util.NewValidationError(fmt.Sprintf("could not validate HTTP fs config: %v", err))
 		if errors.As(err, &errI18n) {