channelaccess

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package channelaccess wires together the global account binding (channel identity <-> web user) and the per-bot Manage capability, resolving the effective Manage as "local override ?? inherited from bound web member".

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCodeNotFound = errors.New("link code not found")
	ErrCodeExpired  = errors.New("link code expired")
	ErrCodeConsumed = errors.New("link code already used")
	ErrInvalidInput = errors.New("invalid input")
)

Functions

This section is empty.

Types

type Binding

type Binding struct {
	ID                         string    `json:"id"`
	UserID                     string    `json:"user_id"`
	ChannelIdentityID          string    `json:"channel_identity_id"`
	ChannelType                string    `json:"channel_type,omitempty"`
	ChannelSubjectID           string    `json:"channel_subject_id,omitempty"`
	ChannelIdentityDisplayName string    `json:"channel_identity_display_name,omitempty"`
	ChannelIdentityAvatarURL   string    `json:"channel_identity_avatar_url,omitempty"`
	CreatedAt                  time.Time `json:"created_at"`
}

Binding is a global account-level link between a web user and an IM channel identity.

type IssueLinkCodeRequest

type IssueLinkCodeRequest struct {
	ChannelType string `json:"channel_type,omitempty"`
}

IssueLinkCodeRequest is the body for generating a link code.

type LinkCode

type LinkCode struct {
	Token       string    `json:"token"`
	UserID      string    `json:"user_id"`
	ChannelType string    `json:"channel_type,omitempty"`
	ExpiresAt   time.Time `json:"expires_at"`
	CreatedAt   time.Time `json:"created_at"`
}

LinkCode is a one-time code a user generates in the web app and then sends as `/link <code>` to a bot in IM to bind the sending channel identity to their account.

type ListBindingsResponse

type ListBindingsResponse struct {
	Items []Binding `json:"items"`
}

ListBindingsResponse wraps the connected channel identities for a user.

type ListManagersResponse

type ListManagersResponse struct {
	Items []Manager `json:"items"`
}

ListManagersResponse wraps the effective managers of a bot.

type Manager

type Manager struct {
	ChannelIdentityID          string `json:"channel_identity_id"`
	ChannelType                string `json:"channel_type,omitempty"`
	ChannelSubjectID           string `json:"channel_subject_id,omitempty"`
	ChannelIdentityDisplayName string `json:"channel_identity_display_name,omitempty"`
	ChannelIdentityAvatarURL   string `json:"channel_identity_avatar_url,omitempty"`
	// Manage is the effective Manage capability (local override ?? inherited).
	Manage bool `json:"manage"`
	// Inherited reports whether this identity is bound to a web member that carries
	// the Manage capability (owner or workspace manage grant).
	Inherited bool `json:"inherited"`
	// HasOverride reports whether a local Channel Access override exists for it.
	HasOverride bool `json:"has_override"`
	// Bound reports whether this identity is linked to a workspace member of this
	// bot (any permission). It marks the identity as a "platform member" in the UI
	// regardless of whether it carries Manage.
	Bound bool `json:"bound"`
}

Manager is the effective Manage state for a channel identity on a bot, combining the local override (Channel Access) with the inherited grant (bound web member).

type Service

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

func NewService

func NewService(log *slog.Logger, queries dbstore.Queries, aclService *acl.Service, botService *bots.Service) *Service

func (*Service) ClearManagerOverride

func (s *Service) ClearManagerOverride(ctx context.Context, botID, channelIdentityID string) error

ClearManagerOverride removes the local Manage override so the identity falls back to inheritance.

func (*Service) ConsumeLinkCode

func (s *Service) ConsumeLinkCode(ctx context.Context, token, channelIdentityID string) (Binding, error)

ConsumeLinkCode binds the given channel identity to the user that owns the code. It is invoked from the IM /link command with the sender's channel identity.

func (*Service) HasManageGrant

func (s *Service) HasManageGrant(ctx context.Context, botID, channelIdentityID string) (bool, error)

HasManageGrant reports the effective Manage capability for a channel identity on a bot: a local Channel Access override wins; otherwise it is inherited when the identity is bound to a web member that carries Manage (owner or manage grant). It satisfies the command package's ChannelManageResolver.

func (*Service) IssueLinkCode

func (s *Service) IssueLinkCode(ctx context.Context, userID, channelType string) (LinkCode, error)

IssueLinkCode generates a one-time code the user sends as /link <code> in IM.

func (*Service) ListManagers

func (s *Service) ListManagers(ctx context.Context, botID string) ([]Manager, error)

ListManagers returns the effective Manage state per channel identity on a bot, merging inherited members (bound web members carrying Manage) with local overrides.

func (*Service) ListUserBindings

func (s *Service) ListUserBindings(ctx context.Context, userID string) ([]Binding, error)

ListUserBindings returns the channel identities bound to a user's account.

func (*Service) SetManager

func (s *Service) SetManager(ctx context.Context, botID, channelIdentityID string, granted bool, actorUserID string) error

SetManager sets a local Manage override (ON/OFF) for a channel identity on a bot.

func (*Service) Unbind

func (s *Service) Unbind(ctx context.Context, userID, channelIdentityID string) error

Unbind removes a channel identity binding from a user's account.

type SetManagerRequest

type SetManagerRequest struct {
	ChannelIdentityID string `json:"channel_identity_id"`
	// Granted forces Manage ON (true) or OFF (false) locally.
	Granted bool `json:"granted"`
}

SetManagerRequest sets the local Manage override for a channel identity.

Jump to

Keyboard shortcuts

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