Skip to content
Snippets Groups Projects
Select Git revision
  • v1.20151229
  • master default protected
  • commit-alias
  • editor-modeline
  • commit-abbreviation
  • make-hooks-work-as-advertised
  • lyda-home-version
  • feature-aliases
  • git-version-bsd-fix
  • hook-changes
  • v1.20151229-1
  • v1.20150502-1
  • v1.20150502
  • v1.20141026-manpage-static
  • v1.20141026-1
  • v1.20141026
  • v1.20141025-1
  • v1.20141025
  • v1.20141009-manpage-static
  • v1.20141009-1
  • v1.20141009
  • v1.20140508-1-bpo70+1
  • v1.20140508-1
  • v1.20140508-manpage-static
  • v1.20140508
  • v1.20140507
  • v1.20140313
  • v1.20131229-homebrew
  • v1.20131229-1-bpo60+1
29 results

CONTRIBUTORS

Blame
  • folders.go 3.08 KiB
    // Package folders are all the routines and sql for managing folders.
    package folders
    
    import (
    	"errors"
    	"strings"
    
    	"git.lyda.ie/kevin/bulletin/storage"
    	"git.lyda.ie/kevin/bulletin/this"
    )
    
    // ValidFolder validates the folder name for this user.
    func ValidFolder(folder string) (storage.Folder, error) {
    	if strings.Contains(folder, "%") {
    		return storage.Folder{}, errors.New("Folder name cannot contain a %")
    	}
    	correct := FindFolder(folder)
    	if correct.Name == "" {
    		return storage.Folder{}, errors.New("Unable to select the folder")
    	}
    	if !IsFolderAccess(correct.Name, this.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 storage.Folder{}, errors.New("Unable to select the folder")
    	}
    	return correct, nil
    }
    
    // Values for FolderVisibility.
    const (
    	FolderPublic      int64 = 0
    	FolderSemiPrivate       = 1
    	FolderPrivate           = 2
    )
    
    // CreateFolder creates a new folder.
    func CreateFolder(owner string, options storage.CreateFolderParams) error {
    	if !IsAlphaNum(options.Name) {
    		return errors.New("Folder can only have letters and numbers")
    	}
    	options.Name = strings.ToUpper(options.Name)
    
    	ctx := storage.Context()
    	tx, err := this.Store.Begin()
    	if err != nil {
    		return err
    	}
    	defer tx.Rollback()
    	qtx := this.Q.WithTx(tx)
    	err = qtx.CreateFolder(ctx, options)
    	if err != nil {
    		return err
    	}
    	err = qtx.AddFolderOwner(ctx, storage.AddFolderOwnerParams{
    		Folder: options.Name,
    		Login:  owner,
    	})
    	if err != nil {
    		return err
    	}
    
    	// TODO: process this error a bit more to give a better error message.
    	return tx.Commit()
    }
    
    // ListFolder provides a list of folders that this.User has access to.
    func ListFolder() ([]storage.ListFolderRow, error) {
    	// TODO: need to check access.
    	ctx := storage.Context()