shareaccess

package
v1.106.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package shareaccess decides who may open a portal share token.

Before #999 a share token was a bearer credential: anyone holding the URL could read the shared asset, including shares created for one named person and emailed to them. This package holds the mode domain and the access decision, independent of HTTP, so the portal's public routes all reach the same verdict through one function.

Index

Constants

View Source
const (
	MsgSignInRequired = "This link requires you to sign in. " +
		"Open it again after signing in to the platform."
	MsgNotRecipient = "This link is restricted to the person it was shared with. " +
		"You are signed in as a different user. Ask the sender to share it with you."
	MsgRevoked = "This share link has been revoked."
	MsgExpired = "This share link has expired."
)

Denial messages. They name the reason so a viewer can act on it (sign in, or ask the sender) instead of guessing.

Variables

View Source
var (
	ErrInvalidMode = errors.New(
		"invalid access_mode: must be restricted, authenticated, or public")
	ErrRestrictedNeedsRecipient = errors.New(
		"access_mode restricted requires shared_with_email or shared_with_user_id")
)

Errors returned when a create-share request asks for an impossible mode.

Functions

func Authorize

func Authorize(share Share, viewer *Viewer) (string, bool)

Authorize decides whether viewer may open share, returning the message to render when it may not. viewer is nil for an anonymous request.

A share whose mode is empty (a row written before the mode column existed, or by a caller that left it blank) is treated as its shape's default rather than as public, so an unset value can never widen access.

func Availability

func Availability(revoked bool, expiresAt *time.Time, now time.Time) string

Availability returns the message to render when a share cannot be opened by anyone — revoked, or past its expiry — and "" while it is still live. It is the check that precedes Authorize: who the caller is does not matter yet.

Types

type Mode

type Mode string

Mode determines who may open a share token.

const (
	// ModeRestricted admits only the share's named recipient and its
	// creator. A restricted share without a recipient is invalid.
	ModeRestricted Mode = "restricted"
	// ModeAuthenticated admits any signed-in platform user.
	ModeAuthenticated Mode = "authenticated"
	// ModePublic admits anyone holding the token, without sign-in. It is
	// never a default: the create-share request must ask for it.
	ModePublic Mode = "public"
)

func Default

func Default(hasRecipient bool) Mode

Default returns the mode a share takes when its creator did not choose one: restricted when the share names a recipient, authenticated when it does not. ModePublic is never a default — it must be requested.

func Resolve

func Resolve(requested string, hasRecipient bool) (Mode, error)

Resolve validates a requested mode and applies the default for the share's shape. A restricted share with no named recipient is rejected: there would be nobody it resolves for.

type Share

type Share struct {
	Mode            Mode
	RecipientUserID string
	RecipientEmail  string
	CreatorEmail    string
}

Share is the part of a share row the decision depends on.

type Viewer

type Viewer struct {
	UserID string
	Email  string
}

Viewer is the authenticated caller. A nil *Viewer is an anonymous request.

Jump to

Keyboard shortcuts

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