resourceshare

package
v1.166.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 {
	Shares    Shares
	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
	ShareID    string
	SharedBy   string
	SharedAt   time.Time
	Permission string
	// ViaPersona names the persona the share reached them through.
	ViaPersona string
}

Ref is one resource shared with a recipient.

type Resources

type Resources interface {
	Get(ctx context.Context, id string) (*resource.Resource, error)
}

Resources reads a resource.

type Service

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

Service serves resource shares.

func New

func New(d Deps) *Service

New returns the service.

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.

func (*Service) Register

func (s *Service) Register(mux *http.ServeMux)

Register mounts the routes on mux. They are more specific than the resources API's own mount, so they are served here.

func (*Service) Withdraw

func (s *Service) Withdraw(ctx context.Context, share *portaldomain.Share)

Withdraw revokes a link share whose post did not go out.

type ShareList

type ShareList struct {
	Shares []portaldomain.Share `json:"shares"`
}

ShareList is the shares on a resource.

type ShareRequest

type ShareRequest struct {
	SharedWithEmail   string `json:"shared_with_email,omitempty" example:"colleague@example.com"`
	SharedWithPersona string `json:"shared_with_persona,omitempty" example:"marketing"`
	// Permission is viewer (the default) or editor. A person of an external
	// persona opens it as viewer whatever it says.
	Permission string `json:"permission,omitempty" example:"viewer"`
	// Message is a plain-text note in the notification.
	Message string `json:"message,omitempty"`
	// Notify is whether the recipient is told; omitted is yes.
	Notify *bool `json:"notify,omitempty"`
}

ShareRequest is a share to create: a person by address, or a persona.

type SharedList

type SharedList struct {
	Resources []SharedResource `json:"resources"`
}

SharedList is the resources shared with the caller.

type SharedResource

type SharedResource struct {
	Resource   resource.Resource `json:"resource"`
	ShareID    string            `json:"share_id"`
	SharedBy   string            `json:"shared_by"`
	SharedAt   time.Time         `json:"shared_at"`
	Permission string            `json:"permission"`
	ViaPersona string            `json:"via_persona,omitempty"`
}

SharedResource is one resource shared with the caller.

type Shares

type Shares interface {
	Insert(ctx context.Context, share *portaldomain.Share) error
	List(ctx context.Context, resourceID string) ([]portaldomain.Share, error)
	Permission(ctx context.Context, resourceID string, rcpt Recipient) (string, error)
	SharedWith(ctx context.Context, rcpt Recipient) ([]Ref, error)
	Revoke(ctx context.Context, resourceID, shareID string) error
	SetPermission(ctx context.Context, resourceID, shareID string, perm portaldomain.SharePermission) error
}

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 NewStore

func NewStore(db *sql.DB) *Store

NewStore returns the store over db.

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, share *portaldomain.Share) error

Insert writes a share built by portaldomain.BuildShare with a ResourceID target, filling CreatedAt from the row.

func (*Store) List

func (s *Store) List(ctx context.Context, resourceID string) ([]portaldomain.Share, error)

List returns the shares that still grant on a resource, newest first.

func (*Store) Permission

func (s *Store) Permission(ctx context.Context, resourceID string, rcpt Recipient) (string, error)

Permission is the highest permission a share gives the recipient on a resource: "editor", "viewer", or "" for none.

func (*Store) Revoke

func (s *Store) Revoke(ctx context.Context, resourceID, shareID string) error

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).

func (*Store) SharedWith

func (s *Store) SharedWith(ctx context.Context, rcpt Recipient) ([]Ref, error)

SharedWith returns the resources shared with the recipient, one row each with the highest permission's share.

Jump to

Keyboard shortcuts

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