You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
Third party permissions working
Former-commit-id: 4b764bddd794d93565dc2a0929c193869101e4e3 [formerly 613db1e61cb4b79e1b6415c1619d7fa66cf7217d] [formerly 6091413c496e4d62db130f7ec99c27fab928d84d [formerly e78e106146]]
Former-commit-id: df9abaa4e53da7d9216c702c9162203186c594c0 [formerly 5e43c76b511d3e152f5c0d1b8024a98ae6d899e1]
Former-commit-id: e10ca024c0c9429e876bf1de060849133fc19a8e
This commit is contained in:
@@ -42,12 +42,12 @@ type FileManager struct {
|
||||
// edited directly. Use SetBaseURL.
|
||||
BaseURL string
|
||||
|
||||
// The Default User needed to build the New User page.
|
||||
DefaultUser *User
|
||||
|
||||
// Users is a map with the different configurations for each user.
|
||||
Users map[string]*User
|
||||
|
||||
// A map with the runtime added permissions for a user.
|
||||
BasePermissions map[string]bool
|
||||
|
||||
// A map of events to a slice of commands.
|
||||
Commands map[string][]string
|
||||
|
||||
@@ -87,7 +87,7 @@ type User struct {
|
||||
AllowNew bool `json:"allowNew"` // Create files and folders
|
||||
AllowEdit bool `json:"allowEdit"` // Edit/rename files
|
||||
AllowCommands bool `json:"allowCommands"` // Execute commands
|
||||
Permissions map[string]bool `json:""` // Permissions added by plugins
|
||||
Permissions map[string]bool `json:"permissions"` // Permissions added by plugins
|
||||
|
||||
// Commands is the list of commands the user can execute.
|
||||
Commands []string `json:"commands"`
|
||||
@@ -132,6 +132,7 @@ var DefaultUser = User{
|
||||
AllowCommands: true,
|
||||
AllowEdit: true,
|
||||
AllowNew: true,
|
||||
Permissions: map[string]bool{},
|
||||
Commands: []string{},
|
||||
Rules: []*Rule{},
|
||||
CSS: "",
|
||||
@@ -187,17 +188,6 @@ func New(database string, base User) (*FileManager, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Tries to get the base permissions from the database.
|
||||
err = db.Get("config", "permissions", &m.BasePermissions)
|
||||
if err != nil && err == storm.ErrNotFound {
|
||||
m.BasePermissions = map[string]bool{}
|
||||
err = db.Set("config", "permissions", m.BasePermissions)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Tries to fetch the users from the database and if there are
|
||||
// any, add them to the current File Manager instance.
|
||||
var users []User
|
||||
@@ -233,6 +223,9 @@ func New(database string, base User) (*FileManager, error) {
|
||||
|
||||
// Attaches db to this File Manager instance.
|
||||
m.db = db
|
||||
base.Username = ""
|
||||
base.Password = ""
|
||||
m.DefaultUser = &base
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -295,11 +288,17 @@ func (m *FileManager) RegisterEventType(name string) error {
|
||||
// user with it default's 'value'. If the user is an admin, it will
|
||||
// be true.
|
||||
func (m *FileManager) RegisterPermission(name string, value bool) error {
|
||||
if _, ok := m.BasePermissions[name]; ok {
|
||||
if _, ok := m.DefaultUser.Permissions[name]; ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
m.DefaultUser.Permissions[name] = value
|
||||
|
||||
for _, u := range m.Users {
|
||||
if u.Permissions == nil {
|
||||
u.Permissions = map[string]bool{}
|
||||
}
|
||||
|
||||
if u.Admin {
|
||||
u.Permissions[name] = true
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user