Loading dclish/dclish.go +5 −3 Original line number Diff line number Diff line Loading @@ -14,7 +14,8 @@ type ActionFunc func(*Command) error // a given command. type CompleterFunc func() []string // Flag is a flag for a command. // Flag is a flag for a command. In the future setting a type would make // things a little easier. type Flag struct { OptArg bool Value string Loading @@ -26,7 +27,9 @@ type Flag struct { // Flags is the list of flags. type Flags map[string]*Flag // Command contains the definition of a command, it's flags and subcommands. // Command contains the definition of a command, its flags, subcommands // and a completer function for the arguments. The number of args can // be limited. type Command struct { Flags Flags Args []string Loading Loading @@ -194,7 +197,6 @@ func (c Commands) run(words []string) error { } return cmd.Action(cmd) } // TODO: need to clean this up. args := words[1:] for i := range args { if strings.HasPrefix(args[i], "/") { Loading repl/accounts.go +0 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,6 @@ func ActionUserList(_ *dclish.Command) error { fmt.Printf("ERROR: Failed to list users (%s).\n", err) return nil } // TODO: nicer output for user. for _, u := range userlist { fmt.Printf("%s\n", u) } Loading repl/command.go +17 −5 Original line number Diff line number Diff line Loading @@ -1130,19 +1130,29 @@ characteristics of the BULLETIN Utility. The following options are available: ACCESS ALWAYS BRIEF DEFAULT_EXPIRE EXPIRE_LIMIT FOLDER NOALWAYS NOBRIEF NOPROMPT_EXPIRE NOREADNEW NOSHOWNEW NOSYSTEM PROMPT_EXPIRE READNEW SHOWNEW SYSTEM EXPIRE_LIMIT FOLDER NOACCESS NOALWAYS NOBRIEF NOPROMPT_EXPIRE NOREADNEW NOSHOWNEW NOSYSTEM PROMPT_EXPIRE READNEW SHOWNEW SYSTEM `, Action: ActionSet, Commands: dclish.Commands{ "NOACCESS": { Description: `This removes access for users. Format: SET NOACCESS id-name [folder-name]`, MinArgs: 1, MaxArgs: 2, Action: ActionSetNoaccess, }, "ACCESS": { Description: `Controls access to a private folder. A private folder can only be selected by users who have been granted access. Only the owner of that folder is allowed to grant access. Format: SET [NO]ACCESS id-name [folder-name] SET ACCESS id-name [folder-name] The id-name can be one or more ids from the system Rights Database for which access is being modified. It can also be a file name which Loading @@ -1169,6 +1179,8 @@ messages, and thus will not be able to set any login flags. (NOTE: If such a user selects such a folder and then uses SET ACCESS to grant him or herself access, the user must reselect the folder in order for the new access to take affect in order to be able to set login flags.)`, MinArgs: 0, MaxArgs: 2, Action: ActionSetAccess, Flags: dclish.Flags{ "/ALL": { Loading repl/set.go +89 −4 Original line number Diff line number Diff line Loading @@ -60,9 +60,92 @@ func ActionSet(cmd *dclish.Command) error { return nil } // ActionSetNoaccess handles the `SET ACCESS` command. func ActionSetNoaccess(cmd *dclish.Command) error { ctx := storage.Context() login := cmd.Args[0] folder := this.Folder if len(cmd.Args) == 2 { folder = folders.FindFolder(cmd.Args[1]) if folder.Name == "" { return errors.New("Folder not found") } } if this.User.Admin == 0 || folder.Owner != this.User.Login { return errors.New("Must be an admin or folder owner") } this.Q.DeleteFolderAccess(ctx, storage.DeleteFolderAccessParams{ Login: login, Folder: folder.Name, }) return nil } // ActionSetAccess handles the `SET ACCESS` command. func ActionSetAccess(_ *dclish.Command) error { fmt.Println("TODO: implement ActionSetAccess.") func ActionSetAccess(cmd *dclish.Command) error { ctx := storage.Context() optAll := cmd.Flags["/ALL"].Set if optAll { if cmd.Flags["/ALL"].Value != "true" { return errors.New("Flag '/NOALL' not recognised") } } optRead := cmd.Flags["/READ"].Set if optRead { if cmd.Flags["/READ"].Value != "true" { return errors.New("Flag '/READ' not recognised") } } if optAll { if len(cmd.Args) > 1 { return errors.New("Too many arguments for /ALL") } folder := this.Folder if len(cmd.Args) == 1 { folder = folders.FindFolder(cmd.Args[0]) if folder.Name == "" { return errors.New("Folder not found") } } if this.User.Admin == 0 || folder.Owner != this.User.Login { return errors.New("Must be an admin or folder owner") } visibility := int64(2) if optRead { visibility = 1 } this.Q.UpdateFolderVisibility(ctx, storage.UpdateFolderVisibilityParams{ Visibility: visibility, Name: folder.Name, }) return nil } if len(cmd.Args) == 0 { return errors.New("Must supply a user login to set access") } login := cmd.Args[0] folder := this.Folder if len(cmd.Args) == 2 { folder = folders.FindFolder(cmd.Args[1]) if folder.Name == "" { return errors.New("Folder not found") } } if this.User.Admin == 0 || folder.Owner != this.User.Login { return errors.New("Must be an admin or folder owner") } visibility := int64(2) if optRead { visibility = 1 } this.Q.UpdateFolderAccess(ctx, storage.UpdateFolderAccessParams{ Login: login, Folder: folder.Name, Visibility: visibility, }) return nil } Loading Loading @@ -167,7 +250,6 @@ func ActionSetSystem(_ *dclish.Command) error { if this.User.Admin == 0 { return errors.New("You are not an admin") } // TODO: parse flags and args. ctx := storage.Context() this.Q.UpdateFolderSystem(ctx, storage.UpdateFolderSystemParams{ System: 1, Loading @@ -181,7 +263,10 @@ func ActionSetNosystem(_ *dclish.Command) error { if this.User.Admin == 0 { return errors.New("You are not an admin") } // TODO: parse flags and args. if this.Folder.Name == "GENERAL" { fmt.Println("Can't remove SYSTEM from the GENERAL folder.") return nil } ctx := storage.Context() this.Q.UpdateFolderSystem(ctx, storage.UpdateFolderSystemParams{ System: 1, Loading repl/show.go +2 −2 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ func ActionShowFlags(_ *dclish.Command) error { return nil } // ActionShowFolder handles the `SHOW FOLDER` command. // ActionShowFolder handles the `SHOW FOLDER` command. This is based on // `SHOW_FOLDER` in bulletin5.for. func ActionShowFolder(cmd *dclish.Command) error { folder := this.Folder if len(cmd.Args) == 1 { Loading Loading @@ -75,7 +76,6 @@ func ActionShowFolder(cmd *dclish.Command) error { if folder.System != 0 { fmt.Println(" SYSTEM has been set.") } // TODO: Review SHOW_FOLDER in bulletin5.for. if folder.Always != 0 { fmt.Println(" ALWAYS has been set.") } Loading Loading
dclish/dclish.go +5 −3 Original line number Diff line number Diff line Loading @@ -14,7 +14,8 @@ type ActionFunc func(*Command) error // a given command. type CompleterFunc func() []string // Flag is a flag for a command. // Flag is a flag for a command. In the future setting a type would make // things a little easier. type Flag struct { OptArg bool Value string Loading @@ -26,7 +27,9 @@ type Flag struct { // Flags is the list of flags. type Flags map[string]*Flag // Command contains the definition of a command, it's flags and subcommands. // Command contains the definition of a command, its flags, subcommands // and a completer function for the arguments. The number of args can // be limited. type Command struct { Flags Flags Args []string Loading Loading @@ -194,7 +197,6 @@ func (c Commands) run(words []string) error { } return cmd.Action(cmd) } // TODO: need to clean this up. args := words[1:] for i := range args { if strings.HasPrefix(args[i], "/") { Loading
repl/accounts.go +0 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,6 @@ func ActionUserList(_ *dclish.Command) error { fmt.Printf("ERROR: Failed to list users (%s).\n", err) return nil } // TODO: nicer output for user. for _, u := range userlist { fmt.Printf("%s\n", u) } Loading
repl/command.go +17 −5 Original line number Diff line number Diff line Loading @@ -1130,19 +1130,29 @@ characteristics of the BULLETIN Utility. The following options are available: ACCESS ALWAYS BRIEF DEFAULT_EXPIRE EXPIRE_LIMIT FOLDER NOALWAYS NOBRIEF NOPROMPT_EXPIRE NOREADNEW NOSHOWNEW NOSYSTEM PROMPT_EXPIRE READNEW SHOWNEW SYSTEM EXPIRE_LIMIT FOLDER NOACCESS NOALWAYS NOBRIEF NOPROMPT_EXPIRE NOREADNEW NOSHOWNEW NOSYSTEM PROMPT_EXPIRE READNEW SHOWNEW SYSTEM `, Action: ActionSet, Commands: dclish.Commands{ "NOACCESS": { Description: `This removes access for users. Format: SET NOACCESS id-name [folder-name]`, MinArgs: 1, MaxArgs: 2, Action: ActionSetNoaccess, }, "ACCESS": { Description: `Controls access to a private folder. A private folder can only be selected by users who have been granted access. Only the owner of that folder is allowed to grant access. Format: SET [NO]ACCESS id-name [folder-name] SET ACCESS id-name [folder-name] The id-name can be one or more ids from the system Rights Database for which access is being modified. It can also be a file name which Loading @@ -1169,6 +1179,8 @@ messages, and thus will not be able to set any login flags. (NOTE: If such a user selects such a folder and then uses SET ACCESS to grant him or herself access, the user must reselect the folder in order for the new access to take affect in order to be able to set login flags.)`, MinArgs: 0, MaxArgs: 2, Action: ActionSetAccess, Flags: dclish.Flags{ "/ALL": { Loading
repl/set.go +89 −4 Original line number Diff line number Diff line Loading @@ -60,9 +60,92 @@ func ActionSet(cmd *dclish.Command) error { return nil } // ActionSetNoaccess handles the `SET ACCESS` command. func ActionSetNoaccess(cmd *dclish.Command) error { ctx := storage.Context() login := cmd.Args[0] folder := this.Folder if len(cmd.Args) == 2 { folder = folders.FindFolder(cmd.Args[1]) if folder.Name == "" { return errors.New("Folder not found") } } if this.User.Admin == 0 || folder.Owner != this.User.Login { return errors.New("Must be an admin or folder owner") } this.Q.DeleteFolderAccess(ctx, storage.DeleteFolderAccessParams{ Login: login, Folder: folder.Name, }) return nil } // ActionSetAccess handles the `SET ACCESS` command. func ActionSetAccess(_ *dclish.Command) error { fmt.Println("TODO: implement ActionSetAccess.") func ActionSetAccess(cmd *dclish.Command) error { ctx := storage.Context() optAll := cmd.Flags["/ALL"].Set if optAll { if cmd.Flags["/ALL"].Value != "true" { return errors.New("Flag '/NOALL' not recognised") } } optRead := cmd.Flags["/READ"].Set if optRead { if cmd.Flags["/READ"].Value != "true" { return errors.New("Flag '/READ' not recognised") } } if optAll { if len(cmd.Args) > 1 { return errors.New("Too many arguments for /ALL") } folder := this.Folder if len(cmd.Args) == 1 { folder = folders.FindFolder(cmd.Args[0]) if folder.Name == "" { return errors.New("Folder not found") } } if this.User.Admin == 0 || folder.Owner != this.User.Login { return errors.New("Must be an admin or folder owner") } visibility := int64(2) if optRead { visibility = 1 } this.Q.UpdateFolderVisibility(ctx, storage.UpdateFolderVisibilityParams{ Visibility: visibility, Name: folder.Name, }) return nil } if len(cmd.Args) == 0 { return errors.New("Must supply a user login to set access") } login := cmd.Args[0] folder := this.Folder if len(cmd.Args) == 2 { folder = folders.FindFolder(cmd.Args[1]) if folder.Name == "" { return errors.New("Folder not found") } } if this.User.Admin == 0 || folder.Owner != this.User.Login { return errors.New("Must be an admin or folder owner") } visibility := int64(2) if optRead { visibility = 1 } this.Q.UpdateFolderAccess(ctx, storage.UpdateFolderAccessParams{ Login: login, Folder: folder.Name, Visibility: visibility, }) return nil } Loading Loading @@ -167,7 +250,6 @@ func ActionSetSystem(_ *dclish.Command) error { if this.User.Admin == 0 { return errors.New("You are not an admin") } // TODO: parse flags and args. ctx := storage.Context() this.Q.UpdateFolderSystem(ctx, storage.UpdateFolderSystemParams{ System: 1, Loading @@ -181,7 +263,10 @@ func ActionSetNosystem(_ *dclish.Command) error { if this.User.Admin == 0 { return errors.New("You are not an admin") } // TODO: parse flags and args. if this.Folder.Name == "GENERAL" { fmt.Println("Can't remove SYSTEM from the GENERAL folder.") return nil } ctx := storage.Context() this.Q.UpdateFolderSystem(ctx, storage.UpdateFolderSystemParams{ System: 1, Loading
repl/show.go +2 −2 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ func ActionShowFlags(_ *dclish.Command) error { return nil } // ActionShowFolder handles the `SHOW FOLDER` command. // ActionShowFolder handles the `SHOW FOLDER` command. This is based on // `SHOW_FOLDER` in bulletin5.for. func ActionShowFolder(cmd *dclish.Command) error { folder := this.Folder if len(cmd.Args) == 1 { Loading Loading @@ -75,7 +76,6 @@ func ActionShowFolder(cmd *dclish.Command) error { if folder.System != 0 { fmt.Println(" SYSTEM has been set.") } // TODO: Review SHOW_FOLDER in bulletin5.for. if folder.Always != 0 { fmt.Println(" ALWAYS has been set.") } Loading