2017-11-27 17:23:35 -05:00
|
|
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2018-06-27 08:46:38 -04:00
|
|
|
"fmt"
|
2018-07-16 15:49:26 -04:00
|
|
|
"net/http"
|
2018-07-09 07:25:57 -07:00
|
|
|
"strings"
|
2017-11-27 17:23:35 -05:00
|
|
|
|
2018-07-03 09:58:28 -07:00
|
|
|
"github.com/mattermost/mattermost-server/mlog"
|
2017-11-27 17:23:35 -05:00
|
|
|
"github.com/mattermost/mattermost-server/model"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PluginAPI struct {
|
2018-07-09 07:25:57 -07:00
|
|
|
id string
|
|
|
|
|
app *App
|
|
|
|
|
logger *mlog.SugarLogger
|
|
|
|
|
manifest *model.Manifest
|
2017-11-27 17:23:35 -05:00
|
|
|
}
|
|
|
|
|
|
2018-06-25 12:33:13 -07:00
|
|
|
func NewPluginAPI(a *App, manifest *model.Manifest) *PluginAPI {
|
|
|
|
|
return &PluginAPI{
|
2018-07-09 07:25:57 -07:00
|
|
|
id: manifest.Id,
|
|
|
|
|
manifest: manifest,
|
|
|
|
|
app: a,
|
|
|
|
|
logger: a.Log.With(mlog.String("plugin_id", manifest.Id)).Sugar(),
|
2018-06-25 12:33:13 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) LoadPluginConfiguration(dest interface{}) error {
|
2018-07-09 07:25:57 -07:00
|
|
|
finalConfig := make(map[string]interface{})
|
|
|
|
|
|
|
|
|
|
// 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 07:25:57 -07: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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if pluginSettingsJsonBytes, err := json.Marshal(finalConfig); err != nil {
|
2018-07-27 05:25:53 -07:00
|
|
|
api.logger.Error("Error marshaling config for plugin", mlog.Err(err))
|
|
|
|
|
return nil
|
2017-11-27 17:23:35 -05:00
|
|
|
} else {
|
2018-07-27 05:25:53 -07: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 13:55:41 -06:00
|
|
|
func (api *PluginAPI) RegisterCommand(command *model.Command) error {
|
|
|
|
|
return api.app.RegisterPluginCommand(api.id, command)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UnregisterCommand(teamId, trigger string) error {
|
|
|
|
|
api.app.UnregisterPluginCommand(api.id, teamId, trigger)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 00:16:04 +02:00
|
|
|
func (api *PluginAPI) GetSession(sessionId string) (*model.Session, *model.AppError) {
|
|
|
|
|
session, err := api.app.GetSessionById(sessionId)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return session, nil
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-07 00:32:55 +02:00
|
|
|
func (api *PluginAPI) GetConfig() *model.Config {
|
|
|
|
|
return api.app.GetConfig()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) SaveConfig(config *model.Config) *model.AppError {
|
|
|
|
|
return api.app.SaveConfig(config, true)
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 18:56:47 +02:00
|
|
|
func (api *PluginAPI) GetServerVersion() string {
|
|
|
|
|
return model.CurrentVersion
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) CreateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.CreateTeam(team)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteTeam(teamId string) *model.AppError {
|
|
|
|
|
return api.app.SoftDeleteTeam(teamId)
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-07 00:32:55 +02:00
|
|
|
func (api *PluginAPI) GetTeams() ([]*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.GetAllTeams()
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) GetTeam(teamId string) (*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.GetTeam(teamId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetTeamByName(name string) (*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.GetTeamByName(name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.UpdateTeam(team)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 16:37:52 +02:00
|
|
|
func (api *PluginAPI) GetTeamsForUser(userId string) ([]*model.Team, *model.AppError) {
|
|
|
|
|
return api.app.GetTeamsForUser(userId)
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-07 00:32:55 +02:00
|
|
|
func (api *PluginAPI) CreateTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) {
|
|
|
|
|
return api.app.AddTeamMember(teamId, userId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError) {
|
|
|
|
|
return api.app.AddTeamMembers(teamId, userIds, requestorId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteTeamMember(teamId, userId, requestorId string) *model.AppError {
|
|
|
|
|
return api.app.RemoveUserFromTeam(teamId, userId, requestorId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetTeamMembers(teamId string, offset, limit int) ([]*model.TeamMember, *model.AppError) {
|
|
|
|
|
return api.app.GetTeamMembers(teamId, offset, limit)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) {
|
|
|
|
|
return api.app.GetTeamMember(teamId, userId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateTeamMemberRoles(teamId, userId, newRoles string) (*model.TeamMember, *model.AppError) {
|
|
|
|
|
return api.app.UpdateTeamMemberRoles(teamId, userId, newRoles)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) CreateUser(user *model.User) (*model.User, *model.AppError) {
|
|
|
|
|
return api.app.CreateUser(user)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteUser(userId string) *model.AppError {
|
|
|
|
|
user, err := api.app.GetUser(userId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
_, err = api.app.UpdateActive(user, false)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetUser(userId string) (*model.User, *model.AppError) {
|
|
|
|
|
return api.app.GetUser(userId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 15:11:30 +02:00
|
|
|
func (api *PluginAPI) GetUsersByUsernames(usernames []string) ([]*model.User, *model.AppError) {
|
|
|
|
|
return api.app.GetUsersByUsernames(usernames, true)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:24:26 +02:00
|
|
|
func (api *PluginAPI) GetUsersInTeam(teamId string, page int, perPage int) ([]*model.User, *model.AppError) {
|
|
|
|
|
return api.app.GetUsersInTeam(teamId, page, perPage)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) {
|
|
|
|
|
return api.app.UpdateUser(user, true)
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-16 15:49:26 -04:00
|
|
|
func (api *PluginAPI) GetUserStatus(userId string) (*model.Status, *model.AppError) {
|
|
|
|
|
return api.app.GetStatus(userId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError) {
|
|
|
|
|
return api.app.GetUserStatusesByIds(userIds)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateUserStatus(userId, status string) (*model.Status, *model.AppError) {
|
|
|
|
|
switch status {
|
|
|
|
|
case model.STATUS_ONLINE:
|
|
|
|
|
api.app.SetStatusOnline(userId, true)
|
|
|
|
|
case model.STATUS_OFFLINE:
|
|
|
|
|
api.app.SetStatusOffline(userId, true)
|
|
|
|
|
case model.STATUS_AWAY:
|
|
|
|
|
api.app.SetStatusAwayIfNeeded(userId, true)
|
|
|
|
|
case model.STATUS_DND:
|
|
|
|
|
api.app.SetStatusDoNotDisturb(userId)
|
|
|
|
|
default:
|
|
|
|
|
return nil, model.NewAppError("UpdateUserStatus", "plugin.api.update_user_status.bad_status", nil, "unrecognized status", http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return api.app.GetStatus(userId)
|
|
|
|
|
}
|
2018-10-22 08:49:50 -04:00
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError) {
|
|
|
|
|
switch sortBy {
|
|
|
|
|
case model.CHANNEL_SORT_BY_USERNAME:
|
|
|
|
|
return api.app.GetUsersInChannel(channelId, page*perPage, perPage)
|
|
|
|
|
case model.CHANNEL_SORT_BY_STATUS:
|
|
|
|
|
return api.app.GetUsersInChannelByStatus(channelId, page*perPage, perPage)
|
|
|
|
|
default:
|
|
|
|
|
return nil, model.NewAppError("GetUsersInChannel", "plugin.api.get_users_in_channel", nil, "invalid sort option", http.StatusBadRequest)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 14:07:27 -04:00
|
|
|
func (api *PluginAPI) GetLDAPUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError) {
|
|
|
|
|
if api.app.Ldap == nil {
|
|
|
|
|
return nil, model.NewAppError("GetLdapUserAttributes", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user, err := api.app.GetUser(userId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if user.AuthService != model.USER_AUTH_SERVICE_LDAP || user.AuthData == nil {
|
|
|
|
|
return map[string]string{}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return api.app.Ldap.GetUserAttributes(*user.AuthData, attributes)
|
|
|
|
|
}
|
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) {
|
|
|
|
|
return api.app.CreateChannel(channel, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteChannel(channelId string) *model.AppError {
|
|
|
|
|
channel, err := api.app.GetChannel(channelId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return api.app.DeleteChannel(channel, "")
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-07 00:32:55 +02:00
|
|
|
func (api *PluginAPI) GetPublicChannelsForTeam(teamId string, offset, limit int) (*model.ChannelList, *model.AppError) {
|
|
|
|
|
return api.app.GetPublicChannelsForTeam(teamId, offset, limit)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) GetChannel(channelId string) (*model.Channel, *model.AppError) {
|
|
|
|
|
return api.app.GetChannel(channelId)
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 15:06:08 -04:00
|
|
|
func (api *PluginAPI) GetChannelByName(teamId, name string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
|
|
|
|
return api.app.GetChannelByName(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) {
|
|
|
|
|
return api.app.GetChannelByNameForTeamName(channelName, teamName, includeDeleted)
|
2018-07-20 12:03:08 -04:00
|
|
|
}
|
|
|
|
|
|
2018-10-15 18:27:45 +02:00
|
|
|
func (api *PluginAPI) GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
|
|
|
|
|
return api.app.GetChannelsForUser(teamId, userId, includeDeleted)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 17:24:43 +00:00
|
|
|
func (api *PluginAPI) GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError) {
|
|
|
|
|
memberCount, err := api.app.GetChannelMemberCount(channelId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &model.ChannelStats{ChannelId: channelId, MemberCount: memberCount}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError) {
|
|
|
|
|
return api.app.GetDirectChannel(userId1, userId2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
|
|
|
|
|
return api.app.CreateGroupChannel(userIds, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
|
|
|
|
return api.app.UpdateChannel(channel)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 12:23:46 -04:00
|
|
|
func (api *PluginAPI) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {
|
|
|
|
|
return api.app.SearchChannels(teamId, term)
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-06 17:08:57 -04:00
|
|
|
func (api *PluginAPI) AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
|
|
|
|
|
// For now, don't allow overriding these via the plugin API.
|
|
|
|
|
userRequestorId := ""
|
|
|
|
|
postRootId := ""
|
|
|
|
|
|
|
|
|
|
channel, err := api.GetChannel(channelId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-26 16:34:12 +02:00
|
|
|
return api.app.AddChannelMember(userId, channel, userRequestorId, postRootId, false)
|
2018-04-06 17:08:57 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 09:14:03 -05:00
|
|
|
func (api *PluginAPI) GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
|
|
|
|
|
return api.app.GetChannelMember(channelId, userId)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-04 01:37:54 +05:30
|
|
|
func (api *PluginAPI) GetChannelMembers(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
|
|
|
|
|
return api.app.GetChannelMembersPage(channelId, page, perPage)
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-06 17:08:57 -04:00
|
|
|
func (api *PluginAPI) UpdateChannelMemberRoles(channelId, userId, newRoles string) (*model.ChannelMember, *model.AppError) {
|
|
|
|
|
return api.app.UpdateChannelMemberRoles(channelId, userId, newRoles)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) UpdateChannelMemberNotifications(channelId, userId string, notifications map[string]string) (*model.ChannelMember, *model.AppError) {
|
|
|
|
|
return api.app.UpdateChannelMemberNotifyProps(notifications, channelId, userId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) DeleteChannelMember(channelId, userId string) *model.AppError {
|
|
|
|
|
return api.app.LeaveChannel(channelId, userId)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
|
|
|
|
return api.app.CreatePostMissingChannel(post, true)
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 18:22:08 +02:00
|
|
|
func (api *PluginAPI) AddReaction(reaction *model.Reaction) (*model.Reaction, *model.AppError) {
|
|
|
|
|
return api.app.SaveReactionForPost(reaction)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) RemoveReaction(reaction *model.Reaction) *model.AppError {
|
|
|
|
|
return api.app.DeleteReactionForPost(reaction)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) GetReactions(postId string) ([]*model.Reaction, *model.AppError) {
|
|
|
|
|
return api.app.GetReactionsForPost(postId)
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-07 00:32:55 +02:00
|
|
|
func (api *PluginAPI) SendEphemeralPost(userId string, post *model.Post) *model.Post {
|
|
|
|
|
return api.app.SendEphemeralPost(userId, post)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) DeletePost(postId string) *model.AppError {
|
2018-06-01 12:45:46 -04:00
|
|
|
_, err := api.app.DeletePost(postId, api.id)
|
2017-11-27 17:23:35 -05:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 15:19:36 +02:00
|
|
|
func (api *PluginAPI) GetPostThread(postId string) (*model.PostList, *model.AppError) {
|
|
|
|
|
return api.app.GetPostThread(postId)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) GetPost(postId string) (*model.Post, *model.AppError) {
|
|
|
|
|
return api.app.GetSinglePost(postId)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 16:04:22 +02:00
|
|
|
func (api *PluginAPI) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) {
|
|
|
|
|
return api.app.GetPostsSince(channelId, time)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 18:11:15 +02:00
|
|
|
func (api *PluginAPI) GetPostsAfter(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
|
|
|
|
return api.app.GetPostsAfterPost(channelId, postId, page, perPage)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 19:18:23 +02:00
|
|
|
func (api *PluginAPI) GetPostsBefore(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
|
|
|
|
return api.app.GetPostsBeforePost(channelId, postId, page, perPage)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-10 18:53:36 +05:30
|
|
|
func (api *PluginAPI) GetPostsForChannel(channelId string, page, perPage int) (*model.PostList, *model.AppError) {
|
|
|
|
|
return api.app.GetPostsPage(channelId, page, perPage)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 17:23:35 -05:00
|
|
|
func (api *PluginAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
|
|
|
|
|
return api.app.UpdatePost(post, false)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 16:23:41 +02:00
|
|
|
func (api *PluginAPI) GetProfileImage(userId string) ([]byte, *model.AppError) {
|
|
|
|
|
user, err := api.app.GetUser(userId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data, _, err := api.app.GetProfileImage(user)
|
|
|
|
|
return data, err
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 17:09:30 -04:00
|
|
|
func (api *PluginAPI) GetEmojiByName(name string) (*model.Emoji, *model.AppError) {
|
|
|
|
|
return api.app.GetEmojiByName(name)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 13:54:10 +00:00
|
|
|
func (api *PluginAPI) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) {
|
|
|
|
|
return api.app.GetEmoji(emojiId)
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 10:37:31 -04:00
|
|
|
func (api *PluginAPI) CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError) {
|
|
|
|
|
return api.app.CopyFileInfos(userId, fileIds)
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 13:18:25 -03:00
|
|
|
func (api *PluginAPI) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
|
|
|
|
return api.app.GetFileInfo(fileId)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 20:31:51 -04:00
|
|
|
func (api *PluginAPI) GetFileLink(fileId string) (string, *model.AppError) {
|
|
|
|
|
if !api.app.Config().FileSettings.EnablePublicLink {
|
|
|
|
|
return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.disabled.app_error", nil, "", http.StatusNotImplemented)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info, err := api.app.GetFileInfo(fileId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(info.PostId) == 0 {
|
|
|
|
|
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 13:18:25 -03:00
|
|
|
func (api *PluginAPI) ReadFile(path string) ([]byte, *model.AppError) {
|
|
|
|
|
return api.app.ReadFile(path)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 04:07:21 +08:00
|
|
|
func (api *PluginAPI) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) {
|
|
|
|
|
return api.app.GetEmojiImage(emojiId)
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 12:33:13 -07: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
|
|
|
}
|
|
|
|
|
|
2018-10-10 19:55:12 +02: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 12:33:13 -07: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 12:33:13 -07: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 19:55:12 +02:00
|
|
|
func (api *PluginAPI) KVDeleteAll() *model.AppError {
|
|
|
|
|
return api.app.DeleteAllKeysForPlugin(api.id)
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-03 13:04:37 -07:00
|
|
|
func (api *PluginAPI) KVList(page, perPage int) ([]string, *model.AppError) {
|
|
|
|
|
return api.app.ListPluginKeys(api.id, page, perPage)
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 08:46:38 -04:00
|
|
|
func (api *PluginAPI) PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) {
|
|
|
|
|
api.app.Publish(&model.WebSocketEvent{
|
|
|
|
|
Event: fmt.Sprintf("custom_%v_%v", api.id, event),
|
|
|
|
|
Data: payload,
|
|
|
|
|
Broadcast: broadcast,
|
|
|
|
|
})
|
|
|
|
|
}
|
2018-07-03 09:58:28 -07:00
|
|
|
|
2018-08-20 18:22:08 +02:00
|
|
|
func (api *PluginAPI) HasPermissionTo(userId string, permission *model.Permission) bool {
|
|
|
|
|
return api.app.HasPermissionTo(userId, permission)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) HasPermissionToTeam(userId, teamId string, permission *model.Permission) bool {
|
|
|
|
|
return api.app.HasPermissionToTeam(userId, teamId, permission)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (api *PluginAPI) HasPermissionToChannel(userId, channelId string, permission *model.Permission) bool {
|
|
|
|
|
return api.app.HasPermissionToChannel(userId, channelId, permission)
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 09:58:28 -07:00
|
|
|
func (api *PluginAPI) LogDebug(msg string, keyValuePairs ...interface{}) {
|
|
|
|
|
api.logger.Debug(msg, keyValuePairs...)
|
|
|
|
|
}
|
|
|
|
|
func (api *PluginAPI) LogInfo(msg string, keyValuePairs ...interface{}) {
|
|
|
|
|
api.logger.Info(msg, keyValuePairs...)
|
|
|
|
|
}
|
|
|
|
|
func (api *PluginAPI) LogError(msg string, keyValuePairs ...interface{}) {
|
|
|
|
|
api.logger.Error(msg, keyValuePairs...)
|
|
|
|
|
}
|
|
|
|
|
func (api *PluginAPI) LogWarn(msg string, keyValuePairs ...interface{}) {
|
|
|
|
|
api.logger.Warn(msg, keyValuePairs...)
|
|
|
|
|
}
|