PermissionRepository

works.iterative.sqldb.PermissionRepository

Repository interface for persisting RelationTuples to a SQL database.

This trait defines the contract for storing Zanzibar-inspired permission tuples, enabling database-backed PermissionService implementations.

Implementation notes:

  • All operations return Task[T] to handle database errors
  • Database errors should be handled at the service layer (fail-closed pattern)
  • Implementations should use parameterized queries to prevent SQL injection
  • addRelation should be idempotent (duplicate inserts should succeed)

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def addRelation(userId: UserId, relation: String, target: PermissionTarget): Task[Unit]

Add a relation tuple to the database.

Add a relation tuple to the database.

This operation should be idempotent - adding the same relation twice should succeed without error (either by using INSERT IGNORE or catching unique constraint violations).

Value parameters

relation

The relationship type

target

The permission target

userId

The user ID

Attributes

Returns

Task[Unit]

def getUserRelations(userId: UserId, namespace: String): Task[Set[RelationTuple]]

Get all relation tuples for a user in a specific namespace.

Get all relation tuples for a user in a specific namespace.

This is the primary query for permission checking - fetches all relations the user has within a namespace, which are then evaluated by PermissionLogic.

Value parameters

namespace

The resource namespace to filter by

userId

The user ID

Attributes

Returns

Task[Set[RelationTuple]] - Set of all relation tuples for the user in namespace

def hasRelation(userId: UserId, relation: String, target: PermissionTarget): Task[Boolean]

Check if a specific relation exists between user and target.

Check if a specific relation exists between user and target.

Value parameters

relation

The relationship type (e.g., "owner", "editor", "viewer")

target

The permission target

userId

The user ID to check

Attributes

Returns

Task[Boolean] - true if relation exists, false otherwise

def removeRelation(userId: UserId, relation: String, target: PermissionTarget): Task[Unit]

Remove a relation tuple from the database.

Remove a relation tuple from the database.

This operation should be idempotent - removing a non-existent relation should succeed.

Value parameters

relation

The relationship type

target

The permission target

userId

The user ID

Attributes

Returns

Task[Unit]