Loading NOTES.md +2 −2 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ repl.commands? * this.Folder should be a storage.Folder. * Implement batch jobs * ~~Have install populate the database with some test data.~~ * reboot * expire * ~~reboot~~ * ~~expire~~ * Implement each command. * Next: folder commands - ~~CREATE~~, ~~REMOVE~~, MODIFY, ~~INDEX~~, ~~SELECT~~ * Messages: ~~ADD~~, CURRENT, ~~DIRECTORY~~, BACK, CHANGE, Loading batch/batch.go +21 −5 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ package batch import ( "context" _ "embed" "errors" "fmt" Loading @@ -26,18 +25,36 @@ var announce206 string // Reboot deletes all messages with `shutdown` set. func Reboot() int { fmt.Println("TODO: Delete messages with shutdown != 0.") ctx := storage.Context() store, err := storage.Open() ask.CheckErr(err) q := storage.New(store.DB) rows, err := q.DeleteAllShutdownMessages(ctx) ask.CheckErr(err) fmt.Printf("Removed %d shutdown messages\n", rows) return 0 } // Expire deletes all messages that have hit their expiration date. func Expire() int { fmt.Println("TODO: expire messages.") ctx := storage.Context() store, err := storage.Open() ask.CheckErr(err) q := storage.New(store.DB) rows, err := q.DeleteAllExpiredMessages(ctx) ask.CheckErr(err) fmt.Printf("Expired %d messages\n", rows) return 0 } // Install is an interactive command used to install the crontab. func Install() int { ctx := storage.Context() // Check if install has run before. touchfile := path.Join(xdg.Home, ".bulletin-installed") if _, err := os.Stat(touchfile); err == nil { Loading @@ -64,7 +81,6 @@ func Install() int { ask.CheckErr(err) // Seed data. ctx := context.TODO() ask.CheckErr(q.SeedUserSystem(ctx)) ask.CheckErr(q.SeedFolderGeneral(ctx)) ask.CheckErr(q.SeedGeneralOwner(ctx)) Loading @@ -89,7 +105,7 @@ func Install() int { crontab := &strings.Builder{} template.Must(template.New("crontab").Parse(crontabTemplate)). Execute(crontab, map[string]string{"Bulletin": bulletin}) fmt.Printf("Add this to crontab:\n\n%s\n", crontab.String()) fmt.Printf("Adding this to crontab:\n\n%s\n", crontab.String()) err = installCrontab(crontab.String()) if err != nil { panic(err) // TODO: cleanup error handling. Loading folders/folders.go +6 −7 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ package folders import ( "context" "errors" "strings" Loading Loading @@ -42,7 +41,7 @@ func CreateFolder(owner string, options storage.CreateFolderParams) error { } options.Name = strings.ToUpper(options.Name) ctx := context.TODO() ctx := storage.Context() tx, err := this.Store.Begin() if err != nil { return err Loading @@ -68,7 +67,7 @@ func CreateFolder(owner string, options storage.CreateFolderParams) error { // ListFolder provides a list of folders that this.User has access to. func ListFolder() ([]storage.ListFolderRow, error) { // TODO: need to check access. ctx := context.TODO() ctx := storage.Context() rows, err := this.Q.ListFolder(ctx) if err != nil { // TODO: process this error a bit more to give a better error message. Loading @@ -79,7 +78,7 @@ func ListFolder() ([]storage.ListFolderRow, error) { // FindFolder finds a folder based on the prefix. func FindFolder(name string) string { ctx := context.TODO() ctx := storage.Context() folder, _ := this.Q.FindFolderExact(ctx, name) if folder != "" { return folder Loading @@ -90,7 +89,7 @@ func FindFolder(name string) string { // IsFolderAccess checks if a user can access a folder. func IsFolderAccess(name, login string) bool { ctx := context.TODO() ctx := storage.Context() found, _ := this.Q.IsFolderAccess(ctx, storage.IsFolderAccessParams{ Name: name, Login: login, Loading @@ -100,7 +99,7 @@ func IsFolderAccess(name, login string) bool { // IsFolderOwner checks if a user is a folder owner. func IsFolderOwner(folder, login string) bool { ctx := context.TODO() ctx := storage.Context() found, _ := this.Q.IsFolderOwner(ctx, storage.IsFolderOwnerParams{ Folder: folder, Login: login, Loading @@ -111,7 +110,7 @@ func IsFolderOwner(folder, login string) bool { // DeleteFolder deletes a folder. func DeleteFolder(name string) error { // TODO: make sure user can delete this table. ctx := context.TODO() ctx := storage.Context() err := this.Q.DeleteFolder(ctx, name) // TODO: process this error a bit more to give a better error message. if err != nil { Loading folders/messages.go +7 −10 Original line number Diff line number Diff line package folders import ( "context" "errors" "time" Loading @@ -11,7 +10,7 @@ import ( // CreateMessage creates a new folder. func CreateMessage(author, subject, message, folder string, permanent, shutdown int, expiration *time.Time) error { ctx := context.TODO() ctx := storage.Context() if expiration == nil { days, err := this.Q.GetFolderExpire(ctx, folder) if err != nil { Loading @@ -27,7 +26,6 @@ func CreateMessage(author, subject, message, folder string, permanent, shutdown // TODO: replace _ with rows and check. err := this.Q.CreateMessage(ctx, storage.CreateMessageParams{ Folder: folder, Folder_2: folder, Author: author, Subject: subject, Message: message, Loading @@ -41,7 +39,7 @@ func CreateMessage(author, subject, message, folder string, permanent, shutdown // ReadMessage reads a message for a user. func ReadMessage(login, folder string, msgid int64) (*storage.Message, error) { ctx := context.TODO() ctx := storage.Context() msg, err := this.Q.ReadMessage(ctx, storage.ReadMessageParams{ Folder: folder, ID: msgid, Loading @@ -64,10 +62,9 @@ func ReadMessage(login, folder string, msgid int64) (*storage.Message, error) { // NextMsgid gets the next message id. func NextMsgid(login, folder string, msgid int64) int64 { ctx := context.TODO() ctx := storage.Context() newid, err := this.Q.NextMsgid(ctx, storage.NextMsgidParams{ Folder: folder, Folder_2: folder, Login: login, ID: msgid, }) Loading @@ -79,7 +76,7 @@ func NextMsgid(login, folder string, msgid int64) int64 { // ListMessages lists messages. func ListMessages(folder string) ([]storage.Message, error) { ctx := context.TODO() ctx := storage.Context() // TODO: options aren't implemented - need to set them? rows, err := this.Q.ListMessages(ctx, folder) return rows, err Loading folders/users.go +3 −4 Original line number Diff line number Diff line package folders import ( "context" "strings" "git.lyda.ie/kevin/bulletin/storage" Loading @@ -10,7 +9,7 @@ import ( // GetUser gets a user. func GetUser(login string) (*storage.User, error) { ctx := context.TODO() ctx := storage.Context() user, err := this.Q.GetUser(ctx, login) return &user, err Loading @@ -18,7 +17,7 @@ func GetUser(login string) (*storage.User, error) { // AddUser adds a user. func AddUser(user storage.User) (*storage.User, error) { ctx := context.TODO() ctx := storage.Context() newuser, err := this.Q.AddUser(ctx, storage.AddUserParams{ Login: strings.ToUpper(user.Login), Name: user.Name, Loading @@ -29,7 +28,7 @@ func AddUser(user storage.User) (*storage.User, error) { // IsUserAdmin checks if a user is an admin. func IsUserAdmin(login string) bool { ctx := context.TODO() ctx := storage.Context() found, _ := this.Q.IsUserAdmin(ctx, login) return found == 1 } Loading
NOTES.md +2 −2 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ repl.commands? * this.Folder should be a storage.Folder. * Implement batch jobs * ~~Have install populate the database with some test data.~~ * reboot * expire * ~~reboot~~ * ~~expire~~ * Implement each command. * Next: folder commands - ~~CREATE~~, ~~REMOVE~~, MODIFY, ~~INDEX~~, ~~SELECT~~ * Messages: ~~ADD~~, CURRENT, ~~DIRECTORY~~, BACK, CHANGE, Loading
batch/batch.go +21 −5 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ package batch import ( "context" _ "embed" "errors" "fmt" Loading @@ -26,18 +25,36 @@ var announce206 string // Reboot deletes all messages with `shutdown` set. func Reboot() int { fmt.Println("TODO: Delete messages with shutdown != 0.") ctx := storage.Context() store, err := storage.Open() ask.CheckErr(err) q := storage.New(store.DB) rows, err := q.DeleteAllShutdownMessages(ctx) ask.CheckErr(err) fmt.Printf("Removed %d shutdown messages\n", rows) return 0 } // Expire deletes all messages that have hit their expiration date. func Expire() int { fmt.Println("TODO: expire messages.") ctx := storage.Context() store, err := storage.Open() ask.CheckErr(err) q := storage.New(store.DB) rows, err := q.DeleteAllExpiredMessages(ctx) ask.CheckErr(err) fmt.Printf("Expired %d messages\n", rows) return 0 } // Install is an interactive command used to install the crontab. func Install() int { ctx := storage.Context() // Check if install has run before. touchfile := path.Join(xdg.Home, ".bulletin-installed") if _, err := os.Stat(touchfile); err == nil { Loading @@ -64,7 +81,6 @@ func Install() int { ask.CheckErr(err) // Seed data. ctx := context.TODO() ask.CheckErr(q.SeedUserSystem(ctx)) ask.CheckErr(q.SeedFolderGeneral(ctx)) ask.CheckErr(q.SeedGeneralOwner(ctx)) Loading @@ -89,7 +105,7 @@ func Install() int { crontab := &strings.Builder{} template.Must(template.New("crontab").Parse(crontabTemplate)). Execute(crontab, map[string]string{"Bulletin": bulletin}) fmt.Printf("Add this to crontab:\n\n%s\n", crontab.String()) fmt.Printf("Adding this to crontab:\n\n%s\n", crontab.String()) err = installCrontab(crontab.String()) if err != nil { panic(err) // TODO: cleanup error handling. Loading
folders/folders.go +6 −7 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ package folders import ( "context" "errors" "strings" Loading Loading @@ -42,7 +41,7 @@ func CreateFolder(owner string, options storage.CreateFolderParams) error { } options.Name = strings.ToUpper(options.Name) ctx := context.TODO() ctx := storage.Context() tx, err := this.Store.Begin() if err != nil { return err Loading @@ -68,7 +67,7 @@ func CreateFolder(owner string, options storage.CreateFolderParams) error { // ListFolder provides a list of folders that this.User has access to. func ListFolder() ([]storage.ListFolderRow, error) { // TODO: need to check access. ctx := context.TODO() ctx := storage.Context() rows, err := this.Q.ListFolder(ctx) if err != nil { // TODO: process this error a bit more to give a better error message. Loading @@ -79,7 +78,7 @@ func ListFolder() ([]storage.ListFolderRow, error) { // FindFolder finds a folder based on the prefix. func FindFolder(name string) string { ctx := context.TODO() ctx := storage.Context() folder, _ := this.Q.FindFolderExact(ctx, name) if folder != "" { return folder Loading @@ -90,7 +89,7 @@ func FindFolder(name string) string { // IsFolderAccess checks if a user can access a folder. func IsFolderAccess(name, login string) bool { ctx := context.TODO() ctx := storage.Context() found, _ := this.Q.IsFolderAccess(ctx, storage.IsFolderAccessParams{ Name: name, Login: login, Loading @@ -100,7 +99,7 @@ func IsFolderAccess(name, login string) bool { // IsFolderOwner checks if a user is a folder owner. func IsFolderOwner(folder, login string) bool { ctx := context.TODO() ctx := storage.Context() found, _ := this.Q.IsFolderOwner(ctx, storage.IsFolderOwnerParams{ Folder: folder, Login: login, Loading @@ -111,7 +110,7 @@ func IsFolderOwner(folder, login string) bool { // DeleteFolder deletes a folder. func DeleteFolder(name string) error { // TODO: make sure user can delete this table. ctx := context.TODO() ctx := storage.Context() err := this.Q.DeleteFolder(ctx, name) // TODO: process this error a bit more to give a better error message. if err != nil { Loading
folders/messages.go +7 −10 Original line number Diff line number Diff line package folders import ( "context" "errors" "time" Loading @@ -11,7 +10,7 @@ import ( // CreateMessage creates a new folder. func CreateMessage(author, subject, message, folder string, permanent, shutdown int, expiration *time.Time) error { ctx := context.TODO() ctx := storage.Context() if expiration == nil { days, err := this.Q.GetFolderExpire(ctx, folder) if err != nil { Loading @@ -27,7 +26,6 @@ func CreateMessage(author, subject, message, folder string, permanent, shutdown // TODO: replace _ with rows and check. err := this.Q.CreateMessage(ctx, storage.CreateMessageParams{ Folder: folder, Folder_2: folder, Author: author, Subject: subject, Message: message, Loading @@ -41,7 +39,7 @@ func CreateMessage(author, subject, message, folder string, permanent, shutdown // ReadMessage reads a message for a user. func ReadMessage(login, folder string, msgid int64) (*storage.Message, error) { ctx := context.TODO() ctx := storage.Context() msg, err := this.Q.ReadMessage(ctx, storage.ReadMessageParams{ Folder: folder, ID: msgid, Loading @@ -64,10 +62,9 @@ func ReadMessage(login, folder string, msgid int64) (*storage.Message, error) { // NextMsgid gets the next message id. func NextMsgid(login, folder string, msgid int64) int64 { ctx := context.TODO() ctx := storage.Context() newid, err := this.Q.NextMsgid(ctx, storage.NextMsgidParams{ Folder: folder, Folder_2: folder, Login: login, ID: msgid, }) Loading @@ -79,7 +76,7 @@ func NextMsgid(login, folder string, msgid int64) int64 { // ListMessages lists messages. func ListMessages(folder string) ([]storage.Message, error) { ctx := context.TODO() ctx := storage.Context() // TODO: options aren't implemented - need to set them? rows, err := this.Q.ListMessages(ctx, folder) return rows, err Loading
folders/users.go +3 −4 Original line number Diff line number Diff line package folders import ( "context" "strings" "git.lyda.ie/kevin/bulletin/storage" Loading @@ -10,7 +9,7 @@ import ( // GetUser gets a user. func GetUser(login string) (*storage.User, error) { ctx := context.TODO() ctx := storage.Context() user, err := this.Q.GetUser(ctx, login) return &user, err Loading @@ -18,7 +17,7 @@ func GetUser(login string) (*storage.User, error) { // AddUser adds a user. func AddUser(user storage.User) (*storage.User, error) { ctx := context.TODO() ctx := storage.Context() newuser, err := this.Q.AddUser(ctx, storage.AddUserParams{ Login: strings.ToUpper(user.Login), Name: user.Name, Loading @@ -29,7 +28,7 @@ func AddUser(user storage.User) (*storage.User, error) { // IsUserAdmin checks if a user is an admin. func IsUserAdmin(login string) bool { ctx := context.TODO() ctx := storage.Context() found, _ := this.Q.IsUserAdmin(ctx, login) return found == 1 }