Skip to content
Snippets Groups Projects
Unverified Commit 0c04baa6 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Implement select

parent 48f6e506
Branches
Tags
No related merge requests found
......@@ -24,8 +24,11 @@ sqlite trigger tracing: `.trace stdout --row --profile --stmt --expanded --plain
## Things to do
* Implement each command.
* Next: folder commands - ~~CREATE~~, ~~REMOVE~~, MODIFY, INDEX, SELECT
* Messages: ADD, CURRENT, DIRECTORY
* Next: folder commands - ~~CREATE~~, ~~REMOVE~~, MODIFY, ~~INDEX~~, SELECT
* Messages: ADD, CURRENT, DIRECTORY, BACK, CHANGE, FIRST, REMOVE, NEXT, READ
* Messages edit: CHANGE, REPLY, FORWARD
* Moving messages: COPY, MOVE
* Mail: MAIL, FORWARD,
* Editor - need an embedded editor
* An EDT inspired [editor](https://sourceforge.net/projects/edt-text-editor/)
* [gkilo](https://github.com/vcnovaes/gkilo)
......
......@@ -102,19 +102,32 @@ func (s *Store) ListFolder(user string, _ FolderListOptions) ([]FolderListRow, e
return flr, nil
}
// IsFolderAccess checks if a user can access a folder.
func (s *Store) IsFolderAccess(name, user string) bool {
found := 0
s.db.Get(&found,
`SELECT 1 FROM folders AS f LEFT JOIN co_owners AS c ON f.name = c.folder
WHERE f.name = $1 AND
(f.visibility = "public"
OR (f.owner = $2 OR c.OWNER = $2))`,
name, user)
return found == 1
}
// IsFolderOwner checks if a user is a folder owner.
func (s *Store) IsFolderOwner(name, user string) bool {
found := 0
s.db.Get(&found,
`SELECT 1 FROM folders AS f LEFT JOIN co_owners AS c
ON f.name = c.folder
WHERE f.name = $1 (f.owner = '$2' OR c.OWNER = '$2')`,
WHERE f.name = $1 AND (f.owner = '$2' OR c.OWNER = '$2')`,
name, user)
return found == 1
}
// DeleteFolder creates a new folder.
func (s *Store) DeleteFolder(name string) error {
// TODO: make sure user can delete this table.
results, err := s.db.Exec("DELETE FROM folders WHERE name=$1", name)
// TODO: process this error a bit more to give a better error message.
if err != nil {
......
......@@ -82,7 +82,9 @@ func ActionCreate(cmd *dclish.Command) error {
// ActionSelect handles the `SELECT` command. This selects a folder.
func ActionSelect(cmd *dclish.Command) error {
fmt.Printf("TODO: implement SELECT:\n%s\n\n", cmd.Description)
if accounts.User.Folders.IsFolderAccess(cmd.Args[0], accounts.User.Login) {
accounts.User.CurrentFolder = cmd.Args[0]
}
return nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment