snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
231
server/public/pluginapi/team.go
Normal file
231
server/public/pluginapi/team.go
Normal file
@@ -0,0 +1,231 @@
|
||||
package pluginapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
)
|
||||
|
||||
// TeamService exposes methods to manipulate teams and their members.
|
||||
type TeamService struct {
|
||||
api plugin.API
|
||||
}
|
||||
|
||||
// Get gets a team.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) Get(teamID string) (*model.Team, error) {
|
||||
team, appErr := t.api.GetTeam(teamID)
|
||||
|
||||
return team, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// GetByName gets a team by its name.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) GetByName(name string) (*model.Team, error) {
|
||||
team, appErr := t.api.GetTeamByName(name)
|
||||
|
||||
return team, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// TeamListOption is used to filter team listing.
|
||||
type TeamListOption func(*ListTeamsOptions)
|
||||
|
||||
// ListTeamsOptions holds options about filter out team listing.
|
||||
type ListTeamsOptions struct {
|
||||
UserID string
|
||||
}
|
||||
|
||||
// FilterTeamsByUser option is used to filter teams by user.
|
||||
func FilterTeamsByUser(userID string) TeamListOption {
|
||||
return func(o *ListTeamsOptions) {
|
||||
o.UserID = userID
|
||||
}
|
||||
}
|
||||
|
||||
// List gets a list of teams by options.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
// Minimum server version when LimitTeamsToUser() option is used: 5.6
|
||||
func (t *TeamService) List(options ...TeamListOption) ([]*model.Team, error) {
|
||||
opts := ListTeamsOptions{}
|
||||
for _, o := range options {
|
||||
o(&opts)
|
||||
}
|
||||
|
||||
var teams []*model.Team
|
||||
var appErr *model.AppError
|
||||
if opts.UserID != "" {
|
||||
teams, appErr = t.api.GetTeamsForUser(opts.UserID)
|
||||
} else {
|
||||
teams, appErr = t.api.GetTeams()
|
||||
}
|
||||
|
||||
return teams, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// Search search a team.
|
||||
//
|
||||
// Minimum server version: 5.8
|
||||
func (t *TeamService) Search(term string) ([]*model.Team, error) {
|
||||
teams, appErr := t.api.SearchTeams(term)
|
||||
|
||||
return teams, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// Create creates a team.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) Create(team *model.Team) error {
|
||||
createdTeam, appErr := t.api.CreateTeam(team)
|
||||
if appErr != nil {
|
||||
return normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
*team = *createdTeam
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates a team.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) Update(team *model.Team) error {
|
||||
updatedTeam, appErr := t.api.UpdateTeam(team)
|
||||
if appErr != nil {
|
||||
return normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
*team = *updatedTeam
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a team.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) Delete(teamID string) error {
|
||||
return normalizeAppErr(t.api.DeleteTeam(teamID))
|
||||
}
|
||||
|
||||
// GetIcon gets the team icon.
|
||||
//
|
||||
// Minimum server version: 5.6
|
||||
func (t *TeamService) GetIcon(teamID string) (io.Reader, error) {
|
||||
contentBytes, appErr := t.api.GetTeamIcon(teamID)
|
||||
if appErr != nil {
|
||||
return nil, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
return bytes.NewReader(contentBytes), nil
|
||||
}
|
||||
|
||||
// SetIcon sets the team icon.
|
||||
//
|
||||
// Minimum server version: 5.6
|
||||
func (t *TeamService) SetIcon(teamID string, content io.Reader) error {
|
||||
contentBytes, err := io.ReadAll(content)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return normalizeAppErr(t.api.SetTeamIcon(teamID, contentBytes))
|
||||
}
|
||||
|
||||
// DeleteIcon removes the team icon.
|
||||
//
|
||||
// Minimum server version: 5.6
|
||||
func (t *TeamService) DeleteIcon(teamID string) error {
|
||||
return normalizeAppErr(t.api.RemoveTeamIcon(teamID))
|
||||
}
|
||||
|
||||
// GetUsers lists users of the team.
|
||||
//
|
||||
// Minimum server version: 5.6
|
||||
func (t *TeamService) ListUsers(teamID string, page, count int) ([]*model.User, error) {
|
||||
users, appErr := t.api.GetUsersInTeam(teamID, page, count)
|
||||
|
||||
return users, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// ListUnreadForUser gets the unread message and mention counts for each team to which the given user belongs.
|
||||
//
|
||||
// Minimum server version: 5.6
|
||||
func (t *TeamService) ListUnreadForUser(userID string) ([]*model.TeamUnread, error) {
|
||||
teamUnreads, appErr := t.api.GetTeamsUnreadForUser(userID)
|
||||
|
||||
return teamUnreads, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// GetMember returns a specific membership.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) GetMember(teamID, userID string) (*model.TeamMember, error) {
|
||||
teamMember, appErr := t.api.GetTeamMember(teamID, userID)
|
||||
|
||||
return teamMember, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// ListMembers returns the memberships of a specific team.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) ListMembers(teamID string, page, perPage int) ([]*model.TeamMember, error) {
|
||||
teamMembers, appErr := t.api.GetTeamMembers(teamID, page, perPage)
|
||||
|
||||
return teamMembers, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// ListMembersForUser returns all team memberships for a user.
|
||||
//
|
||||
// Minimum server version: 5.10
|
||||
func (t *TeamService) ListMembersForUser(userID string, page, perPage int) ([]*model.TeamMember, error) {
|
||||
teamMembers, appErr := t.api.GetTeamMembersForUser(userID, page, perPage)
|
||||
|
||||
return teamMembers, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// CreateMember creates a team membership.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) CreateMember(teamID, userID string) (*model.TeamMember, error) {
|
||||
teamMember, appErr := t.api.CreateTeamMember(teamID, userID)
|
||||
|
||||
return teamMember, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// CreateMembers creates a team membership for all provided user ids.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) CreateMembers(teamID string, userIDs []string, requestorID string) ([]*model.TeamMember, error) {
|
||||
teamMembers, appErr := t.api.CreateTeamMembers(teamID, userIDs, requestorID)
|
||||
|
||||
return teamMembers, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// DeleteMember deletes a team membership.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) DeleteMember(teamID, userID, requestorID string) error {
|
||||
return normalizeAppErr(t.api.DeleteTeamMember(teamID, userID, requestorID))
|
||||
}
|
||||
|
||||
// UpdateMemberRoles updates the role for a team membership.
|
||||
//
|
||||
// Minimum server version: 5.2
|
||||
func (t *TeamService) UpdateMemberRoles(teamID, userID, newRoles string) (*model.TeamMember, error) {
|
||||
teamMember, appErr := t.api.UpdateTeamMemberRoles(teamID, userID, newRoles)
|
||||
|
||||
return teamMember, normalizeAppErr(appErr)
|
||||
}
|
||||
|
||||
// GetStats gets a team's statistics
|
||||
//
|
||||
// Minimum server version: 5.8
|
||||
func (t *TeamService) GetStats(teamID string) (*model.TeamStats, error) {
|
||||
teamStats, appErr := t.api.GetTeamStats(teamID)
|
||||
|
||||
return teamStats, normalizeAppErr(appErr)
|
||||
}
|
||||
Reference in New Issue
Block a user