Documentation
¶
Overview ¶
Package accessreq is the request for access a signed-in person makes from a link to an asset, collection or prompt they cannot open (#2090), and the owner's answer to it. Approving creates an ordinary person share, so the link the requester followed opens with no further step; declining closes the request. A requester has one pending request per item at a time, asks a few times a day at most, and a request expires after the access_requests setting's period.
Index ¶
- Constants
- Variables
- func CleanMessage(m string) (string, error)
- func Register(mux *http.ServeMux, wrap func(http.Handler) http.Handler, d Deps)
- func RegisterSettings(mux *http.ServeMux, wrap func(http.Handler) http.Handler, store SettingsStore, ...)
- type DecideRequest
- type Decision
- type Deps
- type OpenRequest
- type Page
- type Request
- type RequestList
- type Requests
- type Settings
- type SettingsStore
- type Store
- func (s *Store) Decide(ctx context.Context, id string, d Decision) error
- func (s *Store) Get(ctx context.Context, id string) (*Request, error)
- func (s *Store) ListForOwner(ctx context.Context, ownerEmail, targetType, targetID string, all bool) ([]Request, error)
- func (s *Store) Open(ctx context.Context, r Request) (*Request, bool, error)
- func (s *Store) Pending(ctx context.Context, targetType, targetID, requesterID string) (*Request, error)
- type Target
Constants ¶
const ( StatusPending = "pending" StatusApproved = "approved" StatusDeclined = "declined" // StatusExpired is reported, never stored: a pending request past its // expiry reads as expired. StatusExpired = "expired" )
Statuses.
const ( TargetAsset = "asset" TargetCollection = "collection" TargetPrompt = "prompt" // TargetResource is a managed resource, a file (#2258). TargetResource = "resource" )
Target types.
const ( DefaultExpireDays = 14 // MaxPerDay is how many requests one person makes for one item in a day. MaxPerDay = 3 )
Defaults and bounds.
const SettingsSection = "access_requests"
SettingsSection is the platform_settings section holding Settings.
Variables ¶
var ( ErrNotFound = errors.New("access request not found") ErrTooMany = errors.New("you have asked for access to this item too often today; try again tomorrow") ErrDecided = errors.New("the request was already answered") )
Errors a caller maps to a status.
Functions ¶
func CleanMessage ¶
CleanMessage trims a requester's note and refuses one too long.
Types ¶
type DecideRequest ¶
type DecideRequest struct {
// Permission is viewer or editor.
Permission string `json:"permission" example:"viewer"`
}
DecideRequest is the body of an approval.
type Decision ¶
Decision is the answer to a request: approved with a permission and the share it created, or declined.
type Deps ¶
type Deps struct {
Store Requests
// Resolve reads an item; an error is an item that does not exist.
Resolve func(ctx context.Context, targetType, id string) (Target, error)
// CanOpen reports whether the user already opens the item.
CanOpen func(ctx context.Context, user *access.User, targetType, id string) bool
// IsAdmin is the platform's administrator rule.
IsAdmin func(user *access.User) bool
// own (persona.SharingAllowed): an approval writes a share, so an owner
// whose persona withholds sharing cannot approve (#2257). An
// administrator always can. Nil admits every owner.
CanShare func(user *access.User) bool
Share func(ctx context.Context, targetType, id, createdBy, recipientEmail, permission string) (string, error)
// NotifyOwner tells the owner a request is waiting; NotifyRequester tells
// the requester how it was answered. Either may be nil.
NotifyOwner func(ctx context.Context, req *Request, itemName string)
NotifyRequester func(ctx context.Context, req *Request, itemName string)
// Settings reads the stored configuration; nil uses Defaults.
Settings func(ctx context.Context) Settings
}
Deps is what the routes are built from.
type OpenRequest ¶
type OpenRequest struct {
Message string `json:"message,omitempty" example:"I need this for the quarterly review"`
}
OpenRequest is the body of a request for access.
type Page ¶
type Page struct {
// HasAccess is true when the person already opens the item.
HasAccess bool `json:"has_access"`
// Name is the item's name, only when the deployment reveals names.
Name string `json:"name,omitempty"`
// OwnerEmail is who a request goes to.
OwnerEmail string `json:"owner_email"`
// Pending is the person's live request for the item, if any.
Pending *Request `json:"pending,omitempty"`
}
Page is what the page a person who cannot open an item shows.
type Request ¶
type Request struct {
ID string `json:"id"`
TargetType string `json:"target_type" example:"asset"`
TargetID string `json:"target_id"`
RequesterID string `json:"requester_id"`
RequesterEmail string `json:"requester_email"`
OwnerEmail string `json:"owner_email"`
Message string `json:"message,omitempty"`
Status string `json:"status" example:"pending"`
Permission string `json:"permission,omitempty" example:"viewer"`
DecidedBy string `json:"decided_by,omitempty"`
DecidedAt *time.Time `json:"decided_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
// TargetName is the item's name, filled for its owner.
TargetName string `json:"target_name,omitempty"`
}
Request is one request for access.
type RequestList ¶
type RequestList struct {
Requests []Request `json:"requests"`
}
RequestList is an owner's waiting requests.
type Requests ¶
type Requests interface {
Open(ctx context.Context, r Request) (*Request, bool, error)
Pending(ctx context.Context, targetType, targetID, requesterID string) (*Request, error)
Get(ctx context.Context, id string) (*Request, error)
ListForOwner(ctx context.Context, ownerEmail, targetType, targetID string, all bool) ([]Request, error)
Decide(ctx context.Context, id string, d Decision) error
}
Requests is the store the routes read and write; *Store implements it.
type Settings ¶
type Settings struct {
// RevealNames shows the item's name on the page a person who cannot
// open it sees; otherwise the page has a generic title.
RevealNames bool `json:"reveal_names" example:"false"`
// ExpireDays is how long a request waits for an answer.
ExpireDays int `json:"expire_days" example:"14"`
}
Settings is the stored configuration.
type SettingsStore ¶
type SettingsStore interface {
Read(ctx context.Context) Settings
Write(ctx context.Context, s Settings, author string) error
}
SettingsStore reads and writes the section.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps the requests.
func (*Store) ListForOwner ¶
func (s *Store) ListForOwner(ctx context.Context, ownerEmail, targetType, targetID string, all bool) ([]Request, error)
ListForOwner returns the live pending requests for items the address owns, or for one item when targetType and targetID are set; with all, every request on the platform (an administrator's list).