account

package
v0.5.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// RoleAdmin is the admin role for accounts
	RoleAdmin = `admin`

	// PermAuthCross is the permission for cross-account auth
	PermAuthCross = `auth.cross`
)

Variables

View Source
var CtxPermissionCheckAccount = models.CtxPermissionCheckAccount

CtxPermissionCheckAccount is the context key for account permission checks.

Functions

This section is empty.

Types

type ACLAccount added in v0.5.0

type ACLAccount struct {
	models.AccountBase
}

ACLAccount is a minimal account.Model for permission checks (ID + admins only).

func ACLAccountStub added in v0.5.0

func ACLAccountStub(id uint64, adminUserIDs ...uint64) *ACLAccount

ACLAccountStub returns an ACL placeholder account for permission checks.

type Filter

type Filter struct {
	ID     []uint64
	UserID []uint64
	Title  []string
	Status []pkgModels.ApproveStatus
}

Filter of the objects list

func (*Filter) AdjustPermissions added in v0.4.0

func (fl *Filter) AdjustPermissions(ctx context.Context) error

AdjustPermissions narrows the filter to the current user's accounts. Cannot import pkg/acl or pkg/context/session due to an import cycle; uses the lower-level context sub-packages instead.

func (*Filter) PrepareQuery

func (fl *Filter) PrepareQuery(query *gorm.DB) *gorm.DB

type ListOptions added in v0.4.0

type ListOptions = repository.ListOptions

ListOptions is the list of query options

type ListOrder

type ListOrder struct {
	ID        pkgModels.Order
	Title     pkgModels.Order
	Status    pkgModels.Order
	CreatedAt pkgModels.Order
	UpdatedAt pkgModels.Order
}

ListOrder of the objects list

func (*ListOrder) PrepareQuery

func (ord *ListOrder) PrepareQuery(query *gorm.DB) *gorm.DB

type M2MAccountMemberRole added in v0.4.0

type M2MAccountMemberRole = models.M2MAccountMemberRole

type Member added in v0.5.0

type Member[TUser user.Model, TAccount Model] struct {
	models.MemberBase
	Account TAccount `db:"-" gorm:"foreignKey:AccountID;references:ID"`
	User    TUser    `db:"-" gorm:"foreignKey:UserID;references:ID"`
}

Member links a user to an account with optional preloaded Account and User refs.

func MemberStub added in v0.5.0

func MemberStub[TUser user.Model, TAccount Model](id, accountID, userID uint64) *Member[TUser, TAccount]

MemberStub returns member with ID and optional account/user keys (ACL/GraphQL placeholders).

func MemberStubFromUser added in v0.5.0

func MemberStubFromUser[TUser user.Model, TAccount Model](accountObj TAccount, userObj TUser) *Member[TUser, TAccount]

MemberStubFromUser builds a member ACL placeholder from account and user models.

func (*Member[TUser, TAccount]) RBACResourceName added in v0.5.0

func (m *Member[TUser, TAccount]) RBACResourceName() string

RBACResourceName is nil-safe.

func (*Member[TUser, TAccount]) TableName added in v0.5.0

func (m *Member[TUser, TAccount]) TableName() string

TableName is nil-safe (used in query builders via (*Member[...])(nil).TableName()).

type MemberFilter

type MemberFilter struct {
	ID        []uint64
	AccountID []uint64
	UserID    []uint64
	NotUserID []uint64
	Status    []pkgModels.ApproveStatus
	IsAdmin   null.Bool
}

MemberFilter of the objects list

func (*MemberFilter) AdjustPermissions added in v0.4.0

func (fl *MemberFilter) AdjustPermissions(ctx context.Context) error

AdjustPermissions narrows the member filter to the current session account. Cannot import pkg/acl or pkg/context/session due to an import cycle; uses the lower-level context sub-packages instead.

func (*MemberFilter) PrepareQuery

func (fl *MemberFilter) PrepareQuery(query *gorm.DB) *gorm.DB

type MemberListOrder

