foldergrant

package
v1.167.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package foldergrant keeps write grants on Global folders (#2684): an administrator grants a person (by address) or a persona write on one folder of the Global library, and the grant covers that folder and everything beneath it (resource.PathUnder). A grant is a share whose target is the folder's path (portal_shares.folder_path), read on every request a resources check asks about, through the source installed in pkg/resource.

Only administrators list, add and remove grants; a grantee only learns that they can write somewhere.

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicate = errors.New("this folder already grants write to that person or persona")

ErrDuplicate is a grant the folder already holds for the same grantee.

View Source
var ErrNotFound = errors.New("folder grant not found")

ErrNotFound is a grant that does not exist or was already removed.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is the admin routes.

func NewAPI

func NewAPI(d Deps) *API

NewAPI returns the routes over d.

func (*API) Register

func (a *API) Register(mux *http.ServeMux, wrap func(http.Handler) http.Handler)

Register mounts the routes behind wrap, the admin API's authentication.

type AddInput

type AddInput struct {
	Folder  string `json:"folder" example:"reports"`
	Email   string `json:"email,omitempty" example:"jane@example.com"`
	Persona string `json:"persona,omitempty" example:"finance"`
}

AddInput grants write on a Global folder to a person or a persona.

type Deps

type Deps struct {
	Store *Store
	// Actor is the administrator's address; every request passed the admin
	// API's authentication.
	Actor func(*http.Request) string
	// PersonaExists reports whether a persona is defined.
	PersonaExists func(name string) bool
	// ExternalPersona reports whether a persona is external.
	ExternalPersona func(name string) bool
	// ExternalPerson reports whether the person at an address resolves to an
	// external persona now; nil reads nobody as one.
	ExternalPerson func(ctx context.Context, email string) bool
	// FolderExists reports whether a Global folder exists (stored, or holding
	// a file).
	FolderExists func(ctx context.Context, path string) (bool, error)
	// Sites names the sites serving a Global folder or one above it as media;
	// nil names none.
	Sites func(ctx context.Context, path string) ([]string, error)
	// Audit records every change; nil records none.
	Audit middleware.AuditLogger
}

Deps is what the routes act through.

type Grant

type Grant struct {
	ID string `json:"id" example:"fg_9c1e"`
	// Folder is the Global folder the grant is on.
	Folder string `json:"folder" example:"reports"`
	// Email is the person it is for, "" for a persona grant.
	Email string `json:"email,omitempty" example:"jane@example.com"`
	// Persona is the persona it is for, "" for a person's grant.
	Persona   string    `json:"persona,omitempty" example:"finance"`
	CreatedBy string    `json:"created_by" example:"admin@example.com"`
	CreatedAt time.Time `json:"created_at"`
	// Inherited is a grant on a folder above the one asked about, which
	// covers it too.
	Inherited bool `json:"inherited"`
}

Grant is one write grant on a Global folder.

type GrantList

type GrantList struct {
	Folder string  `json:"folder" example:"reports"`
	Grants []Grant `json:"grants"`
	// Sites are the sites serving the folder, or one above it, as media: a
	// grantee's write changes what they serve.
	Sites []string `json:"sites"`
}

GrantList is the grants covering a Global folder.

type Source

type Source struct {
	Store *Store
	// External reports whether a persona is external; nil reads none as one.
	External func(persona string) bool
}

Source is the resource.FolderGrantSource the platform installs: a grantee's grants, none for a person any of whose personas is now external, since a person of an external persona never sees Global.

func (Source) WritableFolders

func (s Source) WritableFolders(ctx context.Context, g grantsource.Grantee) ([]string, error)

WritableFolders is resource.FolderGrantSource.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store reads and writes grants.

func NewStore

func NewStore(db *sql.DB) *Store

NewStore returns the store over db, nil without one.

func (*Store) Add

func (s *Store) Add(ctx context.Context, g *Grant) error

Add writes a grant, refusing one the folder already holds for the grantee.

func (*Store) ByPersona

func (s *Store) ByPersona(ctx context.Context, persona string) ([]Grant, error)

ByPersona is the grants a persona holds, by folder.

func (*Store) FolderExists

func (s *Store) FolderExists(ctx context.Context, path string) (bool, error)

FolderExists reports whether the Global folder exists.

func (*Store) List

func (s *Store) List(ctx context.Context, folder string) ([]Grant, error)

List is the grants covering folder, its own first after the inherited ones, each marked inherited when it is on a folder above.

func (*Store) Remove

func (s *Store) Remove(ctx context.Context, id string) (*Grant, error)

Remove ends a grant, returning what it was.

func (*Store) Sites

func (s *Store) Sites(ctx context.Context, path string) ([]string, error)

Sites is the sites serving the Global folder, or one above it, as media.

func (*Store) Writable

func (s *Store) Writable(ctx context.Context, g grantsource.Grantee) ([]string, error)

Writable is the folders the grantee holds a grant on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL