diff --git a/repl/accounts.go b/repl/accounts.go index f6478d648cee21628e069a2dc84733bc7e054658..dd756ab8c673cf7302313d5248565a9d293e0acd 100644 --- a/repl/accounts.go +++ b/repl/accounts.go @@ -10,15 +10,18 @@ import ( "git.lyda.ie/kevin/bulletin/storage" "git.lyda.ie/kevin/bulletin/this" "git.lyda.ie/kevin/bulletin/users" + "github.com/pkg/errors" ) -// ActionUser handles the `USER` command. +// ActionUser handles the USER command - it prints out help for all the +// USER subcommands. This is new to the Go version of BULLETIN. func ActionUser(cmd *dclish.Command) error { fmt.Println(cmd.Description) return nil } -// ActionUserAdd handles the `USER ADD` command. +// ActionUserAdd handles the `USER ADD` command. This is used to add a +// new user. This is new to the Go version of BULLETIN. func ActionUserAdd(cmd *dclish.Command) error { ctx := storage.Context() login := strings.ToUpper(cmd.Args[0]) @@ -46,7 +49,10 @@ func ActionUserAdd(cmd *dclish.Command) error { return nil } -// ActionUserList handles the `USER LIST` command. +// ActionUserList handles the `USER LIST` command. This lists all the +// users. For now this is limited to only the admin users. +// +// This is new to the Go version of BULLETIN. func ActionUserList(_ *dclish.Command) error { if this.User.Admin == 0 { fmt.Println("ERROR: You are not an admin.") @@ -64,7 +70,10 @@ func ActionUserList(_ *dclish.Command) error { return nil } -// ActionUserDelete handles the `USER DELETE` command. +// ActionUserDelete handles the `USER DELETE` command. This will delete +// the named user. Only the admin can use this command. +// +// This is new to the Go version of BULLETIN. func ActionUserDelete(cmd *dclish.Command) error { if this.User.Admin == 0 { fmt.Println("ERROR: You are not an admin.") @@ -109,12 +118,18 @@ func actionUserEnable(cmd *dclish.Command, disabled int64, doing string) error { return nil } -// ActionUserEnable handles the `USER ENABLE` command. +// ActionUserEnable handles the `USER ENABLE` command. This enables +// a user. Only the admin can use this command. +// +// This is new to the Go version of BULLETIN. func ActionUserEnable(cmd *dclish.Command) error { return actionUserEnable(cmd, 0, "enable") } -// ActionUserDisable handles the `USER DISABLE` command. +// ActionUserDisable handles the `USER DISABLE` command. This disables +// a user. Only the admin can use this command. +// +// This is new to the Go version of BULLETIN. func ActionUserDisable(cmd *dclish.Command) error { return actionUserEnable(cmd, 1, "disable") } @@ -126,8 +141,10 @@ func actionUserAdmin(cmd *dclish.Command, admin int64, doing string) error { } u, err := users.ValidExistingLogin(this.Q, cmd.Args[0]) if err != nil || u.Login == "" { - fmt.Println("ERROR: User not found.") - return nil + return errors.New("User not found") + } + if u.Login == this.User.Login || u.Login == "SYSTEM" { + return errors.New("Invalid user given") } if u.Admin == admin { fmt.Printf("User is already %s.\n", doing) @@ -136,19 +153,24 @@ func actionUserAdmin(cmd *dclish.Command, admin int64, doing string) error { ctx := storage.Context() err = this.Q.UpdateUserAdmin(ctx, admin, u.Login) if err != nil { - fmt.Printf("ERROR: Failed to make user %s (%s).\n", doing, err) - return nil + return errors.Errorf("Failed to make user %s (%s)", doing, err) } fmt.Printf("User is now %s.\n", doing) return nil } -// ActionUserAdmin handles the `USER ADMIN` command. +// ActionUserAdmin handles the `USER ADMIN` command. This makes the given +// user an admin. Only the admin can use this command. +// +// This is new to the Go version of BULLETIN. func ActionUserAdmin(cmd *dclish.Command) error { return actionUserAdmin(cmd, 1, "an admin") } -// ActionUserNoadmin handles the `USER NOADMIN` command. +// ActionUserNoadmin handles the `USER NOADMIN` command. This removes the +// admin bit from a given user. Only the admin can use this command. +// +// This is new to the Go version of BULLETIN. func ActionUserNoadmin(cmd *dclish.Command) error { return actionUserAdmin(cmd, 0, "not an admin") } @@ -177,17 +199,26 @@ func actionUserMod(cmd *dclish.Command, mod int64, doing string) error { return nil } -// ActionUserMod handles the `USER MOD` command. +// ActionUserMod handles the `USER MOD` command. Makes given the user a +// moderator. Only the admin can use this command. +// +// This is new to the Go version of BULLETIN. func ActionUserMod(cmd *dclish.Command) error { return actionUserMod(cmd, 1, "a moderator") } -// ActionUserNomod handles the `USER NOMOD` command. +// ActionUserNomod handles the `USER NOMOD` command. Removes the +// moderator bit from the given user. Only the admin can use this command. +// +// This is new to the Go version of BULLETIN. func ActionUserNomod(cmd *dclish.Command) error { return actionUserMod(cmd, 0, "not a moderator") } -// ActionUserName handles the `USER LIST` command. +// ActionUserName handles the `USER NAME` command. Updates the user's +// name. Only the admin can use the two argument version of this command. +// +// This is new to the Go version of BULLETIN. func ActionUserName(cmd *dclish.Command) error { if len(cmd.Args) == 2 && this.User.Admin == 0 { fmt.Println("ERROR: You are not an admin.") @@ -212,13 +243,19 @@ func ActionUserName(cmd *dclish.Command) error { return nil } -// ActionSSH handles the `SSH` command. +// ActionSSH handles the `SSH` command. This prints the help for all the +// SSH commands. These are used to manage the authorized_keys file. +// These are new to the Go version of BULLETIN. func ActionSSH(cmd *dclish.Command) error { fmt.Println(cmd.Description) return nil } -// ActionSSHAdd handles the `SSH ADD` command. +// ActionSSHAdd handles the `SSH ADD` command. This adds a given ssh key +// to the authorized_keys file for the given user. An admin can add +// a new public key for another user. +// +// This is new to the Go version of BULLETIN. func ActionSSHAdd(cmd *dclish.Command) error { if this.User.Admin == 0 && len(cmd.Args) == 1 { fmt.Println("ERROR: You are not an admin.") @@ -243,7 +280,11 @@ func ActionSSHAdd(cmd *dclish.Command) error { return nil } -// ActionSSHList handles the `SSH LIST` command. +// ActionSSHList handles the `SSH LIST` command. This lists all the +// public keys for this user. An admin can list public keys for another +// user. +// +// This is new to the Go version of BULLETIN. func ActionSSHList(cmd *dclish.Command) error { if this.User.Admin == 0 && len(cmd.Args) == 1 { fmt.Println("ERROR: You are not an admin.") @@ -267,7 +308,11 @@ func ActionSSHList(cmd *dclish.Command) error { return nil } -// ActionSSHDelete handles the `SSH DELETE` command. +// ActionSSHDelete handles the `SSH DELETE` command. Removes ssh public +// keys for a user. And admin can specify a different user to remove +// public keys for. +// +// This is new to the Go version of BULLETIN. func ActionSSHDelete(cmd *dclish.Command) error { if this.User.Admin == 0 && len(cmd.Args) == 1 { fmt.Println("ERROR: You are not an admin.") @@ -309,7 +354,12 @@ func ActionSSHDelete(cmd *dclish.Command) error { return nil } -// ActionSSHFetch handles the `SSH FETCH` command. +// ActionSSHFetch handles the `SSH FETCH` command. This command pulls +// public keys from code sites. It's the quickest way to +// add a number of keys for a user. An admin can do this +// for another user. +// +// This is new to the Go version of BULLETIN. func ActionSSHFetch(cmd *dclish.Command) error { login := this.User.Login sitename := cmd.Args[0] diff --git a/repl/folders.go b/repl/folders.go index 4f09a6f641cb0ec5d14a8348d8360bf5118f186d..3b8160ae2202c819932daf50a6b90ab0e4cdc8fe 100644 --- a/repl/folders.go +++ b/repl/folders.go @@ -14,6 +14,8 @@ import ( ) // ActionIndex handles the `INDEX` command. This lists all the folders. +// +// This originally existed as the subroutine FULL_DIR in bulletin9.for. func ActionIndex(cmd *dclish.Command) error { if cmd.Flags["/MARKED"].Set { @@ -48,6 +50,8 @@ func ActionIndex(cmd *dclish.Command) error { } // ActionCreate handles the `CREATE` command. This creates a folder. +// +// This originally existed as the subroutine CREATE_FOLDER in bulletin4.for. func ActionCreate(cmd *dclish.Command) error { // Populate options... options := storage.CreateFolderParams{} @@ -118,6 +122,7 @@ func ActionCreate(cmd *dclish.Command) error { } // ActionSelect handles the `SELECT` command. This selects a folder. +// // This is based on `SELECT_FOLDER` in bulletin5.for. func ActionSelect(cmd *dclish.Command) error { if strings.Contains(cmd.Args[0], "%") { @@ -137,6 +142,7 @@ func ActionSelect(cmd *dclish.Command) error { } // ActionModify handles the `MODIFY` command. This modifies a folder. +// // This is based on `MODIFY_FOLDER` in bulletin1.for. func ActionModify(cmd *dclish.Command) error { if this.User.Login != this.Folder.Owner && this.User.Admin == 0 { @@ -179,6 +185,8 @@ func ActionModify(cmd *dclish.Command) error { } // ActionRemove handles the `REMOVE` command. This modifies a folder. +// +// This originally existed as the subroutine REMOVE_FOLDER in bulletin5.for. func ActionRemove(cmd *dclish.Command) error { if this.User.Login != this.Folder.Owner && this.User.Admin == 0 { return errors.New("Must be folder owner or admin to delete the folder") diff --git a/repl/help.go b/repl/help.go index 16b7131c90093967c314973293e0021f6afc3ac3..d868081a7645df581101638c42b770f51e373b54 100644 --- a/repl/help.go +++ b/repl/help.go @@ -191,7 +191,10 @@ func findHelp(hmap map[string]string, args []string, fullcmd string) string { return helptext } -// ActionHelp handles the `HELP` command. +// ActionHelp handles the `HELP` command. This provides help taxt +// for each command. +// +// This originally existed as the subroutine HELP in bulletin8.for. func ActionHelp(cmd *dclish.Command) error { if len(cmd.Args) == 0 { fmt.Printf("%s\n", helpmap["HELP"]) diff --git a/repl/mail.go b/repl/mail.go index cf43205b78e6ddb84c438234bdea0d5946b0d1ba..643c80096e24bc5ac8af484086fd1e358b158eb0 100644 --- a/repl/mail.go +++ b/repl/mail.go @@ -7,16 +7,22 @@ import ( ) // ActionForward handles the `FORWARD` command. +// +// This originally existed as the subroutine MAIL in bulletin1.for. func ActionForward(_ *dclish.Command) error { return errors.New("Mail system is not yet implemented (see issue 9)") } // ActionMail handles the `MAIL` command. +// +// This originally existed as the subroutine MAIL in bulletin1.for. func ActionMail(_ *dclish.Command) error { return errors.New("Mail system is not yet implemented (see issue 9)") } // ActionRespond handles the `RESPOND` command. +// +// This originally existed as the subroutine RESPOND_MAIL in bulletin2.for. func ActionRespond(_ *dclish.Command) error { return errors.New("Mail system is not yet implemented (see issue 9)") } diff --git a/repl/messages.go b/repl/messages.go index a201afb8b5d90b399dd00631235e3480be128c3a..db9cccbcfe97f01c3acc03d7b852493c5b4104a3 100644 --- a/repl/messages.go +++ b/repl/messages.go @@ -18,6 +18,9 @@ import ( // ActionDirectory handles the `DIRECTORY` command. This lists all the // messages in the current folder. +// +// This originally existed as the subroutines DIRECTORY in bulletin0.for +// and DIRECTORY_FOLDERS in bulletin5.for. func ActionDirectory(cmd *dclish.Command) error { showExpiration := false if cmd.Flags["/EXPIRATION"].Value == "true" { @@ -55,6 +58,8 @@ func ActionDirectory(cmd *dclish.Command) error { } // ActionAdd handles the `ADD` command. This adds a message to a folder. +// +// This originally existed as the subroutine ADD in bulletin.for. func ActionAdd(cmd *dclish.Command) error { ctx := storage.Context() @@ -177,7 +182,10 @@ func ActionAdd(cmd *dclish.Command) error { return nil } -// ActionCurrent handles the `CURRENT` command. +// ActionCurrent handles the `CURRENT` command. This shows the head of +// the current message. +// +// This originally existed as... not sure. func ActionCurrent(_ *dclish.Command) error { msg, err := folders.GetMessage(this.User.Login, this.Folder.Name, this.MsgID) if err != nil { @@ -191,7 +199,10 @@ func ActionCurrent(_ *dclish.Command) error { return nil } -// ActionBack handles the `BACK` command. +// ActionBack handles the `BACK` command. Goes back and shows the previous +// message. +// +// This originally existed as... not sure. func ActionBack(_ *dclish.Command) error { msgid := folders.PrevMsgid(this.User.Login, this.Folder.Name, this.MsgID) if msgid == 0 { @@ -211,6 +222,8 @@ func ActionBack(_ *dclish.Command) error { // ActionChange handles the `CHANGE` command. This replaces or modifies // an existing message. +// +// This originally existed as... not sure. func ActionChange(cmd *dclish.Command) error { var err error isAdmin := this.User.Admin == 1 @@ -387,7 +400,10 @@ func ActionChange(cmd *dclish.Command) error { return nil } -// ActionFirst handles the `FIRST` command. +// ActionFirst handles the `FIRST` command. Prints the first message in +// a folder. +// +// This originally existed as... not sure. func ActionFirst(_ *dclish.Command) error { msgid := folders.FirstMessage(this.Folder.Name) if msgid == 0 { @@ -405,7 +421,9 @@ func ActionFirst(_ *dclish.Command) error { return nil } -// ActionLast handles the `LAST` command. +// ActionLast handles the `LAST` command. Prints the last message. +// +// This originally existed as... not sure. func ActionLast(_ *dclish.Command) error { msgid := folders.LastMessage(this.Folder.Name) if msgid == 0 { @@ -423,7 +441,9 @@ func ActionLast(_ *dclish.Command) error { return nil } -// ActionNext handles the `NEXT` command. +// ActionNext handles the `NEXT` command. Shows the next message. +// +// This originally existed as... not sure. func ActionNext(_ *dclish.Command) error { msgid := folders.NextMsgid(this.User.Login, this.Folder.Name, this.MsgID) if msgid == 0 { @@ -442,7 +462,11 @@ func ActionNext(_ *dclish.Command) error { return nil } -// ActionPrint handles the `PRINT` command. +// ActionPrint handles the `PRINT` command. This sends the message in +// a way that the terminal will redirect it to an attached printer. Not +// many (any?) terminals support it now. +// +// This originally existed as the subroutine PRINT in bulletin1.for. func ActionPrint(cmd *dclish.Command) error { all := false if cmd.Flags["/ALL"].Value == "true" { @@ -477,7 +501,10 @@ func ActionPrint(cmd *dclish.Command) error { return nil } -// ActionRead handles the `READ` command. +// ActionRead handles the `READ` command. Increment (except the first +// time it's a called in a folder) and reads the message. +// +// This originally existed as the subroutine READ_MSG in bulletin1.for. func ActionRead(cmd *dclish.Command) error { defer func() { this.ReadFirstCall = false }() msgid := this.MsgID @@ -505,7 +532,10 @@ func ActionRead(cmd *dclish.Command) error { return nil } -// ActionReply handles the `REPLY` command. +// ActionReply handles the `REPLY` command. Used to create a reply to +// a message. +// +// This originally existed as the subroutine REPLY in bulletin.for. func ActionReply(cmd *dclish.Command) error { extract := true if cmd.Flags["/EXTRACT"].Value == "false" { @@ -543,7 +573,9 @@ func ActionReply(cmd *dclish.Command) error { return nil } -// ActionSeen handles the `SEEN` command. +// ActionSeen handles the `SEEN` command. Marks messages as seen. +// +// This originally existed as... not sure. func ActionSeen(cmd *dclish.Command) error { var err error msgids := []int64{this.MsgID} @@ -560,7 +592,9 @@ func ActionSeen(cmd *dclish.Command) error { return nil } -// ActionUnseen handles the `UNSEEN` command. +// ActionUnseen handles the `UNSEEN` command. Marks messages as unseen. +// +// This originally existed as... not sure. func ActionUnseen(cmd *dclish.Command) error { var err error msgids := []int64{this.MsgID} @@ -577,7 +611,11 @@ func ActionUnseen(cmd *dclish.Command) error { return nil } -// ActionDelete handles the `DELETE` command. +// ActionDelete handles the `DELETE` command. This deletes a message. +// As of now this is permanent. It would need to be changed to support +// UNDELETE. +// +// This originally existed as the subroutine DELETE_MSG in bulletin0.for. func ActionDelete(cmd *dclish.Command) error { var err error @@ -617,7 +655,9 @@ func ActionDelete(cmd *dclish.Command) error { return nil } -// ActionMark handles the `MARK` command. +// ActionMark handles the `MARK` command. This sets a MARK on messages. +// +// This originally existed as... not sure. func ActionMark(cmd *dclish.Command) error { var err error msgids := []int64{this.MsgID} @@ -634,7 +674,10 @@ func ActionMark(cmd *dclish.Command) error { return nil } -// ActionUnmark handles the `UNMARK` command. +// ActionUnmark handles the `UNMARK` command. This removes a MARK on +// messages. +// +// This originally existed as... not sure. func ActionUnmark(cmd *dclish.Command) error { var err error msgids := []int64{this.MsgID} diff --git a/repl/misc.go b/repl/misc.go index fe91c60ae2eb7fea1695198f44979fff794d3b64..498f4d2b9687a96dabe8d8823dd9ec6b8714dca9 100644 --- a/repl/misc.go +++ b/repl/misc.go @@ -7,14 +7,14 @@ import ( "git.lyda.ie/kevin/bulletin/dclish" ) -// ActionQuit handles the `QUIT` command. +// ActionQuit handles the `QUIT` command. This exits BULLETIN. func ActionQuit(_ *dclish.Command) error { fmt.Println("QUIT") os.Exit(0) return nil } -// ActionExit handles the `EXIT` command. +// ActionExit handles the `EXIT` command. This exits BULLETIN. func ActionExit(_ *dclish.Command) error { fmt.Println("EXIT") os.Exit(0) diff --git a/repl/set.go b/repl/set.go index cda73903723bb9758e2d25ef4ba98fbe5f1adcce..581d286d9b89284136b5c9f7dcb801cfd2c95d2b 100644 --- a/repl/set.go +++ b/repl/set.go @@ -43,13 +43,16 @@ func setAlert(cmd *dclish.Command, alert int64) error { return this.Q.UpdateUserAlert(ctx, this.User.Login, folder.Name, alert) } -// ActionSet handles the `SET` command. +// ActionSet handles the `SET` command. This command has multiple +// subcommands. This just prints the help you'd see with "HELP SET". func ActionSet(cmd *dclish.Command) error { fmt.Println(cmd.Description) return nil } // ActionSetNoaccess handles the `SET ACCESS` command. +// +// This originally existed as the subroutine SET_ACCESS in bulletin5.for. func ActionSetNoaccess(cmd *dclish.Command) error { ctx := storage.Context() login := cmd.Args[0] @@ -68,6 +71,8 @@ func ActionSetNoaccess(cmd *dclish.Command) error { } // ActionSetAccess handles the `SET ACCESS` command. +// +// This originally existed as the subroutine SET_ACCESS in bulletin5.for. func ActionSetAccess(cmd *dclish.Command) error { ctx := storage.Context() optAll := cmd.Flags["/ALL"].Set