more updates

Former-commit-id: 70c00db16b
This commit is contained in:
Henrique Dias
2017-06-25 15:19:23 +01:00
parent a72f25701a
commit a74ad79dd6
2 changed files with 107 additions and 97 deletions

View File

@@ -37,11 +37,16 @@ type FileManager struct {
// Users is a map with the different configurations for each user.
Users map[string]*user
// TODO: event-based?
BeforeSave CommandFunc
AfterSave CommandFunc
// BeforeSave is a function that is called before saving a file.
BeforeSave Command
// AfterSave is a function that is called before saving a file.
AfterSave Command
}
// Command is a command function.
type Command func(r *http.Request, m *FileManager, u *user) error
// user contains the configuration for each user.
type user struct {
// scope is the physical path the user has access to.
@@ -91,24 +96,20 @@ type Rule struct {
Regexp *regexp.Regexp
}
type CommandFunc func(r *http.Request, c *FileManager, u *user) error
// New creates a new File Manager instance with the needed
// configuration to work.
func New(scope string) *FileManager {
m := &FileManager{
user: &user{
AllowCommands: true,
AllowEdit: true,
AllowNew: true,
Commands: []string{"git", "svn", "hg"},
Rules: []*Rule{{
Regex: true,
Allow: false,
Regexp: regexp.MustCompile("\\/\\..+"),
}},
Commands: []string{},
Rules: []*Rule{},
},
Users: map[string]*user{},
BeforeSave: func(r *http.Request, c *FileManager, u *user) error { return nil },
AfterSave: func(r *http.Request, c *FileManager, u *user) error { return nil },
BeforeSave: func(r *http.Request, m *FileManager, u *user) error { return nil },
AfterSave: func(r *http.Request, m *FileManager, u *user) error { return nil },
Assets: &assets{
Templates: rice.MustFindBox("./_assets/templates"),
CSS: rice.MustFindBox("./_assets/css"),