28 disable settings (#34)
This commit is contained in:
parent
cb37a50abc
commit
8cdb79c915
|
@ -4,7 +4,7 @@ on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- 'main'
|
- 'main'
|
||||||
- 'v\d+.\d+.\d+'
|
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -3,7 +3,7 @@ name: release
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'v\d+.\d+.\d+'
|
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
# v0.2.1
|
||||||
|
- issue #29 - Rules can now be configured and read from configuration yaml
|
||||||
|
|
||||||
# v0.2.0
|
# v0.2.0
|
||||||
|
|
||||||
- improved UI
|
- improved UI
|
||||||
- more unified coehisive look
|
- more unified coehisive look
|
||||||
- Adjusted header bar look and icon behavior
|
- Adjusted header bar look and icon behavior
|
||||||
|
|
|
@ -10,16 +10,16 @@ ok github.com/gtsteffaniak/filebrowser/diskcache 0.003s
|
||||||
? github.com/gtsteffaniak/filebrowser/files [no test files]
|
? github.com/gtsteffaniak/filebrowser/files [no test files]
|
||||||
PASS
|
PASS
|
||||||
ok github.com/gtsteffaniak/filebrowser/fileutils 0.003s
|
ok github.com/gtsteffaniak/filebrowser/fileutils 0.003s
|
||||||
2023/09/10 09:17:55 h: 401 <nil>
|
2023/09/24 12:52:05 h: 401 <nil>
|
||||||
2023/09/10 09:17:55 h: 401 <nil>
|
2023/09/24 12:52:05 h: 401 <nil>
|
||||||
2023/09/10 09:17:55 h: 401 <nil>
|
2023/09/24 12:52:05 h: 401 <nil>
|
||||||
2023/09/10 09:17:56 h: 401 <nil>
|
2023/09/24 12:52:05 h: 401 <nil>
|
||||||
2023/09/10 09:17:56 h: 401 <nil>
|
2023/09/24 12:52:05 h: 401 <nil>
|
||||||
2023/09/10 09:17:56 h: 401 <nil>
|
2023/09/24 12:52:05 h: 401 <nil>
|
||||||
PASS
|
PASS
|
||||||
ok github.com/gtsteffaniak/filebrowser/http 0.082s
|
ok github.com/gtsteffaniak/filebrowser/http 0.094s
|
||||||
PASS
|
PASS
|
||||||
ok github.com/gtsteffaniak/filebrowser/img 0.118s
|
ok github.com/gtsteffaniak/filebrowser/img 0.144s
|
||||||
PASS
|
PASS
|
||||||
ok github.com/gtsteffaniak/filebrowser/rules 0.002s
|
ok github.com/gtsteffaniak/filebrowser/rules 0.002s
|
||||||
PASS
|
PASS
|
||||||
|
@ -28,10 +28,10 @@ goos: linux
|
||||||
goarch: amd64
|
goarch: amd64
|
||||||
pkg: github.com/gtsteffaniak/filebrowser/search
|
pkg: github.com/gtsteffaniak/filebrowser/search
|
||||||
cpu: 11th Gen Intel(R) Core(TM) i5-11320H @ 3.20GHz
|
cpu: 11th Gen Intel(R) Core(TM) i5-11320H @ 3.20GHz
|
||||||
BenchmarkSearchAllIndexes-8 10 5311144 ns/op 2934075 B/op 44569 allocs/op
|
BenchmarkSearchAllIndexes-8 10 5912685 ns/op 3003976 B/op 46139 allocs/op
|
||||||
BenchmarkFillIndex-8 10 3142607 ns/op 18473 B/op 452 allocs/op
|
BenchmarkFillIndex-8 10 3157995 ns/op 18370 B/op 449 allocs/op
|
||||||
PASS
|
PASS
|
||||||
ok github.com/gtsteffaniak/filebrowser/search 0.110s
|
ok github.com/gtsteffaniak/filebrowser/search 0.116s
|
||||||
PASS
|
PASS
|
||||||
ok github.com/gtsteffaniak/filebrowser/settings 0.005s
|
ok github.com/gtsteffaniak/filebrowser/settings 0.005s
|
||||||
? github.com/gtsteffaniak/filebrowser/share [no test files]
|
? github.com/gtsteffaniak/filebrowser/share [no test files]
|
||||||
|
|
|
@ -172,7 +172,6 @@ func quickSetup(d pythonData) {
|
||||||
Password: password,
|
Password: password,
|
||||||
LockPassword: false,
|
LockPassword: false,
|
||||||
}
|
}
|
||||||
settings.GlobalConfiguration.UserDefaults.Apply(user)
|
|
||||||
user.Perm.Admin = true
|
user.Perm.Admin = true
|
||||||
err = d.store.Users.Save(user)
|
err = d.store.Users.Save(user)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
|
||||||
|
|
||||||
"github.com/gtsteffaniak/filebrowser/settings"
|
|
||||||
"github.com/gtsteffaniak/filebrowser/users"
|
"github.com/gtsteffaniak/filebrowser/users"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,76 +56,3 @@ func parseUsernameOrID(arg string) (username string, id uint) {
|
||||||
}
|
}
|
||||||
return "", uint(id64)
|
return "", uint(id64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addUserFlags(flags *pflag.FlagSet) {
|
|
||||||
flags.Bool("perm.admin", false, "admin perm for users")
|
|
||||||
flags.Bool("perm.execute", true, "execute perm for users")
|
|
||||||
flags.Bool("perm.create", true, "create perm for users")
|
|
||||||
flags.Bool("perm.rename", true, "rename perm for users")
|
|
||||||
flags.Bool("perm.modify", true, "modify perm for users")
|
|
||||||
flags.Bool("perm.delete", true, "delete perm for users")
|
|
||||||
flags.Bool("perm.share", true, "share perm for users")
|
|
||||||
flags.Bool("perm.download", true, "download perm for users")
|
|
||||||
flags.String("sorting.by", "name", "sorting mode (name, size or modified)")
|
|
||||||
flags.Bool("sorting.asc", false, "sorting by ascending order")
|
|
||||||
flags.Bool("lockPassword", false, "lock password")
|
|
||||||
flags.StringSlice("commands", nil, "a list of the commands a user can execute")
|
|
||||||
flags.String("scope", ".", "scope for users")
|
|
||||||
flags.String("locale", "en", "locale for users")
|
|
||||||
flags.String("viewMode", string(users.ListViewMode), "view mode for users")
|
|
||||||
flags.Bool("singleClick", false, "use single clicks only")
|
|
||||||
}
|
|
||||||
|
|
||||||
func getViewMode(flags *pflag.FlagSet) string {
|
|
||||||
viewMode := settings.GlobalConfiguration.UserDefaults.ViewMode
|
|
||||||
if viewMode != users.ListViewMode && viewMode != users.MosaicViewMode {
|
|
||||||
checkErr(errors.New("view mode must be \"" + string(users.ListViewMode) + "\" or \"" + string(users.MosaicViewMode) + "\""))
|
|
||||||
}
|
|
||||||
return viewMode
|
|
||||||
}
|
|
||||||
|
|
||||||
//nolint:gocyclo
|
|
||||||
func getUserDefaults(flags *pflag.FlagSet, defaults *settings.UserDefaults, all bool) {
|
|
||||||
visit := func(flag *pflag.Flag) {
|
|
||||||
switch flag.Name {
|
|
||||||
case "scope":
|
|
||||||
defaults.Scope = mustGetString(flags, flag.Name)
|
|
||||||
case "locale":
|
|
||||||
defaults.Locale = mustGetString(flags, flag.Name)
|
|
||||||
case "viewMode":
|
|
||||||
defaults.ViewMode = getViewMode(flags)
|
|
||||||
case "singleClick":
|
|
||||||
defaults.SingleClick = mustGetBool(flags, flag.Name)
|
|
||||||
case "perm.admin":
|
|
||||||
defaults.Perm.Admin = mustGetBool(flags, flag.Name)
|
|
||||||
case "perm.execute":
|
|
||||||
defaults.Perm.Execute = mustGetBool(flags, flag.Name)
|
|
||||||
case "perm.create":
|
|
||||||
defaults.Perm.Create = mustGetBool(flags, flag.Name)
|
|
||||||
case "perm.rename":
|
|
||||||
defaults.Perm.Rename = mustGetBool(flags, flag.Name)
|
|
||||||
case "perm.modify":
|
|
||||||
defaults.Perm.Modify = mustGetBool(flags, flag.Name)
|
|
||||||
case "perm.delete":
|
|
||||||
defaults.Perm.Delete = mustGetBool(flags, flag.Name)
|
|
||||||
case "perm.share":
|
|
||||||
defaults.Perm.Share = mustGetBool(flags, flag.Name)
|
|
||||||
case "perm.download":
|
|
||||||
defaults.Perm.Download = mustGetBool(flags, flag.Name)
|
|
||||||
case "commands":
|
|
||||||
commands, err := flags.GetStringSlice(flag.Name)
|
|
||||||
checkErr(err)
|
|
||||||
defaults.Commands = commands
|
|
||||||
case "sorting.by":
|
|
||||||
defaults.Sorting.By = mustGetString(flags, flag.Name)
|
|
||||||
case "sorting.asc":
|
|
||||||
defaults.Sorting.Asc = mustGetBool(flags, flag.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if all {
|
|
||||||
flags.VisitAll(visit)
|
|
||||||
} else {
|
|
||||||
flags.Visit(visit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
usersCmd.AddCommand(usersAddCmd)
|
usersCmd.AddCommand(usersAddCmd)
|
||||||
addUserFlags(usersAddCmd.Flags())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var usersAddCmd = &cobra.Command{
|
var usersAddCmd = &cobra.Command{
|
||||||
|
@ -17,9 +16,6 @@ var usersAddCmd = &cobra.Command{
|
||||||
Long: `Create a new user and add it to the database.`,
|
Long: `Create a new user and add it to the database.`,
|
||||||
Args: cobra.ExactArgs(2), //nolint:gomnd
|
Args: cobra.ExactArgs(2), //nolint:gomnd
|
||||||
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||||
s, err := d.store.Settings.Get()
|
|
||||||
checkErr(err)
|
|
||||||
|
|
||||||
password, err := users.HashPwd(args[1])
|
password, err := users.HashPwd(args[1])
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
|
@ -28,9 +24,6 @@ var usersAddCmd = &cobra.Command{
|
||||||
Password: password,
|
Password: password,
|
||||||
LockPassword: mustGetBool(cmd.Flags(), "lockPassword"),
|
LockPassword: mustGetBool(cmd.Flags(), "lockPassword"),
|
||||||
}
|
}
|
||||||
|
|
||||||
s.UserDefaults.Apply(user)
|
|
||||||
|
|
||||||
servSettings, err := d.store.Settings.GetServer()
|
servSettings, err := d.store.Settings.GetServer()
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
// since getUserDefaults() polluted s.Defaults.Scope
|
// since getUserDefaults() polluted s.Defaults.Scope
|
||||||
|
|
|
@ -8,10 +8,6 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
usersCmd.AddCommand(usersUpdateCmd)
|
usersCmd.AddCommand(usersUpdateCmd)
|
||||||
|
|
||||||
usersUpdateCmd.Flags().StringP("password", "p", "", "new password")
|
|
||||||
usersUpdateCmd.Flags().StringP("username", "u", "", "new username")
|
|
||||||
addUserFlags(usersUpdateCmd.Flags())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var usersUpdateCmd = &cobra.Command{
|
var usersUpdateCmd = &cobra.Command{
|
||||||
|
|
|
@ -4,17 +4,29 @@ server:
|
||||||
auth:
|
auth:
|
||||||
method: noauth
|
method: noauth
|
||||||
signup: true
|
signup: true
|
||||||
userDefaults:
|
|
||||||
scope: "."
|
|
||||||
hideDotfiles: true
|
|
||||||
singleClick: false
|
|
||||||
permissions:
|
|
||||||
admin: false
|
|
||||||
create: true
|
|
||||||
rename: true
|
|
||||||
modify: true
|
|
||||||
delete: true
|
|
||||||
share: true
|
|
||||||
download: true
|
|
||||||
frontend:
|
frontend:
|
||||||
theme: dark
|
theme: dark
|
||||||
|
Users:
|
||||||
|
admin:
|
||||||
|
rules:
|
||||||
|
- regex: false
|
||||||
|
allow: true
|
||||||
|
path: test
|
||||||
|
regexp:
|
||||||
|
raw: ''
|
||||||
|
- regex: true
|
||||||
|
allow: true
|
||||||
|
path: ''
|
||||||
|
regexp:
|
||||||
|
raw: test
|
||||||
|
scope: "."
|
||||||
|
hideDotfiles: true
|
||||||
|
singleClick: false
|
||||||
|
permissions:
|
||||||
|
admin: false
|
||||||
|
create: true
|
||||||
|
rename: true
|
||||||
|
modify: true
|
||||||
|
delete: true
|
||||||
|
share: true
|
||||||
|
download: true
|
|
@ -145,8 +145,6 @@ var signupHandler = func(w http.ResponseWriter, r *http.Request, d *data) (int,
|
||||||
Username: info.Username,
|
Username: info.Username,
|
||||||
}
|
}
|
||||||
|
|
||||||
d.settings.UserDefaults.Apply(user)
|
|
||||||
|
|
||||||
pwd, err := users.HashPwd(info.Password)
|
pwd, err := users.HashPwd(info.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
|
|
|
@ -34,11 +34,19 @@ func TestConfigLoadSpecificValues(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error unmarshaling YAML data: %v", err)
|
log.Fatalf("Error unmarshaling YAML data: %v", err)
|
||||||
}
|
}
|
||||||
|
testCases := []struct {
|
||||||
if GlobalConfiguration.Auth.Method == newConfig.Auth.Method {
|
fieldName string
|
||||||
log.Fatalf("Differences should have been found, but were not on Auth method")
|
globalVal interface{}
|
||||||
|
newVal interface{}
|
||||||
|
}{
|
||||||
|
{"Auth.Method", GlobalConfiguration.Auth.Method, newConfig.Auth.Method},
|
||||||
|
{"UserDefaults.HideDotfiles", GlobalConfiguration.UserDefaults.HideDotfiles, newConfig.UserDefaults.HideDotfiles},
|
||||||
|
{"Server.Database", GlobalConfiguration.Server.Database, newConfig.Server.Database},
|
||||||
}
|
}
|
||||||
if GlobalConfiguration.UserDefaults.HideDotfiles == newConfig.UserDefaults.HideDotfiles {
|
|
||||||
log.Fatalf("Differences should have been found, but were not on Auth method")
|
for _, tc := range testCases {
|
||||||
|
if tc.globalVal == tc.newVal {
|
||||||
|
t.Errorf("Differences should have been found:\n\tGlobalConfig.%s: %v \n\tSetConfig: %v \n", tc.fieldName, tc.globalVal, tc.newVal)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,6 @@ import (
|
||||||
"github.com/gtsteffaniak/filebrowser/users"
|
"github.com/gtsteffaniak/filebrowser/users"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Apply applies the default options to a user.
|
|
||||||
func (d *UserDefaults) Apply(u *users.User) {
|
|
||||||
u.Scope = d.Scope
|
|
||||||
u.Locale = d.Locale
|
|
||||||
u.ViewMode = d.ViewMode
|
|
||||||
u.SingleClick = d.SingleClick
|
|
||||||
u.Perm = d.Perm
|
|
||||||
u.Sorting = d.Sorting
|
|
||||||
u.Commands = d.Commands
|
|
||||||
u.HideDotfiles = d.HideDotfiles
|
|
||||||
u.DateFormat = d.DateFormat
|
|
||||||
}
|
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
Key []byte `json:"key"`
|
Key []byte `json:"key"`
|
||||||
Signup bool `json:"signup"`
|
Signup bool `json:"signup"`
|
||||||
|
@ -31,6 +18,7 @@ type Settings struct {
|
||||||
Server Server `json:"server"`
|
Server Server `json:"server"`
|
||||||
Auth Auth `json:"auth"`
|
Auth Auth `json:"auth"`
|
||||||
Frontend Frontend `json:"frontend"`
|
Frontend Frontend `json:"frontend"`
|
||||||
|
Users []UserDefaults `json:"users,omitempty"`
|
||||||
UserDefaults UserDefaults `json:"userDefaults"`
|
UserDefaults UserDefaults `json:"userDefaults"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,18 +68,20 @@ type Frontend struct {
|
||||||
// UserDefaults is a type that holds the default values
|
// UserDefaults is a type that holds the default values
|
||||||
// for some fields on User.
|
// for some fields on User.
|
||||||
type UserDefaults struct {
|
type UserDefaults struct {
|
||||||
LockPassword bool `json:"lockPassword"`
|
LockPassword bool `json:"lockPassword"`
|
||||||
Scope string `json:"scope"`
|
DisableSettings bool `json:"disableSettings,omitempty"`
|
||||||
Locale string `json:"locale"`
|
Scope string `json:"scope"`
|
||||||
ViewMode string `json:"viewMode"`
|
Locale string `json:"locale"`
|
||||||
SingleClick bool `json:"singleClick"`
|
ViewMode string `json:"viewMode"`
|
||||||
Sorting struct {
|
SingleClick bool `json:"singleClick"`
|
||||||
|
Rules []rules.Rule `json:"rules"`
|
||||||
|
Sorting struct {
|
||||||
By string `json:"by"`
|
By string `json:"by"`
|
||||||
Asc bool `json:"asc"`
|
Asc bool `json:"asc"`
|
||||||
} `json:"sorting"`
|
} `json:"sorting"`
|
||||||
Perm users.Permissions `json:"perm"`
|
Perm users.Permissions `json:"perm"`
|
||||||
Permissions users.Permissions `json:"permissions"`
|
Permissions users.Permissions `json:"permissions"`
|
||||||
Commands []string `json:"commands"`
|
Commands []string `json:"commands,omitemptys"`
|
||||||
HideDotfiles bool `json:"hideDotfiles"`
|
HideDotfiles bool `json:"hideDotfiles"`
|
||||||
DateFormat bool `json:"dateFormat"`
|
DateFormat bool `json:"dateFormat"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ server:
|
||||||
baseURL: "/"
|
baseURL: "/"
|
||||||
address: ""
|
address: ""
|
||||||
log: "stdout"
|
log: "stdout"
|
||||||
database: "database.db"
|
database: "mydb.db"
|
||||||
root: "/srv"
|
root: "/srv"
|
||||||
auth:
|
auth:
|
||||||
recaptcha:
|
recaptcha:
|
||||||
|
@ -47,6 +47,5 @@ userDefaults:
|
||||||
delete: true
|
delete: true
|
||||||
share: true
|
share: true
|
||||||
download: true
|
download: true
|
||||||
commands: []
|
|
||||||
hideDotfiles: false
|
hideDotfiles: false
|
||||||
dateFormat: false
|
dateFormat: false
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: 0 -.5em;
|
margin: 0 -.5em;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
body.rtl .dashboard .row {
|
body.rtl .dashboard .row {
|
||||||
|
@ -61,6 +62,7 @@ p code {
|
||||||
.dashboard #nav .wrapper {
|
.dashboard #nav .wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
|
justify-content: center;
|
||||||
border-bottom: 2px solid rgba(0, 0, 0, 0.05);
|
border-bottom: 2px solid rgba(0, 0, 0, 0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="dashboard">
|
<div class="dashboard">
|
||||||
<div id="nav">
|
<div id="nav">
|
||||||
<div class="wrapper">
|
<div v-if="disabledSettings">
|
||||||
|
nothing to see here
|
||||||
|
</div>
|
||||||
|
<div v-else class="wrapper">
|
||||||
<ul>
|
<ul>
|
||||||
<router-link to="/settings/profile"
|
<router-link to="/settings/profile"
|
||||||
><li :class="{ active: $route.path === '/settings/profile' }">
|
><li :class="{ active: $route.path === '/settings/profile' }">
|
||||||
|
@ -58,6 +61,10 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(["user", "loading","req"]),
|
...mapState(["user", "loading","req"]),
|
||||||
|
disableSettings() {
|
||||||
|
console.log(this.User)
|
||||||
|
this.User.disableSettings == "true"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue