From 3a13902f573d28048f124be5ccec74719bfd2dc2 Mon Sep 17 00:00:00 2001
From: Kevin Lyda <kevin@lyda.ie>
Date: Sun, 25 May 2025 20:50:00 +0100
Subject: [PATCH] Update MODIFY and a few cleanups

---
 NOTES.md        |  1 +
 repl/folders.go | 19 ++++++++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/NOTES.md b/NOTES.md
index ca0a0bb..2e32542 100644
--- a/NOTES.md
+++ b/NOTES.md
@@ -36,6 +36,7 @@ Switch between MAIL and BULLETIN modes? MAIL commands are documented
     * Review sql queries and clean out the ones not used.
     * Review sql queries and find duplicates.
     * Use [dupl](https://github.com/mibk/dupl) to find things to generalise.
+      There's a `make dupl` target.
   * flag abbreviations with values don't seem to work?
 
 Polishing.  Review each command and put a + next to each as it is
diff --git a/repl/folders.go b/repl/folders.go
index 4e5fe8d..c8b7f4a 100644
--- a/repl/folders.go
+++ b/repl/folders.go
@@ -119,6 +119,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], "%") {
 		return errors.New("Folder name cannot contain a %")
@@ -133,23 +134,31 @@ func ActionSelect(cmd *dclish.Command) error {
 		fmt.Printf("Folder has been set to '%s'.\n", folder.Name)
 		return nil
 	}
-	// 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")
 }
 
 // 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 {
 		return errors.New("Must be folder owner or admin to modify the folder")
 	}
+	var err error
 	description := this.Folder.Description
 	if cmd.Flags["/DESCRIPTION"].Set {
-		description = cmd.Flags["/DESCRIPTION"].Value
+		description, err = ask.GetLine("Enter one line description of folder: ")
+		if err != nil {
+			return err
+		}
+		if len(description) > 53 {
+			return errors.New("Description must be < 53 characters")
+		}
 	}
 	owner := this.Folder.Owner
 	if cmd.Flags["/OWNER"].Set {
+		if this.User.Admin == 0 {
+			return errors.New("Must be an admin to modify the folder owner")
+		}
 		owner = cmd.Flags["/OWNER"].Value
 	}
 	name := this.Folder.Name
@@ -161,7 +170,7 @@ func ActionModify(cmd *dclish.Command) error {
 	}
 
 	ctx := storage.Context()
-	err := this.Q.UpdateFolderMain(ctx, storage.UpdateFolderMainParams{
+	err = this.Q.UpdateFolderMain(ctx, storage.UpdateFolderMainParams{
 		Description: description,
 		Owner:       owner,
 		NewName:     name,
-- 
GitLab