2019-11-29 06:59:40 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
2017-11-27 17:23:35 -05:00
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
2018-11-15 15:23:03 -05:00
|
|
|
"bytes"
|
2017-11-27 17:23:35 -05:00
|
|
|
"encoding/json"
|
2024-01-09 06:42:11 -05:00
|
|
|
"errors"
|
2018-06-27 08:46:38 -04:00
|
|
|
"fmt"
|
2019-10-17 14:57:55 -04:00
|
|
|
"io"
|
2018-07-16 15:49:26 -04:00
|
|
|
"net/http"
|
2019-11-04 20:35:58 -05:00
|
|
|
"net/url"
|
2019-03-18 18:01:26 -04:00
|
|
|
"path/filepath"
|
2021-10-20 06:12:58 -04:00
|
|
|
"strconv"
|
2018-07-09 10:25:57 -04:00
|
|
|
"strings"
|
2017-11-27 17:23:35 -05:00
|
|
|
|
2023-06-11 01:24:35 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
|
|
|
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
|
|
|
|
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
2023-09-05 03:47:30 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/shared/request"
|
2017-11-27 17:23:35 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PluginAPI struct {
|
2018-07-09 10:25:57 -04:00
|
|
|
id string
|
|
|
|
|
app *App
|
2023-10-30 11:33:37 -04:00
|
|
|
ctx request.CTX
|
2021-08-17 16:08:04 -04:00
|
|
|
logger mlog.Sugar
|
2018-07-09 10:25:57 -04:00
|
|
|
manifest *model.Manifest
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2025-09-10 09:11:32 -04:00
|
|
|
func NewPluginAPI(a *App, rctx request.CTX, manifest *model.Manifest) *PluginAPI {
|
2018-06-25 15:33:13 -04:00
|
|
|
return &PluginAPI{
|
2018-07-09 10:25:57 -04:00
|
|
|
id: manifest.Id,
|
|
|
|
|
manifest: manifest,
|
2025-09-10 09:11:32 -04:00
|
|
|
ctx: rctx,
|
2018-07-09 10:25:57 -04:00
|
|
|
app: a,
|
2021-08-17 16:08:04 -04:00
|
|
|
logger: a.Log().Sugar(mlog.String("plugin_id", manifest.Id)),
|
2018-06-25 15:33:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 12:00:15 -04:00
|
|
|
func (api *PluginAPI) checkLDAPLicense() error {
|
|
|
|
|
license := api.GetLicense()
|
|
|
|
|
if license == nil || !*license.Features.LDAPGroups {
|
|
|
|
|
return fmt.Errorf("license does not support LDAP groups")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func (api *PluginAPI) LoadPluginConfiguration(dest any) error {
|
|
|
|
|
finalConfig := make(map[string]any)
|
2018-07-09 10:25:57 -04:00
|
|
|
|
|
|
|
|
// First set final config to defaults
|
2018-07-10 10:52:57 -04:00
|
|
|
if api.manifest.SettingsSchema != nil {
|
|
|
|
|
for _, setting := range api.manifest.SettingsSchema.Settings {
|
|
|
|
|
finalConfig[strings.ToLower(setting.Key)] = setting.Default
|
|
|
|
|
}
|
2018-07-09 10:25:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we have settings given we override the defaults with them
|
|
|
|
|
for setting, value := range api.app.Config().PluginSettings.Plugins[api.id] {
|
|
|
|
|
finalConfig[strings.ToLower(setting)] = value
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 10:50:47 -05:00
|
|
|
pluginSettingsJsonBytes, err := json.Marshal(finalConfig)
|
|
|
|
|
if err != nil {
|
2018-07-27 08:25:53 -04:00
|
|
|
api.logger.Error("Error marshaling config for plugin", mlog.Err(err))
|
|
|
|
|
return nil
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
2020-12-21 10:50:47 -05:00
|
|
|
err = json.Unmarshal(pluginSettingsJsonBytes, dest)
|
|
|
|
|
if err != nil {
|
|
|
|
|
api.logger.Error("Error unmarshaling config for plugin", mlog.Err(err))
|
|
|
|
|
}
|
|
|
|
|
return nil
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2017-12-08 14:55:41 -05:00
|
|
|
func (api *PluginAPI) RegisterCommand(command *model.Command) error {
|
|
|
|
|
return api.app.RegisterPluginCommand(api.id, command)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) UnregisterCommand(teamID, trigger string) error {
|
|
|
|
|
api.app.UnregisterPluginCommand(api.id, teamID, trigger)
|
2017-12-08 14:55:41 -05:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 12:31:03 -04:00
|
|
|
func (api *PluginAPI) ExecuteSlashCommand(commandArgs *model.CommandArgs) (*model.CommandResponse, error) {
|
|
|
|
|
user, appErr := api.app.GetUser(commandArgs.UserId)
|
|
|
|
|
if appErr != nil {
|
|
|
|
|
return nil, appErr
|
|
|
|
|
}
|
2021-02-26 02:12:49 -05:00
|
|
|
commandArgs.T = i18n.GetUserTranslations(user.Locale)
|
2020-07-07 12:31:03 -04:00
|
|
|
commandArgs.SiteURL = api.app.GetSiteURL()
|
2021-05-11 06:00:44 -04:00
|
|
|
response, appErr := api.app.ExecuteCommand(api.ctx, commandArgs)
|
2020-07-07 12:31:03 -04:00
|
|
|
if appErr != nil {
|
|
|
|
|
return response, appErr
|
|
|
|
|
}
|
|
|
|
|
return response, nil
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-06 18:32:55 -04:00
|
|
|
func (api *PluginAPI) GetConfig() *model.Config {
|
2019-02-12 08:37:54 -05:00
|
|
|
return api.app.GetSanitizedConfig()
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2019-09-03 18:41:52 -04:00
|
|
|
// GetUnsanitizedConfig gets the configuration for a system admin without removing secrets.
|
|
|
|
|
func (api *PluginAPI) GetUnsanitizedConfig() *model.Config {
|
|
|
|
|
return api.app.Config().Clone()
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-06 18:32:55 -04:00
|
|
|
func (api *PluginAPI) SaveConfig(config *model.Config) *model.AppError {
|
2021-05-21 03:04:39 -04:00
|
|
|
_, _, err := api.app.SaveConfig(config, true)
|
|
|
|
|
return err
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func (api *PluginAPI) GetPluginConfig() map[string]any {
|
2019-02-12 08:37:54 -05:00
|
|
|
cfg := api.app.GetSanitizedConfig()
|
2018-11-19 12:27:15 -05:00
|
|
|
if pluginConfig, isOk := cfg.PluginSettings.Plugins[api.manifest.Id]; isOk {
|
|
|
|
|
return pluginConfig
|
|
|
|
|
}
|
2022-07-05 02:46:50 -04:00
|
|
|
return map[string]any{}
|
2018-11-19 12:27:15 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func (api *PluginAPI) SavePluginConfig(pluginConfig map[string]any) *model.AppError {
|
2025-12-12 15:45:51 -05:00
|
|
|
cfg := api.app.Config().Clone()
|
2018-11-19 12:27:15 -05:00
|
|
|
cfg.PluginSettings.Plugins[api.manifest.Id] = pluginConfig
|
2021-05-21 03:04:39 -04:00
|
|
|
_, _, err := api.app.SaveConfig(cfg, true)
|
|
|
|
|
return err
|
2018-11-19 12:27:15 -05:00
|
|
|
}
|
|
|
|
|
|
2019-03-18 18:01:26 -04:00
|
|
|
func (api *PluginAPI) GetBundlePath() (string, error) {
|
|
|
|
|
bundlePath, err := filepath.Abs(filepath.Join(*api.GetConfig().PluginSettings.Directory, api.manifest.Id))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bundlePath, err
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 12:31:47 -04:00
|
|
|
func (api *PluginAPI) GetLicense() *model.License {
|
2020-06-12 07:43:50 -04:00
|
|
|
return api.app.Srv().License()
|
2019-03-13 12:31:47 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-20 06:12:58 -04:00
|
|
|
func (api *PluginAPI) IsEnterpriseReady() bool {
|
|
|
|
|
result, _ := strconv.ParseBool(model.BuildEnterpriseReady)
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 12:56:47 -04:00
|
|
|
func (api *PluginAPI) GetServerVersion() string {
|
|
|
|
|
return model.CurrentVersion
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 12:31:47 -04:00
|
|
|
func (api *PluginAPI) GetSystemInstallDate() (int64, *model.AppError) {
|
2022-10-06 04:04:21 -04:00
|
|
|
return api.app.Srv().Platform().GetSystemInstallDate()
|
2019-03-13 12:31:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetDiagnosticId() string {
|
2025-09-04 14:46:18 -04:00
|
|
|
return api.app.ServerId()
|
2020-09-08 14:30:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetTelemetryId() string {
|
2025-09-04 14:46:18 -04:00
|
|
|
return api.app.ServerId()
|
2019-03-13 12:31:47 -04:00
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) CreateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.CreateTeam(api.ctx, team)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) DeleteTeam(teamID string) *model.AppError {
|
|
|
|
|
return api.app.SoftDeleteTeam(teamID)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2018-07-06 18:32:55 -04:00
|
|
|
func (api *PluginAPI) GetTeams() ([]*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.GetAllTeams()
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetTeam(teamID string) (*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.GetTeam(teamID)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2019-01-16 03:13:15 -05:00
|
|
|
func (api *PluginAPI) SearchTeams(term string) ([]*model.Team, *model.AppError) {
|
2019-11-28 08:11:02 -05:00
|
|
|
teams, _, err := api.app.SearchAllTeams(&model.TeamSearch{Term: term})
|
|
|
|
|
return teams, err
|
2019-01-16 03:13:15 -05:00
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) GetTeamByName(name string) (*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.GetTeamByName(name)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetTeamsUnreadForUser(userID string) ([]*model.TeamUnread, *model.AppError) {
|
2021-07-22 10:24:20 -04:00
|
|
|
return api.app.GetTeamsUnreadForUser("", userID, false)
|
2018-11-07 14:23:02 -05:00
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.UpdateTeam(team)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetTeamsForUser(userID string) ([]*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.GetTeamsForUser(userID)
|
2018-10-17 10:37:52 -04:00
|
|
|
}
|
|
|
|
|
|
2025-06-25 20:37:32 -04:00
|
|
|
func (api *PluginAPI) LogAuditRec(rec *model.AuditRecord) {
|
|
|
|
|
api.LogAuditRecWithLevel(rec, mlog.LvlAuditCLI)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) LogAuditRecWithLevel(rec *model.AuditRecord, level mlog.Level) {
|
|
|
|
|
if rec == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure the plugin_id is always logged with the correct ID
|
|
|
|
|
model.AddEventParameterToAuditRec(rec, "plugin_id", api.id)
|
|
|
|
|
|
|
|
|
|
api.app.Srv().Audit.LogRecord(level, *rec)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) CreateTeamMember(teamID, userID string) (*model.TeamMember, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.AddTeamMember(api.ctx, teamID, userID)
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) CreateTeamMembers(teamID string, userIDs []string, requestorId string) ([]*model.TeamMember, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
members, err := api.app.AddTeamMembers(api.ctx, teamID, userIDs, requestorId, false)
|
2020-01-14 08:29:50 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return model.TeamMembersWithErrorToTeamMembers(members), nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) CreateTeamMembersGracefully(teamID string, userIDs []string, requestorId string) ([]*model.TeamMemberWithError, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.AddTeamMembers(api.ctx, teamID, userIDs, requestorId, true)
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) DeleteTeamMember(teamID, userID, requestorId string) *model.AppError {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.RemoveUserFromTeam(api.ctx, teamID, userID, requestorId)
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetTeamMembers(teamID string, page, perPage int) ([]*model.TeamMember, *model.AppError) {
|
|
|
|
|
return api.app.GetTeamMembers(teamID, page*perPage, perPage, nil)
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetTeamMember(teamID, userID string) (*model.TeamMember, *model.AppError) {
|
2023-10-11 07:08:55 -04:00
|
|
|
return api.app.GetTeamMember(api.ctx, teamID, userID)
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetTeamMembersForUser(userID string, page int, perPage int) ([]*model.TeamMember, *model.AppError) {
|
|
|
|
|
return api.app.GetTeamMembersForUserWithPagination(userID, page, perPage)
|
2019-02-23 14:41:19 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) UpdateTeamMemberRoles(teamID, userID, newRoles string) (*model.TeamMember, *model.AppError) {
|
2023-10-11 07:08:55 -04:00
|
|
|
return api.app.UpdateTeamMemberRoles(api.ctx, teamID, userID, newRoles)
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetTeamStats(teamID string) (*model.TeamStats, *model.AppError) {
|
|
|
|
|
return api.app.GetTeamStats(teamID, nil)
|
2019-01-15 04:22:04 -05:00
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) CreateUser(user *model.User) (*model.User, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.CreateUser(api.ctx, user)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) DeleteUser(userID string) *model.AppError {
|
|
|
|
|
user, err := api.app.GetUser(userID)
|
2017-11-27 17:23:35 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2021-05-11 06:00:44 -04:00
|
|
|
_, err = api.app.UpdateActive(api.ctx, user, false)
|
2017-11-27 17:23:35 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-30 12:55:02 -05:00
|
|
|
func (api *PluginAPI) GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError) {
|
2022-05-06 12:23:29 -04:00
|
|
|
return api.app.GetUsersFromProfiles(options)
|
2019-01-30 12:55:02 -05:00
|
|
|
}
|
|
|
|
|
|
2024-05-15 10:06:40 -04:00
|
|
|
func (api *PluginAPI) GetUsersByIds(usersID []string) ([]*model.User, *model.AppError) {
|
2025-09-18 10:14:24 -04:00
|
|
|
return api.app.GetUsers(api.ctx, usersID)
|
2024-05-15 10:06:40 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetUser(userID string) (*model.User, *model.AppError) {
|
|
|
|
|
return api.app.GetUser(userID)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetUserByEmail(email string) (*model.User, *model.AppError) {
|
|
|
|
|
return api.app.GetUserByEmail(email)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetUserByUsername(name string) (*model.User, *model.AppError) {
|
|
|
|
|
return api.app.GetUserByUsername(name)
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 11:54:10 -04:00
|
|
|
func (api *PluginAPI) GetUserByRemoteID(remoteID string) (*model.User, *model.AppError) {
|
|
|
|
|
return api.app.GetUserByRemoteID(remoteID)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 09:11:30 -04:00
|
|
|
func (api *PluginAPI) GetUsersByUsernames(usernames []string) ([]*model.User, *model.AppError) {
|
2019-04-29 10:56:56 -04:00
|
|
|
return api.app.GetUsersByUsernames(usernames, true, nil)
|
2018-10-18 09:11:30 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetUsersInTeam(teamID string, page int, perPage int) ([]*model.User, *model.AppError) {
|
|
|
|
|
options := &model.UserGetOptions{InTeamId: teamID, Page: page, PerPage: perPage}
|
2019-01-11 08:50:32 -05:00
|
|
|
return api.app.GetUsersInTeam(options)
|
2018-10-15 12:24:26 -04:00
|
|
|
}
|
|
|
|
|
|
2024-01-04 13:50:19 -05:00
|
|
|
func (api *PluginAPI) GetPreferenceForUser(userID, category, name string) (model.Preference, *model.AppError) {
|
|
|
|
|
pref, err := api.app.GetPreferenceByCategoryAndNameForUser(api.ctx, userID, category, name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return model.Preference{}, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return *pref, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetPreferencesForUser(userID string) ([]model.Preference, *model.AppError) {
|
2024-01-03 12:25:53 -05:00
|
|
|
return api.app.GetPreferencesForUser(api.ctx, userID)
|
2020-05-28 13:15:47 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) UpdatePreferencesForUser(userID string, preferences []model.Preference) *model.AppError {
|
2024-01-03 12:25:53 -05:00
|
|
|
return api.app.UpdatePreferences(api.ctx, userID, preferences)
|
2020-05-28 13:15:47 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) DeletePreferencesForUser(userID string, preferences []model.Preference) *model.AppError {
|
2024-01-03 12:25:53 -05:00
|
|
|
return api.app.DeletePreferences(api.ctx, userID, preferences)
|
2020-05-28 13:15:47 -04:00
|
|
|
}
|
|
|
|
|
|
2021-11-16 09:08:20 -05:00
|
|
|
func (api *PluginAPI) GetSession(sessionID string) (*model.Session, *model.AppError) {
|
2023-10-11 07:08:55 -04:00
|
|
|
return api.app.GetSessionById(api.ctx, sessionID)
|
2021-11-16 09:08:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) CreateSession(session *model.Session) (*model.Session, *model.AppError) {
|
2023-10-11 07:08:55 -04:00
|
|
|
return api.app.CreateSession(api.ctx, session)
|
2021-11-16 09:08:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) ExtendSessionExpiry(sessionID string, expiresAt int64) *model.AppError {
|
2023-10-11 07:08:55 -04:00
|
|
|
session, err := api.app.ch.srv.platform.GetSessionByID(api.ctx, sessionID)
|
2022-03-15 12:38:09 -04:00
|
|
|
if err != nil {
|
2022-08-18 05:01:37 -04:00
|
|
|
return model.NewAppError("extendSessionExpiry", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
2022-03-15 12:38:09 -04:00
|
|
|
}
|
|
|
|
|
|
2022-10-06 04:04:21 -04:00
|
|
|
if err := api.app.ch.srv.platform.ExtendSessionExpiry(session, expiresAt); err != nil {
|
2022-08-18 05:01:37 -04:00
|
|
|
return model.NewAppError("extendSessionExpiry", "app.session.extend_session_expiry.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
2022-03-15 12:38:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
2021-11-16 09:08:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) RevokeSession(sessionID string) *model.AppError {
|
2023-10-11 07:08:55 -04:00
|
|
|
return api.app.RevokeSessionById(api.ctx, sessionID)
|
2021-11-16 09:08:20 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-14 09:08:22 -04:00
|
|
|
func (api *PluginAPI) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError) {
|
2024-04-24 05:52:33 -04:00
|
|
|
return api.app.CreateUserAccessToken(api.ctx, token)
|
2021-07-14 09:08:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) RevokeUserAccessToken(tokenID string) *model.AppError {
|
|
|
|
|
accessToken, err := api.app.GetUserAccessToken(tokenID, false)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 07:08:55 -04:00
|
|
|
return api.app.RevokeUserAccessToken(api.ctx, accessToken)
|
2021-07-14 09:08:22 -04:00
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) {
|
2022-07-28 00:34:21 -04:00
|
|
|
return api.app.UpdateUser(api.ctx, user, true)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2023-11-10 20:55:33 -05:00
|
|
|
func (api *PluginAPI) UpdateUserAuth(userID string, userAuth *model.UserAuth) (*model.UserAuth, *model.AppError) {
|
|
|
|
|
return api.app.UpdateUserAuth(api.ctx, userID, userAuth)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) UpdateUserActive(userID string, active bool) *model.AppError {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.UpdateUserActive(api.ctx, userID, active)
|
2018-12-12 10:18:41 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetUserStatus(userID string) (*model.Status, *model.AppError) {
|
|
|
|
|
return api.app.GetStatus(userID)
|
2018-07-16 15:49:26 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetUserStatusesByIds(userIDs []string) ([]*model.Status, *model.AppError) {
|
|
|
|
|
return api.app.GetUserStatusesByIds(userIDs)
|
2018-07-16 15:49:26 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) UpdateUserStatus(userID, status string) (*model.Status, *model.AppError) {
|
2018-07-16 15:49:26 -04:00
|
|
|
switch status {
|
2021-07-12 14:05:36 -04:00
|
|
|
case model.StatusOnline:
|
2021-02-05 05:22:27 -05:00
|
|
|
api.app.SetStatusOnline(userID, true)
|
2021-07-12 14:05:36 -04:00
|
|
|
case model.StatusOffline:
|
2025-05-29 04:41:14 -04:00
|
|
|
api.app.SetStatusOffline(userID, true, false)
|
2021-07-12 14:05:36 -04:00
|
|
|
case model.StatusAway:
|
2021-02-05 05:22:27 -05:00
|
|
|
api.app.SetStatusAwayIfNeeded(userID, true)
|
2021-07-12 14:05:36 -04:00
|
|
|
case model.StatusDnd:
|
2021-02-05 05:22:27 -05:00
|
|
|
api.app.SetStatusDoNotDisturb(userID)
|
2018-07-16 15:49:26 -04:00
|
|
|
default:
|
|
|
|
|
return nil, model.NewAppError("UpdateUserStatus", "plugin.api.update_user_status.bad_status", nil, "unrecognized status", http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
return api.app.GetStatus(userID)
|
2018-07-16 15:49:26 -04:00
|
|
|
}
|
2018-10-22 08:49:50 -04:00
|
|
|
|
2021-06-16 14:38:26 -04:00
|
|
|
func (api *PluginAPI) SetUserStatusTimedDND(userID string, endTime int64) (*model.Status, *model.AppError) {
|
|
|
|
|
// read-after-write bug which will fail if there are replicas.
|
|
|
|
|
// it works for now because we have a cache in between.
|
|
|
|
|
// FIXME: make SetStatusDoNotDisturbTimed return updated status
|
|
|
|
|
api.app.SetStatusDoNotDisturbTimed(userID, endTime)
|
|
|
|
|
return api.app.GetStatus(userID)
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 11:11:20 -05:00
|
|
|
func (api *PluginAPI) UpdateUserCustomStatus(userID string, customStatus *model.CustomStatus) *model.AppError {
|
2022-07-28 00:34:21 -04:00
|
|
|
return api.app.SetCustomStatus(api.ctx, userID, customStatus)
|
2021-11-10 11:11:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) RemoveUserCustomStatus(userID string) *model.AppError {
|
2022-07-28 00:34:21 -04:00
|
|
|
return api.app.RemoveCustomStatus(api.ctx, userID)
|
2021-11-10 11:11:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetUserCustomStatus(userID string) (*model.CustomStatus, *model.AppError) {
|
|
|
|
|
return api.app.GetCustomStatus(userID)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetUsersInChannel(channelID, sortBy string, page, perPage int) ([]*model.User, *model.AppError) {
|
2018-10-22 08:49:50 -04:00
|
|
|
switch sortBy {
|
2021-07-12 14:05:36 -04:00
|
|
|
case model.ChannelSortByUsername:
|
2020-09-16 04:04:17 -04:00
|
|
|
return api.app.GetUsersInChannel(&model.UserGetOptions{
|
2021-02-25 14:22:27 -05:00
|
|
|
InChannelId: channelID,
|
2020-09-16 04:04:17 -04:00
|
|
|
Page: page,
|
|
|
|
|
PerPage: perPage,
|
|
|
|
|
})
|
2021-07-12 14:05:36 -04:00
|
|
|
case model.ChannelSortByStatus:
|
2020-09-16 04:04:17 -04:00
|
|
|
return api.app.GetUsersInChannelByStatus(&model.UserGetOptions{
|
2021-02-25 14:22:27 -05:00
|
|
|
InChannelId: channelID,
|
2020-09-16 04:04:17 -04:00
|
|
|
Page: page,
|
|
|
|
|
PerPage: perPage,
|
|
|
|
|
})
|
2018-10-22 08:49:50 -04:00
|
|
|
default:
|
|
|
|
|
return nil, model.NewAppError("GetUsersInChannel", "plugin.api.get_users_in_channel", nil, "invalid sort option", http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetLDAPUserAttributes(userID string, attributes []string) (map[string]string, *model.AppError) {
|
2020-02-13 07:26:58 -05:00
|
|
|
if api.app.Ldap() == nil {
|
2018-08-29 14:07:27 -04:00
|
|
|
return nil, model.NewAppError("GetLdapUserAttributes", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
user, err := api.app.GetUser(userID)
|
2018-08-29 14:07:27 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 08:36:35 -04:00
|
|
|
if user.AuthData == nil {
|
2018-08-29 14:07:27 -04:00
|
|
|
return map[string]string{}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 08:36:35 -04:00
|
|
|
// Only bother running the query if the user's auth service is LDAP or it's SAML and sync is enabled.
|
2021-07-12 14:05:36 -04:00
|
|
|
if user.AuthService == model.UserAuthServiceLdap ||
|
|
|
|
|
(user.AuthService == model.UserAuthServiceSaml && *api.app.Config().SamlSettings.EnableSyncWithLdap) {
|
2023-11-03 03:06:16 -04:00
|
|
|
return api.app.Ldap().GetUserAttributes(api.ctx, *user.AuthData, attributes)
|
2019-03-26 08:36:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return map[string]string{}, nil
|
2018-08-29 14:07:27 -04:00
|
|
|
}
|
2018-07-16 15:49:26 -04:00
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.CreateChannel(api.ctx, channel, false)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) DeleteChannel(channelID string) *model.AppError {
|
2022-07-14 05:01:29 -04:00
|
|
|
channel, err := api.app.GetChannel(api.ctx, channelID)
|
2017-11-27 17:23:35 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.DeleteChannel(api.ctx, channel, "")
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetPublicChannelsForTeam(teamID string, page, perPage int) ([]*model.Channel, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
channels, err := api.app.GetPublicChannelsForTeam(api.ctx, teamID, page*perPage, perPage)
|
2018-11-20 08:50:34 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2021-08-17 05:18:33 -04:00
|
|
|
return channels, err
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetChannel(channelID string) (*model.Channel, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.GetChannel(api.ctx, channelID)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetChannelByName(teamID, name string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.GetChannelByName(api.ctx, name, teamID, includeDeleted)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2018-07-30 15:06:08 -04:00
|
|
|
func (api *PluginAPI) GetChannelByNameForTeamName(teamName, channelName string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.GetChannelByNameForTeamName(api.ctx, channelName, teamName, includeDeleted)
|
2018-07-20 12:03:08 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetChannelsForTeamForUser(teamID, userID string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
channels, err := api.app.GetChannelsForTeamForUser(api.ctx, teamID, userID, &model.ChannelSearchOpts{
|
2022-02-02 12:14:22 -05:00
|
|
|
IncludeDeleted: includeDeleted,
|
|
|
|
|
LastDeleteAt: 0,
|
|
|
|
|
})
|
2018-11-20 08:50:34 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2021-08-17 05:18:33 -04:00
|
|
|
return channels, err
|
2018-10-15 12:27:45 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetChannelStats(channelID string) (*model.ChannelStats, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
memberCount, err := api.app.GetChannelMemberCount(api.ctx, channelID)
|
2018-10-25 13:24:43 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2022-07-14 05:01:29 -04:00
|
|
|
guestCount, err := api.app.GetChannelMemberCount(api.ctx, channelID)
|
2019-07-22 16:13:39 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2021-02-25 14:22:27 -05:00
|
|
|
return &model.ChannelStats{ChannelId: channelID, MemberCount: memberCount, GuestCount: guestCount}, nil
|
2018-10-25 13:24:43 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetDirectChannel(userID1, userID2 string) (*model.Channel, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.GetOrCreateDirectChannel(api.ctx, userID1, userID2)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetGroupChannel(userIDs []string) (*model.Channel, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.CreateGroupChannel(api.ctx, userIDs, "")
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.UpdateChannel(api.ctx, channel)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) SearchChannels(teamID string, term string) ([]*model.Channel, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
channels, err := api.app.SearchChannels(api.ctx, teamID, term)
|
2018-11-20 08:50:34 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2021-08-17 05:18:33 -04:00
|
|
|
return channels, err
|
2018-10-15 12:23:46 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-25 12:52:09 -04:00
|
|
|
func (api *PluginAPI) CreateChannelSidebarCategory(userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.CreateSidebarCategory(api.ctx, userID, teamID, newCategory)
|
2021-06-25 12:52:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetChannelSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.GetSidebarCategoriesForTeamForUser(api.ctx, userID, teamID)
|
2021-06-25 12:52:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateChannelSidebarCategories(userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.UpdateSidebarCategories(api.ctx, userID, teamID, categories)
|
2021-06-25 12:52:09 -04:00
|
|
|
}
|
|
|
|
|
|
2018-11-30 10:47:17 -05:00
|
|
|
func (api *PluginAPI) SearchUsers(search *model.UserSearch) ([]*model.User, *model.AppError) {
|
|
|
|
|
pluginSearchUsersOptions := &model.UserSearchOptions{
|
|
|
|
|
IsAdmin: true,
|
|
|
|
|
AllowInactive: search.AllowInactive,
|
|
|
|
|
Limit: search.Limit,
|
|
|
|
|
}
|
2023-12-04 12:34:57 -05:00
|
|
|
return api.app.SearchUsers(api.ctx, search, pluginSearchUsersOptions)
|
2018-11-30 10:47:17 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) SearchPostsInTeam(teamID string, paramsList []*model.SearchParams) ([]*model.Post, *model.AppError) {
|
|
|
|
|
postList, err := api.app.SearchPostsInTeam(teamID, paramsList)
|
2019-02-13 01:41:32 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2022-07-21 10:11:18 -04:00
|
|
|
return postList.ForPlugin().ToSlice(), nil
|
2019-02-13 01:41:32 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) SearchPostsInTeamForUser(teamID string, userID string, searchParams model.SearchParameter) (*model.PostSearchResults, *model.AppError) {
|
2020-06-23 21:58:44 -04:00
|
|
|
var terms string
|
|
|
|
|
if searchParams.Terms != nil {
|
|
|
|
|
terms = *searchParams.Terms
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timeZoneOffset := 0
|
|
|
|
|
if searchParams.TimeZoneOffset != nil {
|
|
|
|
|
timeZoneOffset = *searchParams.TimeZoneOffset
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isOrSearch := false
|
|
|
|
|
if searchParams.IsOrSearch != nil {
|
|
|
|
|
isOrSearch = *searchParams.IsOrSearch
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page := 0
|
|
|
|
|
if searchParams.Page != nil {
|
|
|
|
|
page = *searchParams.Page
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
perPage := 100
|
|
|
|
|
if searchParams.PerPage != nil {
|
|
|
|
|
perPage = *searchParams.PerPage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
includeDeletedChannels := false
|
|
|
|
|
if searchParams.IncludeDeletedChannels != nil {
|
|
|
|
|
includeDeletedChannels = *searchParams.IncludeDeletedChannels
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-24 09:31:06 -04:00
|
|
|
results, appErr := api.app.SearchPostsForUser(api.ctx, terms, userID, teamID, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage)
|
2022-07-21 10:11:18 -04:00
|
|
|
if results != nil {
|
|
|
|
|
results = results.ForPlugin()
|
|
|
|
|
}
|
|
|
|
|
return results, appErr
|
2020-06-23 21:58:44 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) AddChannelMember(channelID, userID string) (*model.ChannelMember, *model.AppError) {
|
|
|
|
|
channel, err := api.GetChannel(channelID)
|
2018-04-06 17:08:57 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.AddChannelMember(api.ctx, userID, channel, ChannelMemberOpts{
|
2021-04-02 05:03:23 -04:00
|
|
|
// For now, don't allow overriding these via the plugin API.
|
|
|
|
|
UserRequestorID: "",
|
|
|
|
|
PostRootID: "",
|
|
|
|
|
})
|
2018-04-06 17:08:57 -04:00
|
|
|
}
|
|
|
|
|
|
2021-04-02 05:03:23 -04:00
|
|
|
func (api *PluginAPI) AddUserToChannel(channelID, userID, asUserID string) (*model.ChannelMember, *model.AppError) {
|
2021-02-25 14:22:27 -05:00
|
|
|
channel, err := api.GetChannel(channelID)
|
2019-10-17 19:11:26 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.AddChannelMember(api.ctx, userID, channel, ChannelMemberOpts{
|
2021-04-02 05:03:23 -04:00
|
|
|
UserRequestorID: asUserID,
|
|
|
|
|
})
|
2019-10-17 19:11:26 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetChannelMember(channelID, userID string) (*model.ChannelMember, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.GetChannelMember(api.ctx, channelID, userID)
|
2017-12-05 09:14:03 -05:00
|
|
|
}
|
|
|
|
|
|
2021-08-17 05:18:33 -04:00
|
|
|
func (api *PluginAPI) GetChannelMembers(channelID string, page, perPage int) (model.ChannelMembers, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.GetChannelMembersPage(api.ctx, channelID, page, perPage)
|
2018-10-03 16:07:54 -04:00
|
|
|
}
|
|
|
|
|
|
2021-08-17 05:18:33 -04:00
|
|
|
func (api *PluginAPI) GetChannelMembersByIds(channelID string, userIDs []string) (model.ChannelMembers, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.GetChannelMembersByIds(api.ctx, channelID, userIDs)
|
2018-10-31 09:29:20 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-26 02:00:59 -04:00
|
|
|
func (api *PluginAPI) GetChannelMembersForUser(_, userID string, page, perPage int) ([]*model.ChannelMember, *model.AppError) {
|
|
|
|
|
// The team ID parameter was never used in the SQL query.
|
|
|
|
|
// But we keep this to maintain compatibility.
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.GetChannelMembersForUserWithPagination(api.ctx, userID, page, perPage)
|
2019-02-23 14:41:19 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) UpdateChannelMemberRoles(channelID, userID, newRoles string) (*model.ChannelMember, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.UpdateChannelMemberRoles(api.ctx, channelID, userID, newRoles)
|
2018-04-06 17:08:57 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) UpdateChannelMemberNotifications(channelID, userID string, notifications map[string]string) (*model.ChannelMember, *model.AppError) {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.UpdateChannelMemberNotifyProps(api.ctx, notifications, channelID, userID)
|
2018-04-06 17:08:57 -04:00
|
|
|
}
|
|
|
|
|
|
2024-01-11 13:24:52 -05:00
|
|
|
func (api *PluginAPI) PatchChannelMembersNotifications(members []*model.ChannelMemberIdentifier, notifications map[string]string) *model.AppError {
|
|
|
|
|
_, err := api.app.PatchChannelMembersNotifyProps(api.ctx, members, notifications)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) DeleteChannelMember(channelID, userID string) *model.AppError {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.LeaveChannel(api.ctx, channelID, userID)
|
2018-04-06 17:08:57 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-22 14:38:08 -04:00
|
|
|
func (api *PluginAPI) GetGroup(groupId string) (*model.Group, *model.AppError) {
|
2022-10-25 11:54:51 -04:00
|
|
|
return api.app.GetGroup(groupId, nil, nil)
|
2019-10-22 14:38:08 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-18 14:17:36 -04:00
|
|
|
func (api *PluginAPI) GetGroupByName(name string) (*model.Group, *model.AppError) {
|
|
|
|
|
return api.app.GetGroupByName(name, model.GroupSearchOpts{})
|
2019-10-22 14:38:08 -04:00
|
|
|
}
|
|
|
|
|
|
2021-04-12 13:01:28 -04:00
|
|
|
func (api *PluginAPI) GetGroupMemberUsers(groupID string, page, perPage int) ([]*model.User, *model.AppError) {
|
2022-10-25 11:54:51 -04:00
|
|
|
users, _, err := api.app.GetGroupMemberUsersPage(groupID, page, perPage, nil)
|
2021-04-12 13:01:28 -04:00
|
|
|
|
|
|
|
|
return users, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) {
|
|
|
|
|
return api.app.GetGroupsBySource(groupSource)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetGroupsForUser(userID string) ([]*model.Group, *model.AppError) {
|
2025-03-31 15:49:55 -04:00
|
|
|
return api.app.GetGroupsByUserId(userID, model.GroupSearchOpts{})
|
2019-10-22 14:38:08 -04:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 12:00:15 -04:00
|
|
|
func (api *PluginAPI) UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("UpsertGroupMember", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.UpsertGroupMember(groupID, userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpsertGroupMembers(groupID string, userIDs []string) ([]*model.GroupMember, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("UpsertGroupMembers", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.UpsertGroupMembers(groupID, userIDs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("GetGroupByRemoteID", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.GetGroupByRemoteID(remoteID, groupSource)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) CreateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("CreateGroup", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.CreateGroup(group)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("UpdateGroup", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.UpdateGroup(group)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteGroup(groupID string) (*model.Group, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("DeleteGroup", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.DeleteGroup(groupID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) RestoreGroup(groupID string) (*model.Group, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("RestoreGroup", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.RestoreGroup(groupID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("DeleteGroupMember", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.DeleteGroupMember(groupID, userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("GetGroupSyncable", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.GetGroupSyncable(groupID, syncableID, syncableType)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("GetGroupSyncables", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.GetGroupSyncables(groupID, syncableType)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("UpsertGroupSyncable", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.UpsertGroupSyncable(groupSyncable)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("UpdateGroupSyncable", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.UpdateGroupSyncable(groupSyncable)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("DeleteGroupSyncable", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.DeleteGroupSyncable(groupID, syncableID, syncableType)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
2025-03-20 07:53:50 -04:00
|
|
|
post.AddProp(model.PostPropsFromPlugin, "true")
|
2022-09-30 04:12:15 -04:00
|
|
|
|
2023-02-03 03:56:47 -05:00
|
|
|
post, appErr := api.app.CreatePostMissingChannel(api.ctx, post, true, true)
|
2022-07-21 10:11:18 -04:00
|
|
|
if post != nil {
|
|
|
|
|
post = post.ForPlugin()
|
|
|
|
|
}
|
|
|
|
|
return post, appErr
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2018-08-20 12:22:08 -04:00
|
|
|
func (api *PluginAPI) AddReaction(reaction *model.Reaction) (*model.Reaction, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.SaveReactionForPost(api.ctx, reaction)
|
2018-08-20 12:22:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) RemoveReaction(reaction *model.Reaction) *model.AppError {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.DeleteReactionForPost(api.ctx, reaction)
|
2018-08-20 12:22:08 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetReactions(postID string) ([]*model.Reaction, *model.AppError) {
|
|
|
|
|
return api.app.GetReactionsForPost(postID)
|
2018-08-20 12:22:08 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) SendEphemeralPost(userID string, post *model.Post) *model.Post {
|
2022-07-21 10:11:18 -04:00
|
|
|
return api.app.SendEphemeralPost(api.ctx, userID, post).ForPlugin()
|
2018-07-06 18:32:55 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) UpdateEphemeralPost(userID string, post *model.Post) *model.Post {
|
2022-07-21 10:11:18 -04:00
|
|
|
return api.app.UpdateEphemeralPost(api.ctx, userID, post).ForPlugin()
|
MM-10516: Added support for PostActions in ephemeral posts (#10258)
* Added support for PostActions in ephemeral posts
The general approach is that we take all the metadata that DoPostAction
needs to process client DoPostActionRequests, and store it in a
serialized, encrypted Cookie field, in the PostAction struct.
The client then must send it back, and it is then used to process
PostActions as a fallback top the metadata in the database.
This PR adds a new config setting, `ServiceSettings.ActionCookieSecret`.
In a cluster environment it must be the same for all instances.
- Added type PostActionCookie, and a Cookie string to PostAction.
- Added App.AddActionCookiesToPost.
- Use App.AddActionCookiesToPost in api4.createEphemeralPost,
App.SendEphemeralPost, App.UpdateEphemeralPost.
- Added App.DoPostActionWithCookie to process incoming requests with
cookies. For backward compatibility, it prefers the metadata in the
database; falls back to cookie.
- Added plugin.API.UpdateEphemeralPost and plugin.API.DeleteEphemeralPost.
- Added App.encryptActionCookie/App.decryptActionCookie.
* Style
* Fixed an unfortunate typo, tested with matterpoll
* minor PR feedback
* Fixed uninitialized Context
* Fixed another test failure
* Fixed permission check
* Added api test for DoPostActionWithCookie
* Replaced config.ActionCookieSecret with Server.PostActionCookieSecret
Modeled after AsymetricSigningKey
* style
* Set DeleteAt in DeleteEphemeralPost
* PR feedback
* Removed deadwood comment
* Added EXPERIMENTAL comment to the 2 APIs in question
2019-03-01 13:15:31 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) DeleteEphemeralPost(userID, postID string) {
|
2024-04-24 05:52:33 -04:00
|
|
|
api.app.DeleteEphemeralPost(api.ctx, userID, postID)
|
MM-10516: Added support for PostActions in ephemeral posts (#10258)
* Added support for PostActions in ephemeral posts
The general approach is that we take all the metadata that DoPostAction
needs to process client DoPostActionRequests, and store it in a
serialized, encrypted Cookie field, in the PostAction struct.
The client then must send it back, and it is then used to process
PostActions as a fallback top the metadata in the database.
This PR adds a new config setting, `ServiceSettings.ActionCookieSecret`.
In a cluster environment it must be the same for all instances.
- Added type PostActionCookie, and a Cookie string to PostAction.
- Added App.AddActionCookiesToPost.
- Use App.AddActionCookiesToPost in api4.createEphemeralPost,
App.SendEphemeralPost, App.UpdateEphemeralPost.
- Added App.DoPostActionWithCookie to process incoming requests with
cookies. For backward compatibility, it prefers the metadata in the
database; falls back to cookie.
- Added plugin.API.UpdateEphemeralPost and plugin.API.DeleteEphemeralPost.
- Added App.encryptActionCookie/App.decryptActionCookie.
* Style
* Fixed an unfortunate typo, tested with matterpoll
* minor PR feedback
* Fixed uninitialized Context
* Fixed another test failure
* Fixed permission check
* Added api test for DoPostActionWithCookie
* Replaced config.ActionCookieSecret with Server.PostActionCookieSecret
Modeled after AsymetricSigningKey
* style
* Set DeleteAt in DeleteEphemeralPost
* PR feedback
* Removed deadwood comment
* Added EXPERIMENTAL comment to the 2 APIs in question
2019-03-01 13:15:31 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) DeletePost(postID string) *model.AppError {
|
2022-07-14 05:01:29 -04:00
|
|
|
_, err := api.app.DeletePost(api.ctx, postID, api.id)
|
2017-11-27 17:23:35 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetPostThread(postID string) (*model.PostList, *model.AppError) {
|
2025-09-18 10:14:24 -04:00
|
|
|
list, appErr := api.app.GetPostThread(api.ctx, postID, model.GetPostsOptions{}, "")
|
2022-07-21 10:11:18 -04:00
|
|
|
if list != nil {
|
|
|
|
|
list = list.ForPlugin()
|
|
|
|
|
}
|
|
|
|
|
return list, appErr
|
2018-10-15 09:19:36 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetPost(postID string) (*model.Post, *model.AppError) {
|
2024-05-24 10:05:48 -04:00
|
|
|
post, appErr := api.app.GetSinglePost(api.ctx, postID, false)
|
2022-07-21 10:11:18 -04:00
|
|
|
if post != nil {
|
|
|
|
|
post = post.ForPlugin()
|
|
|
|
|
}
|
|
|
|
|
return post, appErr
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetPostsSince(channelID string, time int64) (*model.PostList, *model.AppError) {
|
2025-09-18 10:14:24 -04:00
|
|
|
list, appErr := api.app.GetPostsSince(api.ctx, model.GetPostsSinceOptions{ChannelId: channelID, Time: time})
|
2022-07-21 10:11:18 -04:00
|
|
|
if list != nil {
|
|
|
|
|
list = list.ForPlugin()
|
|
|
|
|
}
|
|
|
|
|
return list, appErr
|
2018-10-15 10:04:22 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetPostsAfter(channelID, postID string, page, perPage int) (*model.PostList, *model.AppError) {
|
2025-09-18 10:14:24 -04:00
|
|
|
list, appErr := api.app.GetPostsAfterPost(api.ctx, model.GetPostsOptions{ChannelId: channelID, PostId: postID, Page: page, PerPage: perPage})
|
2022-07-21 10:11:18 -04:00
|
|
|
if list != nil {
|
|
|
|
|
list = list.ForPlugin()
|
|
|
|
|
}
|
|
|
|
|
return list, appErr
|
2018-10-18 12:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetPostsBefore(channelID, postID string, page, perPage int) (*model.PostList, *model.AppError) {
|
2025-09-18 10:14:24 -04:00
|
|
|
list, appErr := api.app.GetPostsBeforePost(api.ctx, model.GetPostsOptions{ChannelId: channelID, PostId: postID, Page: page, PerPage: perPage})
|
2022-07-21 10:11:18 -04:00
|
|
|
if list != nil {
|
|
|
|
|
list = list.ForPlugin()
|
|
|
|
|
}
|
|
|
|
|
return list, appErr
|
2018-10-15 13:18:23 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetPostsForChannel(channelID string, page, perPage int) (*model.PostList, *model.AppError) {
|
2025-09-18 10:14:24 -04:00
|
|
|
list, appErr := api.app.GetPostsPage(api.ctx, model.GetPostsOptions{ChannelId: channelID, Page: page, PerPage: perPage})
|
2022-07-21 10:11:18 -04:00
|
|
|
if list != nil {
|
|
|
|
|
list = list.ForPlugin()
|
|
|
|
|
}
|
|
|
|
|
return list, appErr
|
2018-10-10 09:23:36 -04:00
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
|
2025-01-13 07:46:56 -05:00
|
|
|
post, appErr := api.app.UpdatePost(api.ctx, post, &model.UpdatePostOptions{SafeUpdate: false})
|
2022-07-21 10:11:18 -04:00
|
|
|
if post != nil {
|
|
|
|
|
post = post.ForPlugin()
|
|
|
|
|
}
|
|
|
|
|
return post, appErr
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetProfileImage(userID string) ([]byte, *model.AppError) {
|
|
|
|
|
user, err := api.app.GetUser(userID)
|
2018-10-15 10:23:41 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data, _, err := api.app.GetProfileImage(user)
|
|
|
|
|
return data, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) SetProfileImage(userID string, data []byte) *model.AppError {
|
2021-08-11 03:37:52 -04:00
|
|
|
if _, err := api.app.GetUser(userID); err != nil {
|
2018-11-15 15:23:03 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 00:34:21 -04:00
|
|
|
return api.app.SetProfileImageFromFile(api.ctx, userID, bytes.NewReader(data))
|
2018-11-15 15:23:03 -05:00
|
|
|
}
|
|
|
|
|
|
2018-11-05 08:50:08 -05:00
|
|
|
func (api *PluginAPI) GetEmojiList(sortBy string, page, perPage int) ([]*model.Emoji, *model.AppError) {
|
2022-11-03 03:54:59 -04:00
|
|
|
return api.app.GetEmojiList(api.ctx, page, perPage, sortBy)
|
2018-11-05 08:50:08 -05:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 17:09:30 -04:00
|
|
|
func (api *PluginAPI) GetEmojiByName(name string) (*model.Emoji, *model.AppError) {
|
2022-11-03 03:54:59 -04:00
|
|
|
return api.app.GetEmojiByName(api.ctx, name)
|
2018-10-15 17:09:30 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-25 09:54:10 -04:00
|
|
|
func (api *PluginAPI) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) {
|
2022-11-03 03:54:59 -04:00
|
|
|
return api.app.GetEmoji(api.ctx, emojiId)
|
2018-10-25 09:54:10 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) CopyFileInfos(userID string, fileIDs []string) ([]string, *model.AppError) {
|
2023-12-04 12:34:57 -05:00
|
|
|
return api.app.CopyFileInfos(api.ctx, userID, fileIDs)
|
2018-08-02 10:37:31 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
2023-11-07 04:04:16 -05:00
|
|
|
return api.app.GetFileInfo(api.ctx, fileID)
|
2018-08-20 12:18:25 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-30 16:43:40 -04:00
|
|
|
func (api *PluginAPI) SetFileSearchableContent(fileID string, content string) *model.AppError {
|
2023-12-04 12:34:57 -05:00
|
|
|
return api.app.SetFileSearchableContent(api.ctx, fileID, content)
|
2023-08-30 16:43:40 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-14 15:21:54 -05:00
|
|
|
func (api *PluginAPI) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
2023-11-07 04:04:16 -05:00
|
|
|
return api.app.GetFileInfos(api.ctx, page, perPage, opt)
|
2020-02-14 15:21:54 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetFileLink(fileID string) (string, *model.AppError) {
|
2019-01-31 08:12:01 -05:00
|
|
|
if !*api.app.Config().FileSettings.EnablePublicLink {
|
2018-10-17 20:31:51 -04:00
|
|
|
return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.disabled.app_error", nil, "", http.StatusNotImplemented)
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-07 04:04:16 -05:00
|
|
|
info, err := api.app.GetFileInfo(api.ctx, fileID)
|
2018-10-17 20:31:51 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-25 05:15:17 -05:00
|
|
|
if info.PostId == "" {
|
2018-10-17 20:31:51 -04:00
|
|
|
return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.no_post.app_error", nil, "file_id="+info.Id, http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return api.app.GeneratePublicLink(api.app.GetSiteURL(), info), nil
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 12:18:25 -04:00
|
|
|
func (api *PluginAPI) ReadFile(path string) ([]byte, *model.AppError) {
|
|
|
|
|
return api.app.ReadFile(path)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) GetFile(fileID string) ([]byte, *model.AppError) {
|
2023-11-07 04:04:16 -05:00
|
|
|
return api.app.GetFile(api.ctx, fileID)
|
2018-12-13 04:46:42 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) UploadFile(data []byte, channelID string, filename string) (*model.FileInfo, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.UploadFile(api.ctx, data, channelID, filename)
|
2018-11-07 15:24:54 -05:00
|
|
|
}
|
|
|
|
|
|
2018-10-18 16:07:21 -04:00
|
|
|
func (api *PluginAPI) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) {
|
2022-11-03 03:54:59 -04:00
|
|
|
return api.app.GetEmojiImage(api.ctx, emojiId)
|
2018-10-18 16:07:21 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetTeamIcon(teamID string) ([]byte, *model.AppError) {
|
|
|
|
|
team, err := api.app.GetTeam(teamID)
|
2018-11-16 08:17:42 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data, err := api.app.GetTeamIcon(team)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return data, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) SetTeamIcon(teamID string, data []byte) *model.AppError {
|
|
|
|
|
team, err := api.app.GetTeam(teamID)
|
2018-11-16 10:52:07 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 15:57:43 -04:00
|
|
|
return api.app.SetTeamIconFromFile(api.ctx, team, bytes.NewReader(data))
|
2018-11-16 10:52:07 -05:00
|
|
|
}
|
|
|
|
|
|
2018-11-19 15:27:17 -05:00
|
|
|
func (api *PluginAPI) OpenInteractiveDialog(dialog model.OpenDialogRequest) *model.AppError {
|
2024-04-30 12:27:07 -04:00
|
|
|
return api.app.OpenInteractiveDialog(api.ctx, dialog)
|
2018-11-19 15:27:17 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) RemoveTeamIcon(teamID string) *model.AppError {
|
|
|
|
|
_, err := api.app.GetTeam(teamID)
|
2018-11-20 09:43:42 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
err = api.app.RemoveTeamIcon(teamID)
|
2018-11-20 09:43:42 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 04:06:14 -05:00
|
|
|
// Mail Section
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) SendMail(to, subject, htmlBody string) *model.AppError {
|
|
|
|
|
if to == "" {
|
|
|
|
|
return model.NewAppError("SendMail", "plugin_api.send_mail.missing_to", nil, "", http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if subject == "" {
|
|
|
|
|
return model.NewAppError("SendMail", "plugin_api.send_mail.missing_subject", nil, "", http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if htmlBody == "" {
|
|
|
|
|
return model.NewAppError("SendMail", "plugin_api.send_mail.missing_htmlbody", nil, "", http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 11:26:06 -04:00
|
|
|
if err := api.app.Srv().EmailService.SendNotificationMail(to, subject, htmlBody); err != nil {
|
2022-08-18 05:01:37 -04:00
|
|
|
return model.NewAppError("SendMail", "plugin_api.send_mail.missing_htmlbody", nil, "", http.StatusInternalServerError).Wrap(err)
|
2021-02-09 06:28:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
2019-01-10 04:06:14 -05:00
|
|
|
}
|
|
|
|
|
|
2018-11-08 13:17:07 -05:00
|
|
|
// Plugin Section
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetPlugins() ([]*model.Manifest, *model.AppError) {
|
|
|
|
|
plugins, err := api.app.GetPlugins()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
var manifests []*model.Manifest
|
|
|
|
|
for _, manifest := range plugins.Active {
|
|
|
|
|
manifests = append(manifests, &manifest.Manifest)
|
|
|
|
|
}
|
|
|
|
|
for _, manifest := range plugins.Inactive {
|
|
|
|
|
manifests = append(manifests, &manifest.Manifest)
|
|
|
|
|
}
|
|
|
|
|
return manifests, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) EnablePlugin(id string) *model.AppError {
|
|
|
|
|
return api.app.EnablePlugin(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DisablePlugin(id string) *model.AppError {
|
|
|
|
|
return api.app.DisablePlugin(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) RemovePlugin(id string) *model.AppError {
|
2022-12-21 14:10:26 -05:00
|
|
|
return api.app.Channels().RemovePlugin(id)
|
2018-11-08 13:17:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetPluginStatus(id string) (*model.PluginStatus, *model.AppError) {
|
|
|
|
|
return api.app.GetPluginStatus(id)
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:57:55 -04:00
|
|
|
func (api *PluginAPI) InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError) {
|
|
|
|
|
if !*api.app.Config().PluginSettings.Enable || !*api.app.Config().PluginSettings.EnableUploads {
|
|
|
|
|
return nil, model.NewAppError("installPlugin", "app.plugin.upload_disabled.app_error", nil, "", http.StatusNotImplemented)
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-09 07:25:46 -04:00
|
|
|
fileBuffer, err := io.ReadAll(file)
|
2019-10-17 14:57:55 -04:00
|
|
|
if err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("InstallPlugin", "api.plugin.upload.file.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
2019-10-17 14:57:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return api.app.InstallPlugin(bytes.NewReader(fileBuffer), replace)
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 13:17:07 -05:00
|
|
|
// KV Store Section
|
|
|
|
|
|
2019-12-03 04:46:15 -05:00
|
|
|
func (api *PluginAPI) KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) {
|
2019-11-04 07:49:54 -05:00
|
|
|
return api.app.SetPluginKeyWithOptions(api.id, key, value, options)
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 15:33:13 -04:00
|
|
|
func (api *PluginAPI) KVSet(key string, value []byte) *model.AppError {
|
|
|
|
|
return api.app.SetPluginKey(api.id, key, value)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2019-04-23 13:35:17 -04:00
|
|
|
func (api *PluginAPI) KVCompareAndSet(key string, oldValue, newValue []byte) (bool, *model.AppError) {
|
|
|
|
|
return api.app.CompareAndSetPluginKey(api.id, key, oldValue, newValue)
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 22:25:38 -04:00
|
|
|
func (api *PluginAPI) KVCompareAndDelete(key string, oldValue []byte) (bool, *model.AppError) {
|
2024-04-24 05:52:33 -04:00
|
|
|
return api.app.CompareAndDeletePluginKey(api.ctx, api.id, key, oldValue)
|
2019-08-21 22:25:38 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-10 13:55:12 -04:00
|
|
|
func (api *PluginAPI) KVSetWithExpiry(key string, value []byte, expireInSeconds int64) *model.AppError {
|
|
|
|
|
return api.app.SetPluginKeyWithExpiry(api.id, key, value, expireInSeconds)
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 15:33:13 -04:00
|
|
|
func (api *PluginAPI) KVGet(key string) ([]byte, *model.AppError) {
|
|
|
|
|
return api.app.GetPluginKey(api.id, key)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2018-06-25 15:33:13 -04:00
|
|
|
func (api *PluginAPI) KVDelete(key string) *model.AppError {
|
|
|
|
|
return api.app.DeletePluginKey(api.id, key)
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
2018-06-27 08:46:38 -04:00
|
|
|
|
2018-10-10 13:55:12 -04:00
|
|
|
func (api *PluginAPI) KVDeleteAll() *model.AppError {
|
|
|
|
|
return api.app.DeleteAllKeysForPlugin(api.id)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-03 16:04:37 -04:00
|
|
|
func (api *PluginAPI) KVList(page, perPage int) ([]string, *model.AppError) {
|
|
|
|
|
return api.app.ListPluginKeys(api.id, page, perPage)
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func (api *PluginAPI) PublishWebSocketEvent(event string, payload map[string]any, broadcast *model.WebsocketBroadcast) {
|
2023-11-22 05:09:48 -05:00
|
|
|
ev := model.NewWebSocketEvent(model.WebsocketEventType(fmt.Sprintf("custom_%v_%v", api.id, event)), "", "", "", nil, "")
|
2019-12-24 03:32:11 -05:00
|
|
|
ev = ev.SetBroadcast(broadcast).SetData(payload)
|
|
|
|
|
api.app.Publish(ev)
|
2018-06-27 08:46:38 -04:00
|
|
|
}
|
2018-07-03 12:58:28 -04:00
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) HasPermissionTo(userID string, permission *model.Permission) bool {
|
|
|
|
|
return api.app.HasPermissionTo(userID, permission)
|
2018-08-20 12:22:08 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) HasPermissionToTeam(userID, teamID string, permission *model.Permission) bool {
|
2023-10-11 07:08:55 -04:00
|
|
|
return api.app.HasPermissionToTeam(api.ctx, userID, teamID, permission)
|
2018-08-20 12:22:08 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) HasPermissionToChannel(userID, channelID string, permission *model.Permission) bool {
|
2022-07-14 05:01:29 -04:00
|
|
|
return api.app.HasPermissionToChannel(api.ctx, userID, channelID, permission)
|
2018-08-20 12:22:08 -04:00
|
|
|
}
|
|
|
|
|
|
2021-12-07 12:43:33 -05:00
|
|
|
func (api *PluginAPI) RolesGrantPermission(roleNames []string, permissionId string) bool {
|
|
|
|
|
return api.app.RolesGrantPermission(roleNames, permissionId)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 18:22:54 -04:00
|
|
|
func (api *PluginAPI) UpdateUserRoles(userID string, newRoles string) (*model.User, *model.AppError) {
|
|
|
|
|
return api.app.UpdateUserRoles(api.ctx, userID, newRoles, true)
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func (api *PluginAPI) LogDebug(msg string, keyValuePairs ...any) {
|
2021-09-13 10:12:18 -04:00
|
|
|
api.logger.Debugw(msg, keyValuePairs...)
|
2018-07-03 12:58:28 -04:00
|
|
|
}
|
2025-04-01 15:57:43 -04:00
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func (api *PluginAPI) LogInfo(msg string, keyValuePairs ...any) {
|
2021-09-13 10:12:18 -04:00
|
|
|
api.logger.Infow(msg, keyValuePairs...)
|
2018-07-03 12:58:28 -04:00
|
|
|
}
|
2025-04-01 15:57:43 -04:00
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func (api *PluginAPI) LogError(msg string, keyValuePairs ...any) {
|
2021-09-13 10:12:18 -04:00
|
|
|
api.logger.Errorw(msg, keyValuePairs...)
|
2018-07-03 12:58:28 -04:00
|
|
|
}
|
2025-04-01 15:57:43 -04:00
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func (api *PluginAPI) LogWarn(msg string, keyValuePairs ...any) {
|
2021-09-13 10:12:18 -04:00
|
|
|
api.logger.Warnw(msg, keyValuePairs...)
|
2018-07-03 12:58:28 -04:00
|
|
|
}
|
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 10:06:45 -05:00
|
|
|
|
|
|
|
|
func (api *PluginAPI) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
|
|
|
|
|
// Bots created by a plugin should use the plugin's ID for the creator field, unless
|
|
|
|
|
// otherwise specified by the plugin.
|
|
|
|
|
if bot.OwnerId == "" {
|
|
|
|
|
bot.OwnerId = api.id
|
|
|
|
|
}
|
2019-05-14 16:15:23 -04:00
|
|
|
// Bots cannot be owners of other bots
|
|
|
|
|
if user, err := api.app.GetUser(bot.OwnerId); err == nil {
|
|
|
|
|
if user.IsBot {
|
|
|
|
|
return nil, model.NewAppError("CreateBot", "plugin_api.bot_cant_create_bot", nil, "", http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
}
|
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 10:06:45 -05:00
|
|
|
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.CreateBot(api.ctx, bot)
|
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 10:06:45 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) PatchBot(userID string, botPatch *model.BotPatch) (*model.Bot, *model.AppError) {
|
2023-12-04 12:34:57 -05:00
|
|
|
return api.app.PatchBot(api.ctx, userID, botPatch)
|
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 10:06:45 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) GetBot(userID string, includeDeleted bool) (*model.Bot, *model.AppError) {
|
2024-03-11 08:24:35 -04:00
|
|
|
return api.app.GetBot(api.ctx, userID, includeDeleted)
|
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 10:06:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetBots(options *model.BotGetOptions) ([]*model.Bot, *model.AppError) {
|
2024-03-11 08:24:35 -04:00
|
|
|
bots, err := api.app.GetBots(api.ctx, options)
|
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 10:06:45 -05:00
|
|
|
|
|
|
|
|
return []*model.Bot(bots), err
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) UpdateBotActive(userID string, active bool) (*model.Bot, *model.AppError) {
|
2021-05-11 06:00:44 -04:00
|
|
|
return api.app.UpdateBotActive(api.ctx, userID, active)
|
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 10:06:45 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-05 05:22:27 -05:00
|
|
|
func (api *PluginAPI) PermanentDeleteBot(userID string) *model.AppError {
|
2024-03-11 08:24:35 -04:00
|
|
|
return api.app.PermanentDeleteBot(api.ctx, userID)
|
MM-12393 Server side of bot accounts. (#10378)
* bots model, store and api (#9903)
* bots model, store and api
Fixes: MM-13100, MM-13101, MM-13103, MM-13105, MMM-13119
* uncomment tests incorrectly commented, and fix merge issues
* add etags support
* add missing licenses
* remove unused sqlbuilder.go (for now...)
* rejig permissions
* split out READ_BOTS into READ_BOTS and READ_OTHERS_BOTS, the latter
implicitly allowing the former
* make MANAGE_OTHERS_BOTS imply MANAGE_BOTS
* conform to general rest api pattern
* eliminate redundant http.StatusOK
* Update api4/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* s/model.UserFromBotModel/model.UserFromBot/g
* Update model/bot.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* Update model/client4.go
Co-Authored-By: lieut-data <jesse.hallam@gmail.com>
* move sessionHasPermissionToManageBot to app/authorization.go
* use api.ApiSessionRequired for createBot
* introduce BOT_DESCRIPTION_MAX_RUNES constant
* MM-13512 Prevent getting a user by email based on privacy settings (#10021)
* MM-13512 Prevent getting a user by email based on privacy settings
* Add additional config settings to tests
* upgrade db to 5.7 (#10019)
* MM-13526 Add validation when setting a user's Locale field (#10022)
* Fix typos (#10024)
* Fixing first user being created with system admin privilages without being explicity specified. (#10014)
* Revert "Support for Embeded chat (#9129)" (#10017)
This reverts commit 3fcecd521a5c6ccfdb52fb4c3fb1f8c6ea528a4e.
* s/DisableBot/UpdateBotActive
* add permissions on upgrade
* Update NOTICE.txt (#10054)
- add new dependency (text)
- handle switch to forked dependency (go-gomail -> go-mail)
- misc copyright owner updates
* avoid leaking bot knowledge without permission
* [GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)
* 6798 added a new api to get the bulk reactions for posts
* 6798 added the permsission check before getting the reactions
* GH-6798 added a new app function for the new endpoint
* 6798 added a store method to get reactions for multiple posts
* 6798 connected the app function with the new store function
* 6798 fixed the review comments
* MM-13559 Update model.post.is_valid.file_ids.app_error text per report (#10055)
Ticket: https://mattermost.atlassian.net/browse/MM-13559
Report: https://github.com/mattermost/mattermost-server/issues/10023
* Trigger Login Hooks with OAuth (#10061)
* make BotStore.GetAll deterministic even on duplicate CreateAt
* fix spurious TestMuteCommandSpecificChannel test failure
See
https://community-daily.mattermost.com/core/pl/px9p8s3dzbg1pf3ddrm5cr36uw
* fix race in TestExportUserChannels
* TestExportUserChannels: remove SaveMember call, as it is redundant and used to be silently failing anyway
* MM-13117: bot tokens (#10111)
* eliminate redundant Client/AdminClient declarations
* harden TestUpdateChannelScheme to API failures
* eliminate unnecessary config restoration
* minor cleanup
* make TestGenerateMfaSecret config dependency explicit
* TestCreateUserAccessToken for bots
* TestGetUserAccessToken* for bots
* leverage SessionHasPermissionToUserOrBot for user token APIs
* Test(Revoke|Disable|Enable)UserAccessToken
* make EnableUserAccessTokens explicit, so as to not rely on local config.json
* uncomment TestResetPassword, but still skip
* mark assert(Invalid)Token as helper
* fix whitespace issues
* fix mangled comments
* MM-13116: bot plugin api (#10113)
* MM-13117: expose bot API to plugins
This also changes the `CreatorId` column definition to allow for plugin
ids, as the default unless the plugin overrides is to use the plugin id
here. This branch hasn't hit master yet, so no migration needed.
* gofmt issues
* expunge use of BotList in plugin/client API
* introduce model.BotGetOptions
* use botUserId term for clarity
* MM-13129 Adding functionality to deal with orphaned bots (#10238)
* Add way to list orphaned bots.
* Add /assign route to modify ownership of bot accounts.
* Apply suggestions from code review
Co-Authored-By: crspeller <crspeller@gmail.com>
* MM-13120: add IsBot field to returned user objects (#10103)
* MM-13104: forbid bot login (#10251)
* MM-13104: disallow bot login
* fix shadowing
* MM-13136 Disable user bots when user is disabled. (#10293)
* Disable user bots when user is disabled.
* Grammer.
Co-Authored-By: crspeller <crspeller@gmail.com>
* Fixing bot branch for test changes.
* Don't use external dependancies in bot plugin tests.
* Rename bot CreatorId to OwnerId
* Adding ability to re-enable bots
* Fixing IsBot to not attempt to be saved to DB.
* Adding diagnostics and licencing counting for bot accounts.
* Modifying gorp to allow reading of '-' fields.
* Removing unnessisary nil values from UserCountOptions.
* Changing comment to GoDoc format
* Improving user count SQL
* Some improvments from feedback.
* Omit empty on User.IsBot
2019-03-05 10:06:45 -05:00
|
|
|
}
|
2019-07-11 12:00:12 -04:00
|
|
|
|
2022-06-22 04:36:00 -04:00
|
|
|
func (api *PluginAPI) EnsureBotUser(bot *model.Bot) (string, error) {
|
2022-11-03 01:31:38 -04:00
|
|
|
// Bots created by a plugin should use the plugin's ID for the creator field.
|
|
|
|
|
bot.OwnerId = api.id
|
|
|
|
|
|
2022-06-22 04:36:00 -04:00
|
|
|
return api.app.EnsureBot(api.ctx, api.id, bot)
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 14:22:27 -05:00
|
|
|
func (api *PluginAPI) PublishUserTyping(userID, channelID, parentId string) *model.AppError {
|
|
|
|
|
return api.app.PublishUserTyping(userID, channelID, parentId)
|
2020-06-16 05:41:05 -04:00
|
|
|
}
|
|
|
|
|
|
2019-11-04 20:35:58 -05:00
|
|
|
func (api *PluginAPI) PluginHTTP(request *http.Request) *http.Response {
|
|
|
|
|
split := strings.SplitN(request.URL.Path, "/", 3)
|
|
|
|
|
if len(split) != 3 {
|
|
|
|
|
return &http.Response{
|
|
|
|
|
StatusCode: http.StatusBadRequest,
|
2022-08-09 07:25:46 -04:00
|
|
|
Body: io.NopCloser(bytes.NewBufferString("Not enough URL. Form of URL should be /<pluginid>/*")),
|
2019-11-04 20:35:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
destinationPluginId := split[1]
|
|
|
|
|
newURL, err := url.Parse("/" + split[2])
|
2020-06-30 04:13:27 -04:00
|
|
|
newURL.RawQuery = request.URL.Query().Encode()
|
2019-11-04 20:35:58 -05:00
|
|
|
request.URL = newURL
|
|
|
|
|
if destinationPluginId == "" || err != nil {
|
|
|
|
|
message := "No plugin specified. Form of URL should be /<pluginid>/*"
|
|
|
|
|
if err != nil {
|
|
|
|
|
message = "Form of URL should be /<pluginid>/* Error: " + err.Error()
|
|
|
|
|
}
|
|
|
|
|
return &http.Response{
|
|
|
|
|
StatusCode: http.StatusBadRequest,
|
2022-08-09 07:25:46 -04:00
|
|
|
Body: io.NopCloser(bytes.NewBufferString(message)),
|
2019-11-04 20:35:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
2025-11-05 09:21:13 -05:00
|
|
|
|
|
|
|
|
// Create pipe for streaming response
|
|
|
|
|
pr, pw := io.Pipe()
|
|
|
|
|
responseTransfer := NewPluginResponseWriter(pw)
|
|
|
|
|
|
|
|
|
|
// Serve the request in a goroutine, streaming the response through the pipe
|
|
|
|
|
go func() {
|
|
|
|
|
defer func() {
|
|
|
|
|
// Ensure pipe is closed when request completes
|
|
|
|
|
var closeErr error
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
closeErr = responseTransfer.CloseWithError(fmt.Errorf("panic in plugin request: %v", err))
|
|
|
|
|
} else {
|
|
|
|
|
closeErr = responseTransfer.Close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if closeErr != nil {
|
|
|
|
|
api.logger.Errorw("Failed to close plugin response pipe", "error", closeErr)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
api.app.ServeInterPluginRequest(responseTransfer, request, api.id, destinationPluginId)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// Wait for headers to be ready before returning response
|
|
|
|
|
<-responseTransfer.ResponseReady
|
|
|
|
|
|
|
|
|
|
return responseTransfer.GenerateResponse(pr)
|
2019-11-04 20:35:58 -05:00
|
|
|
}
|
2020-07-31 11:40:15 -04:00
|
|
|
|
|
|
|
|
func (api *PluginAPI) CreateCommand(cmd *model.Command) (*model.Command, error) {
|
|
|
|
|
cmd.CreatorId = ""
|
|
|
|
|
cmd.PluginId = api.id
|
|
|
|
|
|
|
|
|
|
cmd, appErr := api.app.createCommand(cmd)
|
|
|
|
|
|
|
|
|
|
if appErr != nil {
|
|
|
|
|
return cmd, appErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cmd, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) ListCommands(teamID string) ([]*model.Command, error) {
|
|
|
|
|
ret := make([]*model.Command, 0)
|
|
|
|
|
|
|
|
|
|
cmds, err := api.ListPluginCommands(teamID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
ret = append(ret, cmds...)
|
|
|
|
|
|
|
|
|
|
cmds, err = api.ListBuiltInCommands()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
ret = append(ret, cmds...)
|
|
|
|
|
|
|
|
|
|
cmds, err = api.ListCustomCommands(teamID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
ret = append(ret, cmds...)
|
|
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) ListCustomCommands(teamID string) ([]*model.Command, error) {
|
|
|
|
|
// Plugins are allowed to bypass the a.Config().ServiceSettings.EnableCommands setting.
|
2022-10-06 04:04:21 -04:00
|
|
|
return api.app.Srv().Store().Command().GetByTeam(teamID)
|
2020-07-31 11:40:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) ListPluginCommands(teamID string) ([]*model.Command, error) {
|
|
|
|
|
commands := make([]*model.Command, 0)
|
|
|
|
|
seen := make(map[string]bool)
|
|
|
|
|
|
2023-03-22 17:22:27 -04:00
|
|
|
for _, cmd := range api.app.CommandsForTeam(teamID) {
|
2020-07-31 11:40:15 -04:00
|
|
|
if !seen[cmd.Trigger] {
|
|
|
|
|
seen[cmd.Trigger] = true
|
|
|
|
|
commands = append(commands, cmd)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commands, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) ListBuiltInCommands() ([]*model.Command, error) {
|
|
|
|
|
commands := make([]*model.Command, 0)
|
|
|
|
|
seen := make(map[string]bool)
|
|
|
|
|
|
|
|
|
|
for _, value := range commandProviders {
|
2021-02-26 02:12:49 -05:00
|
|
|
if cmd := value.GetCommand(api.app, i18n.T); cmd != nil {
|
2020-07-31 11:40:15 -04:00
|
|
|
cpy := *cmd
|
|
|
|
|
if cpy.AutoComplete && !seen[cpy.Trigger] {
|
|
|
|
|
cpy.Sanitize()
|
|
|
|
|
seen[cpy.Trigger] = true
|
|
|
|
|
commands = append(commands, &cpy)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commands, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetCommand(commandID string) (*model.Command, error) {
|
2022-10-06 04:04:21 -04:00
|
|
|
return api.app.Srv().Store().Command().Get(commandID)
|
2020-07-31 11:40:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateCommand(commandID string, updatedCmd *model.Command) (*model.Command, error) {
|
|
|
|
|
oldCmd, err := api.GetCommand(commandID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatedCmd.Trigger = strings.ToLower(updatedCmd.Trigger)
|
|
|
|
|
updatedCmd.Id = oldCmd.Id
|
|
|
|
|
updatedCmd.Token = oldCmd.Token
|
|
|
|
|
updatedCmd.CreateAt = oldCmd.CreateAt
|
|
|
|
|
updatedCmd.UpdateAt = model.GetMillis()
|
|
|
|
|
updatedCmd.DeleteAt = oldCmd.DeleteAt
|
|
|
|
|
updatedCmd.PluginId = api.id
|
|
|
|
|
if updatedCmd.TeamId == "" {
|
|
|
|
|
updatedCmd.TeamId = oldCmd.TeamId
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 04:04:21 -04:00
|
|
|
return api.app.Srv().Store().Command().Update(updatedCmd)
|
2020-07-31 11:40:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteCommand(commandID string) error {
|
2022-10-06 04:04:21 -04:00
|
|
|
err := api.app.Srv().Store().Command().Delete(commandID, model.GetMillis())
|
2020-07-31 11:40:15 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2021-04-28 13:59:32 -04:00
|
|
|
|
2021-07-14 09:08:22 -04:00
|
|
|
func (api *PluginAPI) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
|
|
|
|
|
return api.app.CreateOAuthApp(app)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetOAuthApp(appID string) (*model.OAuthApp, *model.AppError) {
|
|
|
|
|
return api.app.GetOAuthApp(appID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
|
|
|
|
|
oldApp, err := api.GetOAuthApp(app.Id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 14:05:36 -04:00
|
|
|
return api.app.UpdateOAuthApp(oldApp, app)
|
2021-07-14 09:08:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteOAuthApp(appID string) *model.AppError {
|
2024-04-24 05:52:33 -04:00
|
|
|
return api.app.DeleteOAuthApp(api.ctx, appID)
|
2021-07-14 09:08:22 -04:00
|
|
|
}
|
|
|
|
|
|
2021-04-28 13:59:32 -04:00
|
|
|
// PublishPluginClusterEvent broadcasts a plugin event to all other running instances of
|
|
|
|
|
// the calling plugin.
|
|
|
|
|
func (api *PluginAPI) PublishPluginClusterEvent(ev model.PluginClusterEvent,
|
2025-04-01 15:57:43 -04:00
|
|
|
opts model.PluginClusterEventSendOptions,
|
|
|
|
|
) error {
|
2021-04-28 13:59:32 -04:00
|
|
|
if api.app.Cluster() == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msg := &model.ClusterMessage{
|
2021-07-12 14:05:36 -04:00
|
|
|
Event: model.ClusterEventPluginEvent,
|
2021-04-28 13:59:32 -04:00
|
|
|
SendType: opts.SendType,
|
|
|
|
|
WaitForAllToSend: false,
|
|
|
|
|
Props: map[string]string{
|
|
|
|
|
"PluginID": api.id,
|
|
|
|
|
"EventID": ev.Id,
|
|
|
|
|
},
|
2021-07-26 04:11:20 -04:00
|
|
|
Data: ev.Data,
|
2021-04-28 13:59:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If TargetId is empty we broadcast to all other cluster nodes.
|
|
|
|
|
if opts.TargetId == "" {
|
|
|
|
|
api.app.Cluster().SendClusterMessage(msg)
|
|
|
|
|
} else {
|
|
|
|
|
if err := api.app.Cluster().SendClusterMessageToNode(opts.TargetId, msg); err != nil {
|
|
|
|
|
return fmt.Errorf("failed to send message to cluster node %q: %w", opts.TargetId, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2021-05-14 04:35:59 -04:00
|
|
|
|
|
|
|
|
// RequestTrialLicense requests a trial license and installs it in the server
|
|
|
|
|
func (api *PluginAPI) RequestTrialLicense(requesterID string, users int, termsAccepted bool, receiveEmailsAccepted bool) *model.AppError {
|
2025-04-10 15:22:03 -04:00
|
|
|
// Normally, plugins are unrestricted in their abilities, but to maintain backwards compatbilibity with plugins
|
|
|
|
|
// that were unaware of the nuances of ExperimentalSettings.RestrictSystemAdmin, we restrict the trial license
|
|
|
|
|
// unconditionally.
|
2021-05-14 04:35:59 -04:00
|
|
|
if *api.app.Config().ExperimentalSettings.RestrictSystemAdmin {
|
|
|
|
|
return model.NewAppError("RequestTrialLicense", "api.restricted_system_admin", nil, "", http.StatusForbidden)
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 22:30:29 -05:00
|
|
|
return api.app.Channels().RequestTrialLicense(requesterID, users, termsAccepted, receiveEmailsAccepted)
|
2021-05-14 04:35:59 -04:00
|
|
|
}
|
2022-05-09 09:05:50 -04:00
|
|
|
|
|
|
|
|
// GetCloudLimits returns any limits associated with the cloud instance
|
|
|
|
|
func (api *PluginAPI) GetCloudLimits() (*model.ProductLimits, error) {
|
2022-05-12 11:05:44 -04:00
|
|
|
if api.app.Cloud() == nil {
|
|
|
|
|
return &model.ProductLimits{}, nil
|
|
|
|
|
}
|
2022-05-09 09:05:50 -04:00
|
|
|
limits, err := api.app.Cloud().GetCloudLimits("")
|
|
|
|
|
return limits, err
|
|
|
|
|
}
|
2022-11-03 14:43:30 -04:00
|
|
|
|
2023-06-30 14:31:25 -04:00
|
|
|
// RegisterCollectionAndTopic is no longer supported.
|
2022-11-03 14:43:30 -04:00
|
|
|
func (api *PluginAPI) RegisterCollectionAndTopic(collectionType, topicType string) error {
|
2023-06-30 14:31:25 -04:00
|
|
|
return nil
|
2022-11-03 14:43:30 -04:00
|
|
|
}
|
2022-11-22 16:26:22 -05:00
|
|
|
|
|
|
|
|
func (api *PluginAPI) CreateUploadSession(us *model.UploadSession) (*model.UploadSession, error) {
|
|
|
|
|
us, err := api.app.CreateUploadSession(api.ctx, us)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return us, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UploadData(us *model.UploadSession, rd io.Reader) (*model.FileInfo, error) {
|
|
|
|
|
fi, err := api.app.UploadData(api.ctx, us, rd)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return fi, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetUploadSession(uploadID string) (*model.UploadSession, error) {
|
2022-12-13 12:47:05 -05:00
|
|
|
// We want to fetch from master DB to avoid a potential read-after-write on the plugin side.
|
2023-11-06 06:26:17 -05:00
|
|
|
api.ctx = api.ctx.With(RequestContextWithMaster)
|
2022-12-13 12:47:05 -05:00
|
|
|
fi, err := api.app.GetUploadSession(api.ctx, uploadID)
|
2022-11-22 16:26:22 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return fi, nil
|
|
|
|
|
}
|
2023-08-18 13:05:26 -04:00
|
|
|
|
2023-08-24 12:33:53 -04:00
|
|
|
func (api *PluginAPI) SendPushNotification(notification *model.PushNotification, userID string) *model.AppError {
|
|
|
|
|
// Ignoring skipSessionId because it's only used internally to clear push notifications
|
2024-04-24 05:52:33 -04:00
|
|
|
return api.app.sendPushNotificationToAllSessions(api.ctx, notification, userID, "")
|
2023-08-18 13:05:26 -04:00
|
|
|
}
|
Shared channels plugin APIs for MS Teams plugin (#25805)
New plugin APIs and hooks for accessing Shared Channels service via plugin.
- RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error)
- UnregisterPluginForSharedChannels(pluginID string) error
- ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
- UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
- UnshareChannel(channelID string) (unshared bool, err error)
- UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error
- SyncSharedChannel(channelID string) error
- InviteRemoteToChannel(channelID string, remoteID string, userID string) error
- UninviteRemoteFromChannel(channelID string, remoteID string) error
Hooks
- OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error)
- OnSharedChannelsPing(rc *model.RemoteCluster) bool
2023-12-22 17:00:27 -05:00
|
|
|
|
|
|
|
|
func (api *PluginAPI) RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error) {
|
2024-04-24 05:52:33 -04:00
|
|
|
return api.app.RegisterPluginForSharedChannels(api.ctx, opts)
|
Shared channels plugin APIs for MS Teams plugin (#25805)
New plugin APIs and hooks for accessing Shared Channels service via plugin.
- RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error)
- UnregisterPluginForSharedChannels(pluginID string) error
- ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
- UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
- UnshareChannel(channelID string) (unshared bool, err error)
- UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error
- SyncSharedChannel(channelID string) error
- InviteRemoteToChannel(channelID string, remoteID string, userID string) error
- UninviteRemoteFromChannel(channelID string, remoteID string) error
Hooks
- OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error)
- OnSharedChannelsPing(rc *model.RemoteCluster) bool
2023-12-22 17:00:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UnregisterPluginForSharedChannels(pluginID string) error {
|
|
|
|
|
return api.app.UnregisterPluginForSharedChannels(pluginID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error) {
|
2024-01-09 06:42:11 -05:00
|
|
|
scShared, err := api.app.ShareChannel(api.ctx, sc)
|
2024-02-09 10:47:12 -05:00
|
|
|
if errors.Is(err, model.ErrChannelAlreadyShared) {
|
2024-01-09 06:42:11 -05:00
|
|
|
// sharing an already shared channel is not an error; treat as idempotent and return the existing shared channel
|
|
|
|
|
return api.app.GetSharedChannel(sc.ChannelId)
|
|
|
|
|
}
|
|
|
|
|
return scShared, err
|
Shared channels plugin APIs for MS Teams plugin (#25805)
New plugin APIs and hooks for accessing Shared Channels service via plugin.
- RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error)
- UnregisterPluginForSharedChannels(pluginID string) error
- ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
- UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
- UnshareChannel(channelID string) (unshared bool, err error)
- UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error
- SyncSharedChannel(channelID string) error
- InviteRemoteToChannel(channelID string, remoteID string, userID string) error
- UninviteRemoteFromChannel(channelID string, remoteID string) error
Hooks
- OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error)
- OnSharedChannelsPing(rc *model.RemoteCluster) bool
2023-12-22 17:00:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error) {
|
|
|
|
|
return api.app.UpdateSharedChannel(sc)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UnshareChannel(channelID string) (unshared bool, err error) {
|
|
|
|
|
return api.app.UnshareChannel(channelID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error {
|
|
|
|
|
return api.app.UpdateSharedChannelCursor(channelID, remoteID, cusror)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) SyncSharedChannel(channelID string) error {
|
|
|
|
|
return api.app.SyncSharedChannel(channelID)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-09 10:47:12 -05:00
|
|
|
func (api *PluginAPI) InviteRemoteToChannel(channelID string, remoteID, userID string, shareIfNotShared bool) error {
|
|
|
|
|
return api.app.InviteRemoteToChannel(channelID, remoteID, userID, shareIfNotShared)
|
Shared channels plugin APIs for MS Teams plugin (#25805)
New plugin APIs and hooks for accessing Shared Channels service via plugin.
- RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error)
- UnregisterPluginForSharedChannels(pluginID string) error
- ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
- UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
- UnshareChannel(channelID string) (unshared bool, err error)
- UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error
- SyncSharedChannel(channelID string) error
- InviteRemoteToChannel(channelID string, remoteID string, userID string) error
- UninviteRemoteFromChannel(channelID string, remoteID string) error
Hooks
- OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error)
- OnSharedChannelsPing(rc *model.RemoteCluster) bool
2023-12-22 17:00:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UninviteRemoteFromChannel(channelID string, remoteID string) error {
|
|
|
|
|
return api.app.UninviteRemoteFromChannel(channelID, remoteID)
|
|
|
|
|
}
|
2024-08-26 07:39:29 -04:00
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetPluginID() string {
|
|
|
|
|
return api.id
|
|
|
|
|
}
|
2025-03-13 12:00:15 -04:00
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetGroups(page, perPage int, opts model.GroupSearchOpts, viewRestrictions *model.ViewUsersRestrictions) ([]*model.Group, *model.AppError) {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
2025-04-09 05:38:36 -04:00
|
|
|
return nil, model.NewAppError("GetGroups", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
2025-03-13 12:00:15 -04:00
|
|
|
}
|
|
|
|
|
return api.app.GetGroups(page, perPage, opts, viewRestrictions)
|
|
|
|
|
}
|
2025-05-21 14:44:34 -04:00
|
|
|
|
|
|
|
|
func (api *PluginAPI) CreateDefaultSyncableMemberships(params model.CreateDefaultMembershipParams) *model.AppError {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
|
|
|
|
return model.NewAppError("CreateDefaultSyncableMemberships", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := api.app.CreateDefaultMemberships(api.ctx, params)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return model.NewAppError("CreateDefaultSyncableMemberships", "app.group.create_syncable_memberships.error", nil, "", http.StatusInternalServerError).Wrap(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteGroupConstrainedMemberships() *model.AppError {
|
|
|
|
|
if err := api.checkLDAPLicense(); err != nil {
|
|
|
|
|
return model.NewAppError("DeleteGroupConstrainedMemberships", "app.group.license_error", nil, "", http.StatusForbidden).Wrap(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := api.app.DeleteGroupConstrainedMemberships(api.ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return model.NewAppError("DeleteGroupConstrainedMemberships", "app.group.delete_invalid_syncable_memberships.error", nil, "", http.StatusInternalServerError).Wrap(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2025-06-10 19:10:28 -04:00
|
|
|
|
|
|
|
|
func (api *PluginAPI) CreatePropertyField(field *model.PropertyField) (*model.PropertyField, error) {
|
2025-09-11 15:49:14 -04:00
|
|
|
if field == nil {
|
|
|
|
|
return nil, fmt.Errorf("invalid input: property field parameter is required")
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 19:10:28 -04:00
|
|
|
return api.app.PropertyService().CreatePropertyField(field)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetPropertyField(groupID, fieldID string) (*model.PropertyField, error) {
|
|
|
|
|
return api.app.PropertyService().GetPropertyField(groupID, fieldID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetPropertyFields(groupID string, ids []string) ([]*model.PropertyField, error) {
|
|
|
|
|
return api.app.PropertyService().GetPropertyFields(groupID, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdatePropertyField(groupID string, field *model.PropertyField) (*model.PropertyField, error) {
|
|
|
|
|
return api.app.PropertyService().UpdatePropertyField(groupID, field)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeletePropertyField(groupID, fieldID string) error {
|
|
|
|
|
return api.app.PropertyService().DeletePropertyField(groupID, fieldID)
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 18:56:01 -04:00
|
|
|
func (api *PluginAPI) SearchPropertyFields(groupID string, opts model.PropertyFieldSearchOpts) ([]*model.PropertyField, error) {
|
|
|
|
|
return api.app.PropertyService().SearchPropertyFields(groupID, opts)
|
2025-06-10 19:10:28 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-11 15:49:14 -04:00
|
|
|
func (api *PluginAPI) CountPropertyFields(groupID string, includeDeleted bool) (int64, error) {
|
|
|
|
|
if includeDeleted {
|
|
|
|
|
return api.app.PropertyService().CountAllPropertyFieldsForGroup(groupID)
|
|
|
|
|
}
|
|
|
|
|
return api.app.PropertyService().CountActivePropertyFieldsForGroup(groupID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) CountPropertyFieldsForTarget(groupID, targetType, targetID string, includeDeleted bool) (int64, error) {
|
|
|
|
|
if includeDeleted {
|
|
|
|
|
return api.app.PropertyService().CountAllPropertyFieldsForTarget(groupID, targetType, targetID)
|
|
|
|
|
}
|
|
|
|
|
return api.app.PropertyService().CountActivePropertyFieldsForTarget(groupID, targetType, targetID)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 19:10:28 -04:00
|
|
|
func (api *PluginAPI) CreatePropertyValue(value *model.PropertyValue) (*model.PropertyValue, error) {
|
|
|
|
|
return api.app.PropertyService().CreatePropertyValue(value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetPropertyValue(groupID, valueID string) (*model.PropertyValue, error) {
|
|
|
|
|
return api.app.PropertyService().GetPropertyValue(groupID, valueID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetPropertyValues(groupID string, ids []string) ([]*model.PropertyValue, error) {
|
|
|
|
|
return api.app.PropertyService().GetPropertyValues(groupID, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdatePropertyValue(groupID string, value *model.PropertyValue) (*model.PropertyValue, error) {
|
|
|
|
|
return api.app.PropertyService().UpdatePropertyValue(groupID, value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpsertPropertyValue(value *model.PropertyValue) (*model.PropertyValue, error) {
|
|
|
|
|
return api.app.PropertyService().UpsertPropertyValue(value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeletePropertyValue(groupID, valueID string) error {
|
|
|
|
|
return api.app.PropertyService().DeletePropertyValue(groupID, valueID)
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 18:56:01 -04:00
|
|
|
func (api *PluginAPI) SearchPropertyValues(groupID string, opts model.PropertyValueSearchOpts) ([]*model.PropertyValue, error) {
|
|
|
|
|
return api.app.PropertyService().SearchPropertyValues(groupID, opts)
|
2025-06-10 19:10:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) RegisterPropertyGroup(name string) (*model.PropertyGroup, error) {
|
|
|
|
|
return api.app.PropertyService().RegisterPropertyGroup(name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetPropertyGroup(name string) (*model.PropertyGroup, error) {
|
|
|
|
|
return api.app.PropertyService().GetPropertyGroup(name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetPropertyFieldByName(groupID, targetID, name string) (*model.PropertyField, error) {
|
|
|
|
|
return api.app.PropertyService().GetPropertyFieldByName(groupID, targetID, name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdatePropertyFields(groupID string, fields []*model.PropertyField) ([]*model.PropertyField, error) {
|
|
|
|
|
return api.app.PropertyService().UpdatePropertyFields(groupID, fields)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdatePropertyValues(groupID string, values []*model.PropertyValue) ([]*model.PropertyValue, error) {
|
|
|
|
|
return api.app.PropertyService().UpdatePropertyValues(groupID, values)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpsertPropertyValues(values []*model.PropertyValue) ([]*model.PropertyValue, error) {
|
|
|
|
|
return api.app.PropertyService().UpsertPropertyValues(values)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeletePropertyValuesForTarget(groupID, targetType, targetID string) error {
|
|
|
|
|
return api.app.PropertyService().DeletePropertyValuesForTarget(groupID, targetType, targetID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeletePropertyValuesForField(groupID, fieldID string) error {
|
|
|
|
|
return api.app.PropertyService().DeletePropertyValuesForField(groupID, fieldID)
|
|
|
|
|
}
|