type MemberListOrder struct {
	ID        pkgModels.Order
	AccountID pkgModels.Order
	UserID    pkgModels.Order
	Status    pkgModels.Order
	IsAdmin   pkgModels.Order
	CreatedAt pkgModels.Order
	UpdatedAt pkgModels.Order
}

MemberListOrder of the objects list

func (*MemberListOrder) PrepareQuery

func (ord *MemberListOrder) PrepareQuery(query *gorm.DB) *gorm.DB

type MemberModel added in v0.5.0

type MemberModel interface {
	GetID() uint64
	OwnerAccountID() uint64
}

MemberModel is the compile-time constraint for account member join records.

type MemberRepository added in v0.4.0

type MemberRepository[TUser user.Model, TAccount Model] interface {
	// EmptyObject returns a new empty member object of type Member[TUser, TAccount].
	EmptyObject() *Member[TUser, TAccount]

	// IsAdmin checks if the user is an admin of the account.
	IsAdmin(ctx context.Context, userID, accountID uint64) bool

	// IsMember checks if the user is a member of the account.
	IsMember(ctx context.Context, userID, accountID uint64) bool

	// FetchListMembers retrieves a list of members for the account.
	FetchListMembers(ctx context.Context, opts ...QOption) ([]*Member[TUser, TAccount], error)

	// CountMembers counts the number of members for the account.
	CountMembers(ctx context.Context, opts ...QOption) (int64, error)

	// Member retrieves a member by user ID and account ID.
	Member(ctx context.Context, userID, accountID uint64) (*Member[TUser, TAccount], error)

	// MemberByID retrieves a member by member ID.
	MemberByID(ctx context.Context, id uint64) (*Member[TUser, TAccount], error)

	// LinkMember links users as members to the account with optional admin role.
	LinkMember(ctx context.Context, account TAccount, isAdmin bool, members ...TUser) error

	// UnlinkMember unlinks users from the account.
	UnlinkMember(ctx context.Context, account TAccount, members ...TUser) error

	// UnlinkAccountMember unlinks a member from the account by member ID.
	SetMemberRoles(ctx context.Context, account TAccount, member TUser, roles ...string) error
}

MemberRepository of access to the account members. TUser must be a pointer type implementing user.Model (e.g. consumer-defined User struct).

type MemberUsecase added in v0.4.0

type MemberUsecase[TUser user.Model, TAccount Model] interface {
	// EmptyObject returns a new empty member object of type Member[TUser, TAccount].
	EmptyObject() *Member[TUser, TAccount]

	// FetchListMembers retrieves a list of members based on the provided query options.
	FetchListMembers(ctx context.Context, opts ...QOption) ([]*Member[TUser, TAccount], error)

	// CountMembers returns the total number of members based on the provided query options.
	CountMembers(ctx context.Context, opts ...QOption) (int64, error)

	// LinkMember associates a user with an account, optionally granting admin privileges.
	LinkMember(ctx context.Context, account TAccount, isAdmin bool, members ...TUser) error

	// UnlinkMember removes the association between a user and an account.
	UnlinkMember(ctx context.Context, account TAccount, members ...TUser) error

	// UnlinkAccountMember removes a member from an account based on the member's ID.
	UnlinkAccountMember(ctx context.Context, memberID uint64) error

	// InviteMember sends an invitation to a user to join an account with specified roles.
	InviteMember(ctx context.Context, accountID, userID uint64, roles ...string) (*Member[TUser, TAccount], error)

	// SetAccountMemeberRoles sets the roles for a user within a specific account.
	SetAccountMemeberRoles(ctx context.Context, accountID, userID uint64, roles ...string) (*Member[TUser, TAccount], error)

	// SetMemberRoles sets the roles for a member based on the member's ID.
	SetMemberRoles(ctx context.Context, memberID uint64, roles ...string) (*Member[TUser, TAccount], error)
}

MemberUsecase of the account members

type Model added in v0.5.0

