Unverified Commit 3a13902f authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Update MODIFY and a few cleanups

parent 6a821397
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+14 −5
Original line number Diff line number Diff line
@@ -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,