From 20be1027d6583a5ee2d309eb995cf0afdb8a6671 Mon Sep 17 00:00:00 2001 From: Tiger Nie Date: Mon, 21 Sep 2020 22:17:00 +0800 Subject: [PATCH] Moved `showHidden` check box to Profile Settings. Saving the `showHidden` attribute to the backend database as a part of the user schema. Sending the attribute from the auth endpoint as a part of userInfo --- frontend/src/i18n/en.json | 4 ++-- frontend/src/views/Files.vue | 9 +-------- frontend/src/views/settings/Profile.vue | 8 ++++++-- http/auth.go | 2 ++ settings/defaults.go | 14 ++++++++------ users/users.go | 1 + 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index 9d3ced0e..7c13bf0e 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -58,8 +58,7 @@ "size": "Size", "sortByName": "Sort by name", "sortBySize": "Sort by size", - "sortByLastModified": "Sort by last modified", - "showHiddenFiles": "Show hidden files" + "sortByLastModified": "Sort by last modified" }, "help": { "click": "select file or directory", @@ -174,6 +173,7 @@ "globalRules": "This is a global set of allow and disallow rules. They apply to every user. You can define specific rules on each user's settings to override this ones.", "allowSignup": "Allow users to signup", "createUserDir": "Auto create user home dir while adding new user", + "showHidden": "Show hidden files", "insertRegex": "Insert regex expression", "insertPath": "Insert the path", "userUpdated": "User updated!", diff --git a/frontend/src/views/Files.vue b/frontend/src/views/Files.vue index 78d61210..32fd0bc9 100644 --- a/frontend/src/views/Files.vue +++ b/frontend/src/views/Files.vue @@ -10,13 +10,6 @@ {{ link.name }} - - - {{ $t('files.showHiddenFiles') }} - -
@@ -189,7 +182,7 @@ export default { return } - if (res.isDir && !this.showHidden) { + if (res.isDir && !this.user.showHidden) { res = pruneHiddenFiles(res) } diff --git a/frontend/src/views/settings/Profile.vue b/frontend/src/views/settings/Profile.vue index 32d80404..a2405b1c 100644 --- a/frontend/src/views/settings/Profile.vue +++ b/frontend/src/views/settings/Profile.vue @@ -6,6 +6,9 @@
+ +

{{ $t('settings.showHidden') }}

+

{{ $t('settings.language') }}

@@ -67,6 +70,7 @@ export default { }, created () { this.locale = this.user.locale + this.showHidden = this.user.showHidden }, methods: { ...mapMutations([ 'updateUser' ]), @@ -90,8 +94,8 @@ export default { event.preventDefault() try { - const data = { id: this.user.id, locale: this.locale } - await api.update(data, ['locale']) + const data = { id: this.user.id, locale: this.locale, showHidden: this.showHidden } + await api.update(data, ['locale', 'showHidden']) this.updateUser(data) this.$showSuccess(this.$t('settings.settingsUpdated')) } catch (e) { diff --git a/http/auth.go b/http/auth.go index 5c47fcf1..b3800d2c 100644 --- a/http/auth.go +++ b/http/auth.go @@ -26,6 +26,7 @@ type userInfo struct { Perm users.Permissions `json:"perm"` Commands []string `json:"commands"` LockPassword bool `json:"lockPassword"` + ShowHidden bool `json:"showHidden"` } type authToken struct { @@ -175,6 +176,7 @@ func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.Use Perm: user.Perm, LockPassword: user.LockPassword, Commands: user.Commands, + ShowHidden: user.ShowHidden, }, StandardClaims: jwt.StandardClaims{ IssuedAt: time.Now().Unix(), diff --git a/settings/defaults.go b/settings/defaults.go index b0829655..b5b42d77 100644 --- a/settings/defaults.go +++ b/settings/defaults.go @@ -8,12 +8,13 @@ import ( // UserDefaults is a type that holds the default values // for some fields on User. type UserDefaults struct { - Scope string `json:"scope"` - Locale string `json:"locale"` - ViewMode users.ViewMode `json:"viewMode"` - Sorting files.Sorting `json:"sorting"` - Perm users.Permissions `json:"perm"` - Commands []string `json:"commands"` + Scope string `json:"scope"` + Locale string `json:"locale"` + ViewMode users.ViewMode `json:"viewMode"` + Sorting files.Sorting `json:"sorting"` + Perm users.Permissions `json:"perm"` + Commands []string `json:"commands"` + ShowHidden bool `json:"showHidden"` } // Apply applies the default options to a user. @@ -24,4 +25,5 @@ func (d *UserDefaults) Apply(u *users.User) { u.Perm = d.Perm u.Sorting = d.Sorting u.Commands = d.Commands + u.ShowHidden = d.ShowHidden } diff --git a/users/users.go b/users/users.go index 1df0a89b..f2de56cc 100644 --- a/users/users.go +++ b/users/users.go @@ -33,6 +33,7 @@ type User struct { Sorting files.Sorting `json:"sorting"` Fs afero.Fs `json:"-" yaml:"-"` Rules []rules.Rule `json:"rules"` + ShowHidden bool `json:"showHidden"` } // GetRules implements rules.Provider.