type Model interface {
	auth.IsNillable
	GetID() uint64

	IsAnonymous() bool
	OwnerAccountID() uint64

	GetApprove() pkgModels.ApproveStatus
	GetCreatedAt() time.Time
	GetUpdatedAt() time.Time

	NewWithIDs(id uint64, adminUserIDs ...uint64) Model

	CheckPermissions(ctx context.Context, resource any, patterns ...string) bool
	CheckedPermissions(ctx context.Context, resource any, patterns ...string) rbac.Permission
	IsAdminUser(userID uint64) bool
	IsOwnerUser(userID uint64) bool
	ExtendAdminUsers(ids ...uint64)
	SetPermissions(perm PermissionChecker)
	ExtendPermissions(perm PermissionChecker)
	PermissionsChecker() PermissionChecker
	ListPermissions(patterns ...string) []rbac.Permission
	HasPermission(patterns ...string) bool
}

Model is the compile-time constraint for core account repository/usecase operations. RBACResourceName/TableName stay on concrete structs (used by ACL/GORM), not on this interface.

type Pagination added in v0.4.0

type Pagination = repository.Pagination

Pagination of the objects list

type PermissionChecker added in v0.4.0

type PermissionChecker = models.PermissionChecker

type QOption added in v0.4.0

type QOption = repository.QOption

QOption is the query option interface

type Repository

type Repository[T Model] interface {
	// EmptyObject returns a new empty account object of type T.
	EmptyObject() T

	// Get retrieves an account by ID.
	// Returns ErrNotFound if the account does not exist.
	Get(ctx context.Context, id uint64) (T, error)

	// FetchList retrieves a list of accounts based on the provided query options.
	// Returns an empty slice if no accounts match the criteria.
	FetchList(ctx context.Context, opts ...QOption) ([]T, error)

	// Count returns the number of accounts matching the provided query options.
	Count(ctx context.Context, opts ...QOption) (int64, error)

	// Create creates a new account and returns its ID.
	// Returns an error if the account could not be created.
	Create(ctx context.Context, account T) (uint64, error)

	// Update updates an existing account.
	// Returns an error if the account could not be updated.
	Update(ctx context.Context, id uint64, account T) error

	// Delete deletes an account by ID.
	// Returns an error if the account could not be deleted.
	Delete(ctx context.Context, id uint64) error
}

Repository is the core account CRUD repository parameterized by account model type. T must be a pointer type implementing Model (e.g. consumer-defined Account struct).

type SessionRepository added in v0.5.0

type SessionRepository[TUser user.Model, TAccount Model] interface {
	Repository[TAccount]

	// LoadPermissions loads the permissions for the given user and account.
	LoadPermissions(ctx context.Context, account TAccount, userObj TUser) error

	// GetByToken retrieves the user and account associated with the given session token.
	// Returns ErrInvalidToken if the token is invalid or expired.
	GetByToken(ctx context.Context, token string) (TUser, TAccount, error)
}

SessionRepository extends account repository with auth session helpers.

type Usecase

type Usecase[TUser user.Model, TAccount Model] interface {
	// EmptyObject returns a new empty account object of type TAccount.
	EmptyObject() TAccount

	// Get retrieves an account by ID.
	Get(ctx context.Context, id uint64) (TAccount, error)

	// FetchList retrieves a list of accounts based on the provided query options.
	FetchList(ctx context.Context, opts ...QOption) ([]TAccount, error)

	// Count returns the total number of accounts based on the provided query options.
	Count(ctx context.Context, opts ...QOption) (int64, error)

	// Update modifies an existing account.
	Update(ctx context.Context, account TAccount) (uint64, error)

	// Register creates a new account with the specified owner and account details.
	Register(ctx context.Context, ownerObj TUser, accountObj TAccount) (uint64, error)

	// Delete removes an account by ID.
	Delete(ctx context.Context, id uint64) error
}

Usecase of the account

Directories

Path Synopsis
delivery
graphql/account_login
Package accountlogin provides the email+password login mutation as a schema extension.
Package accountlogin provides the email+password login mutation as a schema extension.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package usecase account implementation
Package usecase account implementation

Jump to

Keyboard shortcuts

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