mmapi

package
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 14 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

Index

Constants

This section is empty.

Variables

View Source
var ErrFileActionForbidden = errors.New("file action is not permitted")

ErrFileActionForbidden is returned before an admin-level file read when the requesting session is absent or denied by the server's file policy.

View Source
var ErrFileChannelForbidden = errors.New("user cannot read the channel the file belongs to")

ErrFileChannelForbidden is returned when a user can no longer read the channel a stored file belongs to.

View Source
var ErrKVNotFound = errors.New("kv key not found")

ErrKVNotFound disambiguates a missing key from a present-but-zero value: upstream pluginapi.KV.Get returns (nil err, empty bytes) for missing keys.

Functions

func CheckFileChannelRead added in v2.12.0

func CheckFileChannelRead(mm Client, userID string, fileInfo *model.FileInfo) error

CheckFileChannelRead fails closed unless userID may read the channel fileInfo belongs to. Download policy is a separate, session-scoped check (see WithFilePolicy); both must pass before stored file content is reused.

func GetReadableFileInfo added in v2.12.0

func GetReadableFileInfo(mm Client, sessionID, userID, fileID string) (*model.FileInfo, error)

GetReadableFileInfo returns fileID's metadata only when sessionID may download the file and userID may still read its channel.

func IsDMWith

func IsDMWith(userID string, channel *model.Channel) bool

func IsKVNotFound

func IsKVNotFound(err error) bool

func IsNotFound added in v2.11.0

func IsNotFound(err error) bool

IsNotFound reports whether err says the requested Mattermost object does not exist, as opposed to failing to look it up.

Types

type Client

type Client interface {
	GetUser(userID string) (*model.User, error)
	GetPost(postID string) (*model.Post, error)
	AddReaction(*model.Reaction) error
	GetPostThread(postID string) (*model.PostList, error)
	GetPostsSince(channelID string, since int64) (*model.PostList, error)
	GetPostsBefore(channelID, postID string, page, perPage int) (*model.PostList, error)
	CreatePost(post *model.Post) error
	UpdatePost(post *model.Post) error
	DM(senderID, receiverID string, post *model.Post) error
	GetTeam(teamID string) (*model.Team, error)
	GetChannel(channelID string) (*model.Channel, error)
	GetDirectChannel(userID1, userID2 string) (*model.Channel, error)
	PublishWebSocketEvent(event string, payload map[string]any, broadcast *model.WebsocketBroadcast)
	GetConfig() *model.Config
	LogError(msg string, keyValuePairs ...any)
	LogWarn(msg string, keyValuePairs ...any)
	KVGet(key string, value any) error
	KVSet(key string, value any) error
	KVSetWithExpiry(key string, value any, ttl time.Duration) error
	KVCompareAndSet(key string, oldValue, newValue any) (bool, error)
	KVCompareAndSetWithExpiry(key string, oldValue, newValue any, ttl time.Duration) (bool, error)
	KVDelete(key string) error
	GetUserByUsername(username string) (*model.User, error)
	GetUserStatus(userID string) (*model.Status, error)
	HasPermissionTo(userID string, permission *model.Permission) bool
	GetPluginStatus(pluginID string) (*model.PluginStatus, error)
	PluginHTTP(req *http.Request) *http.Response
	LogDebug(msg string, keyValuePairs ...any)
	GetChannelByName(teamID, name string, includeDeleted bool) (*model.Channel, error)
	HasPermissionToChannel(userID, channelID string, permission *model.Permission) bool
	HasPermissionToFileAction(sessionID, fileID, action string) bool
	GetFileInfo(fileID string) (*model.FileInfo, error)
	GetFile(fileID string) (io.ReadCloser, error)
	UploadFile(content io.Reader, fileName, channelID string) (*model.FileInfo, error)
	SendEphemeralPost(userID string, post *model.Post)
}

func NewClient

func NewClient(pluginAPI *pluginapi.Client, fileActionAPI ...FileActionPermissionAPI) Client

func WithFilePolicy added in v2.5.4

func WithFilePolicy(mm Client, sessionID string) Client

WithFilePolicy returns a Client whose GetFile and GetFileInfo calls are gated by the requesting session's download-file policy. Other methods delegate unchanged. An empty or denied session fails closed.

type DBClient

type DBClient struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

func NewDBClient

func NewDBClient(pluginAPI *pluginapi.Client) *DBClient

NewDBClient creates the DB part of the client, only supported on postgres, panics on failures.

func NewTestDBClient

func NewTestDBClient(db *sqlx.DB) *DBClient

NewTestDBClient creates a DBClient for testing purposes using a raw sqlx.DB connection. This bypasses the plugin API requirement for test environments.

func (*DBClient) Builder

func (db *DBClient) Builder() sq.StatementBuilderType

func (*DBClient) DoQuery

func (db *DBClient) DoQuery(dest any, b builder) error

func (*DBClient) ExecBuilder

func (db *DBClient) ExecBuilder(b builder) (sql.Result, error)

func (*DBClient) GetFirstPostBeforeTimeRangeID

func (db *DBClient) GetFirstPostBeforeTimeRangeID(channelID string, startTime, endTime int64) (string, error)

type FileActionPermissionAPI added in v2.5.4

type FileActionPermissionAPI interface {
	HasPermissionToFileAction(sessionID, fileID, action string) bool
}

FileActionPermissionAPI is the narrow raw plugin API surface needed to enforce session-scoped file download policy.

type ThreadData

type ThreadData struct {
	Posts     []*model.Post
	UsersByID map[string]*model.User
}

func GetMetadataForPosts

func GetMetadataForPosts(client Client, posts *model.PostList) (*ThreadData, error)

func GetThreadData

func GetThreadData(client Client, postID string) (*ThreadData, error)

func (*ThreadData) CutoffBeforePostID

func (t *ThreadData) CutoffBeforePostID(postID string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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