plugin CRUD operations for users, posts, channels, and teams (#7479)
Этот коммит содержится в:
@@ -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)
|
||||
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,
|
||||
},
|
||||
}
|
||||
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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Ссылка в новой задаче
Block a user