summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-09-21 14:00:14 -0500
committerGitHub <noreply@github.com>2017-09-21 14:00:14 -0500
commite525383c52b0c65ad3b3f6cdbee73f56e1e3f67d (patch)
treee46d2dcd0dcad346da8641f4bd62f9134bc80699 /app
parent266ff8670244da288aec937320d9eecc7996af35 (diff)
downloadchat-e525383c52b0c65ad3b3f6cdbee73f56e1e3f67d.tar.gz
chat-e525383c52b0c65ad3b3f6cdbee73f56e1e3f67d.tar.bz2
chat-e525383c52b0c65ad3b3f6cdbee73f56e1e3f67d.zip
plugin CRUD operations for users, posts, channels, and teams (#7479)
Diffstat (limited to 'app')
-rw-r--r--app/channel.go44
-rw-r--r--app/plugins.go82
2 files changed, 108 insertions, 18 deletions
diff --git a/app/channel.go b/app/channel.go
index 8ca3a563a..436d429c9 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -413,18 +413,24 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelId s
}
func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppError {
- uc := a.Srv.Store.User().Get(userId)
ihc := a.Srv.Store.Webhook().GetIncomingByChannel(channel.Id)
ohc := a.Srv.Store.Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
- if uresult := <-uc; uresult.Err != nil {
- return uresult.Err
- } else if ihcresult := <-ihc; ihcresult.Err != nil {
+ var user *model.User
+ if userId != "" {
+ uc := a.Srv.Store.User().Get(userId)
+ uresult := <-uc
+ if uresult.Err != nil {
+ return uresult.Err
+ }
+ user = uresult.Data.(*model.User)
+ }
+
+ if ihcresult := <-ihc; ihcresult.Err != nil {
return ihcresult.Err
} else if ohcresult := <-ohc; ohcresult.Err != nil {
return ohcresult.Err
} else {
- user := uresult.Data.(*model.User)
incomingHooks := ihcresult.Data.([]*model.IncomingWebhook)
outgoingHooks := ohcresult.Data.([]*model.OutgoingWebhook)
@@ -438,20 +444,22 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
return err
}
- T := utils.GetUserTranslations(user.Locale)
-
- post := &model.Post{
- ChannelId: channel.Id,
- Message: fmt.Sprintf(T("api.channel.delete_channel.archived"), user.Username),
- Type: model.POST_CHANNEL_DELETED,
- UserId: userId,
- Props: model.StringInterface{
- "username": user.Username,
- },
- }
+ if user != nil {
+ T := utils.GetUserTranslations(user.Locale)
+
+ post := &model.Post{
+ ChannelId: channel.Id,
+ Message: fmt.Sprintf(T("api.channel.delete_channel.archived"), user.Username),
+ Type: model.POST_CHANNEL_DELETED,
+ UserId: userId,
+ Props: model.StringInterface{
+ "username": user.Username,
+ },
+ }
- if _, err := a.CreatePost(post, channel, false); err != nil {
- l4g.Error(utils.T("api.channel.delete_channel.failed_post.error"), err)
+ if _, err := a.CreatePost(post, channel, false); err != nil {
+ l4g.Error(utils.T("api.channel.delete_channel.failed_post.error"), err)
+ }
}
now := model.GetMillis()
diff --git a/app/plugins.go b/app/plugins.go
index 86c18ce22..450cfebeb 100644
--- a/app/plugins.go
+++ b/app/plugins.go
@@ -40,22 +40,104 @@ func (api *PluginAPI) LoadPluginConfiguration(dest interface{}) error {
}
}
+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)
+}
+
+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)
+}
+
+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)
}
+func (api *PluginAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) {
+ return api.app.UpdateUser(user, true)
+}
+
+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, "")
+}
+
+func (api *PluginAPI) GetChannel(channelId string) (*model.Channel, *model.AppError) {
+ return api.app.GetChannel(channelId)
+}
+
func (api *PluginAPI) GetChannelByName(name, teamId string) (*model.Channel, *model.AppError) {
return api.app.GetChannelByName(name, teamId)
}
+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)
+}
+
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
return api.app.CreatePostMissingChannel(post, true)
}
+func (api *PluginAPI) DeletePost(postId string) *model.AppError {
+ _, err := api.app.DeletePost(postId)
+ return err
+}
+
+func (api *PluginAPI) GetPost(postId string) (*model.Post, *model.AppError) {
+ return api.app.GetSinglePost(postId)
+}
+
+func (api *PluginAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
+ return api.app.UpdatePost(post, false)
+}
+
type BuiltInPluginAPI struct {
id string
router *mux.Router