Clean cleans up a user and verifies if all its fields are alright to be saved.
(baseScope string, followExternalSymlinks bool, fields ...string)
| 56 | // Clean cleans up a user and verifies if all its fields |
| 57 | // are alright to be saved. |
| 58 | func (u *User) Clean(baseScope string, followExternalSymlinks bool, fields ...string) error { |
| 59 | if len(fields) == 0 { |
| 60 | fields = checkableFields |
| 61 | } |
| 62 | |
| 63 | for _, field := range fields { |
| 64 | switch field { |
| 65 | case "Username": |
| 66 | if u.Username == "" { |
| 67 | return fberrors.ErrEmptyUsername |
| 68 | } |
| 69 | case "Password": |
| 70 | if u.Password == "" { |
| 71 | return fberrors.ErrEmptyPassword |
| 72 | } |
| 73 | case "ViewMode": |
| 74 | if u.ViewMode == "" { |
| 75 | u.ViewMode = ListViewMode |
| 76 | } |
| 77 | case "Commands": |
| 78 | if u.Commands == nil { |
| 79 | u.Commands = []string{} |
| 80 | } |
| 81 | case "Sorting": |
| 82 | if u.Sorting.By == "" { |
| 83 | u.Sorting.By = "name" |
| 84 | } |
| 85 | case "Rules": |
| 86 | if u.Rules == nil { |
| 87 | u.Rules = []rules.Rule{} |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if u.Fs == nil { |
| 93 | scope := u.Scope |
| 94 | scope = filepath.Join(baseScope, filepath.Join("/", scope)) |
| 95 | u.Fs = files.NewFs(afero.NewOsFs(), scope, followExternalSymlinks) |
| 96 | } |
| 97 | |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | // FullPath gets the full path for a user's relative path. |
| 102 | func (u *User) FullPath(path string) string { |