Documentation
¶
Overview ¶
Package resourceshare shares managed resources the way assets are shared (#2258): with a person, an address or a persona, as viewer or editor, in portal_shares beside asset, collection and prompt shares. A share is addressed to whoever it names when they open the resource, so a share to a persona reaches the people whose roles resolve to it then.
The resources API reads a caller's share on every request through Lookup, which is what lets a recipient read a resource outside every folder they can see, and an editor change it. Deleting the resource removes its shares (the column cascades).
Index ¶
- Variables
- type Caller
- type Deps
- type PermissionRequest
- type Recipient
- type Ref
- type Resources
- type Service
- func (s *Service) LinkShare(ctx context.Context, claims *resource.Claims, res *resource.Resource, ...) (share *portaldomain.Share, status int, msg string)
- func (s *Service) Lookup(ctx context.Context, claims *resource.Claims, c Caller) func(resourceID string) string
- func (s *Service) Register(mux *http.ServeMux)
- func (s *Service) Withdraw(ctx context.Context, share *portaldomain.Share)
- type ShareList
- type ShareRequest
- type SharedList
- type SharedResource
- type Shares
- type Store
- func (s *Store) Insert(ctx context.Context, share *portaldomain.Share) error
- func (s *Store) List(ctx context.Context, resourceID string) ([]portaldomain.Share, error)
- func (s *Store) Permission(ctx context.Context, resourceID string, rcpt Recipient) (string, error)
- func (s *Store) Revoke(ctx context.Context, resourceID, shareID string) error
- func (s *Store) SetPermission(ctx context.Context, resourceID, shareID string, ...) error
- func (s *Store) SharedWith(ctx context.Context, rcpt Recipient) ([]Ref, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("share not found")
ErrNotFound is a share that is not on the resource or is already revoked.
Functions ¶
This section is empty.
Types ¶
type Caller ¶
type Caller struct {
// Persona is the persona they resolve to now: what a share to a persona
// is matched against.
Persona string
// External is a person of an external persona: shares to them are held
// to viewer, and they share nothing (#2290).
External bool
// Sharing is persona.SharingAllowed.
Sharing bool
}
Caller is what the share routes need to know of the person asking, from the persona their roles resolve to.
type Deps ¶
type Deps struct {
Resources Resources
// Claims authenticates a request as the resources API does, its level
// applied and its share lookup bound.
Claims func(r *http.Request) (*resource.Claims, error)
// Caller resolves the persona a set of roles resolves to.
Caller func(roles []string) Caller
// Notify tells one address a file was shared with them.
Notify func(ctx context.Context, share *portaldomain.Share, resourceID, title, message string)
// Members are the addresses of a persona's people.
Members func(ctx context.Context, persona string) []string
// PersonaExists reports whether a persona of that name is registered; nil
// accepts any name.
PersonaExists func(name string) bool
// HasAccount reports whether the directory holds an address; one it does
// not can only view (#2291). nil treats every address as one.
HasAccount func(ctx context.Context, email string) bool
}
Deps is what the service is built from.
type PermissionRequest ¶ added in v1.151.1
type PermissionRequest struct {
// Permission is "viewer" or "editor".
Permission string `json:"permission" example:"editor"`
}
PermissionRequest is a file share's new permission.
type Recipient ¶
type Recipient struct {
UserID string
Email string
Persona string
// Internal is a person of an internal persona, whom a link share any
// signed-in person opens reaches; a person of an external persona sees
// only what is shared with them.
Internal bool
}
Recipient is who a lookup is for.
type Ref ¶
type Ref struct {
ResourceID string
Permission string
// ViaPersona names the persona the share reached them through.
ViaPersona string
}
Ref is one resource shared with a recipient.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service serves resource shares.
func (*Service) LinkShare ¶
func (s *Service) LinkShare(ctx context.Context, claims *resource.Claims, res *resource.Resource, where string) (share *portaldomain.Share, status int, msg string)
LinkShare makes the share a file posted to a channel is opened by: any signed-in person of an internal persona, as viewer, recorded as posted to where (#2258). It answers the refusal's status and message when the caller may not share the file.
func (*Service) Lookup ¶
func (s *Service) Lookup(ctx context.Context, claims *resource.Claims, c Caller) func(resourceID string) string
Lookup is resource.Claims.Shared for a caller: the permission a share gives them on a resource, held to viewer for a person of an external persona, as an asset's is (#2258). A read that fails grants nothing.
type ShareRequest ¶
type ShareRequest struct {
// persona opens it as viewer whatever it says.
Permission string `json:"permission,omitempty" example:"viewer"`
Message string `json:"message,omitempty"`
Notify *bool `json:"notify,omitempty"`
}
ShareRequest is a share to create: a person by address, or a persona.
type SharedResource ¶
type SharedResource struct {
}
SharedResource is one resource shared with the caller.
type Shares ¶
type Shares interface {
}
Shares is the store the routes act through; *Store satisfies it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes resource shares.
func (*Store) Insert ¶
Insert writes a share built by portaldomain.BuildShare with a ResourceID target, filling CreatedAt from the row.
func (*Store) Permission ¶
Permission is the highest permission a share gives the recipient on a resource: "editor", "viewer", or "" for none.
func (*Store) SetPermission ¶ added in v1.151.1
func (s *Store) SetPermission(ctx context.Context, resourceID, shareID string, perm portaldomain.SharePermission) error
Revoke ends a share on a resource. SetPermission changes one standing share's permission (#2291).