From 3fa9286238e39b94fe1bda66ac14ffdb30f121a5 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 9 Oct 2017 08:26:05 +0100 Subject: [PATCH] ViewMode constants; default view modes Former-commit-id: d51ad4b2671c76c3a493daf93fd4fb94a76826ed [formerly 576cfa8ebe9c66c9dbc1c8f79ab8ba7fecbe8845] [formerly 0969e87e3c070763d6e58f1d09f815b772814e4d [formerly 8633e9677b40e2a29553c486f62151b20f456eaf]] Former-commit-id: 4dad4cf6bb3858122cd4d4c6a574e691788ef9ae [formerly 0b356f24a005c8886bd2165884e363f277456d8f] Former-commit-id: cadb7589dad74e9bdb47bf3664f98ac672940fe5 --- caddy/parser/parser.go | 2 +- cmd/filemanager/main.go | 2 +- filemanager.go | 12 +++++++++--- http/users.go | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/caddy/parser/parser.go b/caddy/parser/parser.go index bc42fdfa..63a3fc76 100644 --- a/caddy/parser/parser.go +++ b/caddy/parser/parser.go @@ -154,7 +154,7 @@ func Parse(c *caddy.Controller, plugin string) ([]*filemanager.FileManager, erro } u.ViewMode = c.Val() - if u.ViewMode != "mosaic" && u.ViewMode != "list" { + if u.ViewMode != filemanager.MosaicViewMode && u.ViewMode != filemanager.ListViewMode { return nil, c.ArgErr() } case "recaptcha_key": diff --git a/cmd/filemanager/main.go b/cmd/filemanager/main.go index 430d7586..de708bba 100644 --- a/cmd/filemanager/main.go +++ b/cmd/filemanager/main.go @@ -85,7 +85,7 @@ func setupViper() { viper.SetDefault("NoAuth", false) viper.SetDefault("BaseURL", "") viper.SetDefault("PrefixURL", "") - viper.SetDefault("ViewMode", "mosaic") + viper.SetDefault("ViewMode", filemanager.MosaicViewMode) viper.SetDefault("ReCaptchaKey", "") viper.SetDefault("ReCaptchaSecret", "") diff --git a/filemanager.go b/filemanager.go index b5156b69..04e04578 100644 --- a/filemanager.go +++ b/filemanager.go @@ -22,7 +22,13 @@ import ( ) // Version is the current File Manager version. -const Version = "(untracked)" +const ( + // Version is the current File Manager version. + Version = "(untracked)" + + ListViewMode = "list" + MosaicViewMode = "mosaic" +) var ( ErrExist = errors.New("the resource already exists") @@ -207,8 +213,8 @@ func (m *FileManager) Setup() error { // TODO: remove this after 1.5 for _, user := range users { - if user.ViewMode != "list" && user.ViewMode != "mosaic" { - user.ViewMode = "list" + if user.ViewMode != ListViewMode && user.ViewMode != MosaicViewMode { + user.ViewMode = ListViewMode m.Store.Users.Update(user, "ViewMode") } } diff --git a/http/users.go b/http/users.go index 9ffee669..9846217e 100644 --- a/http/users.go +++ b/http/users.go @@ -182,6 +182,7 @@ func usersPostHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (in } u.Password = pw + u.ViewMode = fm.MosaicViewMode // Saves the user to the database. err = c.Store.Users.Save(u)