Unverified Commit 54b02937 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Changes for accounts to users

parent a9a59a3a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ ssh `authorized_keys` should look like this:
command="/home/bulletin/bin/bulletin -u alice",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty KEY-TYPE KEY
```

Have readline store a history file for the user.  Configure at the `accounts.Open` step.
Have readline store a history file for the user.  Configure at the `users.Open` step.

Look up how godoc does references to other things.

+1 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ go 1.24.2

require (
	github.com/adrg/xdg v0.5.3
	github.com/carlmjohnson/versioninfo v0.22.5
	github.com/chzyer/readline v1.5.1
	github.com/gdamore/tcell/v2 v2.8.1
	github.com/golang-migrate/migrate/v4 v4.18.3
@@ -14,7 +15,6 @@ require (
)

require (
	github.com/carlmjohnson/versioninfo v0.22.5 // indirect
	github.com/dustin/go-humanize v1.0.1 // indirect
	github.com/gdamore/encoding v1.0.1 // indirect
	github.com/google/uuid v1.6.0 // indirect
+3 −3
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ import (
	"fmt"
	"os"

	"git.lyda.ie/kevin/bulletin/accounts"
	"git.lyda.ie/kevin/bulletin/users"
	"git.lyda.ie/kevin/bulletin/batch"
	"git.lyda.ie/kevin/bulletin/repl"

@@ -46,7 +46,7 @@ func main() {
					fmt.Println("ERROR: can only run batch commands as SYSTEM.")
					os.Exit(1)
				}
				err := accounts.Open(user, cmd.String("name"))
				err := users.Open(user, cmd.String("name"))
				if err != nil {
					fmt.Printf("ERROR: %s.", err)
					os.Exit(1)
@@ -66,7 +66,7 @@ func main() {
				os.Exit(exitcode)
			}

			err := accounts.Open(user, cmd.String("name"))
			err := users.Open(user, cmd.String("name"))
			if err != nil {
				return err
			}
+9 −9
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ import (
	"strconv"
	"strings"

	"git.lyda.ie/kevin/bulletin/accounts"
	"git.lyda.ie/kevin/bulletin/users"
	"git.lyda.ie/kevin/bulletin/dclish"
	"git.lyda.ie/kevin/bulletin/folders"
)
@@ -15,7 +15,7 @@ import (
// ActionIndex handles the `INDEX` command.  This lists all the folders.
func ActionIndex(_ *dclish.Command) error {
	options := folders.FolderListOptions{}
	rows, err := accounts.User.Folders.ListFolder(accounts.User.Login, options)
	rows, err := users.User.Folders.ListFolder(users.User.Login, options)
	if err != nil {
		return err
	}
@@ -46,7 +46,7 @@ func ActionCreate(cmd *dclish.Command) error {
	if cmd.Flags["/OWNER"].Value != "" {
		options.Owner = cmd.Flags["/OWNER"].Value
	} else {
		options.Owner = accounts.User.Login
		options.Owner = users.User.Login
	}
	if cmd.Flags["/READNEW"].Value == "true" {
		options.Readnew = 1
@@ -78,7 +78,7 @@ func ActionCreate(cmd *dclish.Command) error {
	// Verify options...
	if options.Description == "" {
		var err error
		options.Description, err = accounts.GetLine("Enter one line description of folder: ")
		options.Description, err = users.GetLine("Enter one line description of folder: ")
		if err != nil {
			return nil
		}
@@ -86,7 +86,7 @@ func ActionCreate(cmd *dclish.Command) error {
	if options.Description == "" || len(options.Description) > 53 {
		return errors.New("Description must exist and be under 53 characters")
	}
	err := accounts.User.Folders.CreateFolder(cmd.Args[0], options)
	err := users.User.Folders.CreateFolder(cmd.Args[0], options)
	// TODO: handle the /ID flag.
	return err
}
@@ -96,12 +96,12 @@ func ActionSelect(cmd *dclish.Command) error {
	if strings.Contains(cmd.Args[0], "%") {
		return errors.New("Folder name cannot contain a %")
	}
	folder := accounts.User.Folders.FindFolder(cmd.Args[0])
	folder := users.User.Folders.FindFolder(cmd.Args[0])
	if folder == "" {
		return errors.New("Unable to select the folder")
	}
	if accounts.User.Folders.IsFolderAccess(folder, accounts.User.Login) {
		accounts.User.CurrentFolder = folder
	if users.User.Folders.IsFolderAccess(folder, users.User.Login) {
		users.User.CurrentFolder = folder
		fmt.Printf("Folder has been set to '%s'.\n", folder)
		return nil
	}
@@ -119,7 +119,7 @@ func ActionModify(cmd *dclish.Command) error {

// ActionRemove handles the `REMOVE` command.  This modifies a folder.
func ActionRemove(cmd *dclish.Command) error {
	err := accounts.User.Folders.DeleteFolder(cmd.Args[0])
	err := users.User.Folders.DeleteFolder(cmd.Args[0])
	if err == nil {
		fmt.Println("Folder removed.")
	}
+14 −14
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import (
	"strings"
	"time"

	"git.lyda.ie/kevin/bulletin/accounts"
	"git.lyda.ie/kevin/bulletin/users"
	"git.lyda.ie/kevin/bulletin/dclish"
	"git.lyda.ie/kevin/bulletin/editor"
)
@@ -21,20 +21,20 @@ func ActionDirectory(cmd *dclish.Command) error {
		if strings.Contains(cmd.Args[0], "%") {
			return errors.New("Folder name cannot contain a %")
		}
		folder := accounts.User.Folders.FindFolder(cmd.Args[0])
		folder := users.User.Folders.FindFolder(cmd.Args[0])
		if folder == "" {
			return errors.New("Unable to select the folder")
		}
		if !accounts.User.Folders.IsFolderAccess(folder, accounts.User.Login) {
		if !users.User.Folders.IsFolderAccess(folder, users.User.Login) {
			// TODO: Should be:
			//       WRITE(6,'('' You are not allowed to access folder.'')')
			//       WRITE(6,'('' See '',A,'' if you wish to access folder.'')')
			return errors.New("Unable to select the folder")
		}
		accounts.User.CurrentFolder = folder
		users.User.CurrentFolder = folder
	}
	msgs, err := accounts.User.Folders.ListMessages(
		accounts.User.CurrentFolder, nil)
	msgs, err := users.User.Folders.ListMessages(
		users.User.CurrentFolder, nil)
	if err != nil {
		return err
	}
@@ -129,11 +129,11 @@ func ActionAdd(cmd *dclish.Command) error {
	fmt.Printf("TODO: optSystem is not yet implemented - you set it to %d\n", optSystem)

	if len(optFolder) == 0 {
		optFolder = []string{accounts.User.CurrentFolder}
		optFolder = []string{users.User.CurrentFolder}
	}
	// TODO: check if folders exist.
	if optSubject == "" {
		optSubject, _ = accounts.GetLine("Enter subject of message: ")
		optSubject, _ = users.GetLine("Enter subject of message: ")
		if optSubject == "" {
			return errors.New("Must enter a subject")
		}
@@ -145,7 +145,7 @@ func ActionAdd(cmd *dclish.Command) error {
		return err
	}
	for i := range optFolder {
		err = accounts.User.Folders.CreateMessage(accounts.User.Login, optSubject, message,
		err = users.User.Folders.CreateMessage(users.User.Login, optSubject, message,
			optFolder[i], optPermanent, optShutdown, optExpiration)
	}
	return nil
@@ -183,8 +183,8 @@ func ActionNext(cmd *dclish.Command) error {

// ActionRead handles the `READ` command.
func ActionRead(cmd *dclish.Command) error {
	// TODO: We need to set accounts.User.CurrentMessage when we change folder.
	msgid := accounts.User.CurrentMessage
	// TODO: We need to set users.User.CurrentMessage when we change folder.
	msgid := users.User.CurrentMessage
	if len(cmd.Args) == 1 {
		var err error
		msgid, err = strconv.Atoi(cmd.Args[0])
@@ -192,12 +192,12 @@ func ActionRead(cmd *dclish.Command) error {
			return err
		}
	}
	msg, err := accounts.User.Folders.ReadMessage(
		accounts.User.Login, accounts.User.CurrentFolder, msgid)
	msg, err := users.User.Folders.ReadMessage(
		users.User.Login, users.User.CurrentFolder, msgid)
	if err != nil {
		return err
	}
	// TODO: update accounts.User.CurrentMessage
	// TODO: update users.User.CurrentMessage
	fmt.Printf("%s\n", msg)
	return nil
}
Loading