repository

package
v1.0.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 1 module, 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 repository reads and writes the sharing table every vertical grants through.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

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

Repository reads and writes every share in the platform.

One repository for every resource kind, because the rows differ only in the resource type they name. Every method is scoped by that type: an id is unique within its own kind, not across them, so a lookup that omitted the type could return a product's share for a storage's id.

func NewRepository

func NewRepository(db *gorm.DB) *Repository

NewRepository returns a repository backed by db.

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, s *model.Sharing) error

Delete removes a share.

func (*Repository) DeleteByPrincipal

func (r *Repository) DeleteByPrincipal(ctx context.Context, principalType model.PrincipalType, principalID string) error

DeleteByPrincipal removes every share granted to one principal, across every resource kind.

It is what keeps a deleted group from leaving rows behind. Those rows would grant nothing — memberships are cascaded away with the group, so nobody resolves as an active member of it — but they would accumulate, and a listing of a resource's shares would name a group that no longer exists.

func (*Repository) DeleteByResources

func (r *Repository) DeleteByResources(ctx context.Context, resourceType model.ResourceType, resourceIDs []string) error

DeleteByResources removes every share of any of resourceIDs.

No foreign key points at the resource, so nothing in the database removes these when the record they open up goes away: whatever deletes a resource calls this in the same transaction. For a virtual directory that means the whole subtree, since the directory rows below it are cascaded away by the database without their shares.

func (*Repository) FindByID

func (r *Repository) FindByID(ctx context.Context, resourceType model.ResourceType, resourceID, sharingID string) (*model.Sharing, error)

FindByID returns one share scoped to its resource, or gorm.ErrRecordNotFound.

Scoping is deliberate: it stops a sharing id belonging to one resource from being reached through another resource's path.

func (*Repository) FindByPrincipal

func (r *Repository) FindByPrincipal(ctx context.Context, resourceType model.ResourceType, resourceID string, principalType model.PrincipalType, principalID string) (*model.Sharing, error)

FindByPrincipal returns the share of one resource with one principal, or gorm.ErrRecordNotFound. It is what makes a duplicate share reportable as a conflict.

func (*Repository) FindByResource

func (r *Repository) FindByResource(ctx context.Context, resourceType model.ResourceType, resourceID string) ([]model.Sharing, error)

FindByResource returns every share of one resource, of either principal kind.

Resolving access needs them together, which is the whole point of the single table: what used to be two queries against two tables is one.

func (*Repository) FindByResources

func (r *Repository) FindByResources(ctx context.Context, resourceType model.ResourceType, resourceIDs []string) ([]model.Sharing, error)

FindByResources returns every share of any of resourceIDs.

A virtual directory inherits what its ancestors grant, so resolving one node asks about the whole chain at once rather than once per level.

func (*Repository) ResourceIDsSharedWith

func (r *Repository) ResourceIDsSharedWith(ctx context.Context, resourceType model.ResourceType, userID string) ([]string, error)

ResourceIDsSharedWith returns the ids of one kind of resource reaching userID through a share: named directly, or through a group they are an active member of.

It replaces the pair of correlated subqueries each resource used to build against its own two tables. Callers filter out what the user already owns; a share is not how an owner reaches their own record.

func (*Repository) Save

func (r *Repository) Save(ctx context.Context, s *model.Sharing) error

Save inserts or updates a share.

func (*Repository) WithTx

func (r *Repository) WithTx(tx *gorm.DB) *Repository

WithTx returns a repository bound to tx.

Jump to

Keyboard shortcuts

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