Initial migration of the store to be sync (#10592)
* Migrating audit store * Final migration example for the audit store * async example * Ending migration * Removing Async helper * Fixing tests * Fixing govet problems with the StoreResult instanstiation
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
957ec1388b
Коммит
12c50eb830
12
app/audit.go
12
app/audit.go
@@ -8,17 +8,9 @@ import (
|
||||
)
|
||||
|
||||
func (a *App) GetAudits(userId string, limit int) (model.Audits, *model.AppError) {
|
||||
result := <-a.Srv.Store.Audit().Get(userId, 0, limit)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(model.Audits), nil
|
||||
return a.Srv.Store.Audit().Get(userId, 0, limit)
|
||||
}
|
||||
|
||||
func (a *App) GetAuditsPage(userId string, page int, perPage int) (model.Audits, *model.AppError) {
|
||||
result := <-a.Srv.Store.Audit().Get(userId, page*perPage, perPage)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(model.Audits), nil
|
||||
return a.Srv.Store.Audit().Get(userId, page*perPage, perPage)
|
||||
}
|
||||
|
||||
20
app/bot.go
20
app/bot.go
@@ -34,22 +34,21 @@ func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot,
|
||||
|
||||
bot.Patch(botPatch)
|
||||
|
||||
result := <-a.Srv.Store.User().Get(botUserId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
user, err := a.Srv.Store.User().Get(botUserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
patchedUser := model.UserFromBot(bot)
|
||||
user.Id = patchedUser.Id
|
||||
user.Username = patchedUser.Username
|
||||
user.Email = patchedUser.Email
|
||||
user.FirstName = patchedUser.FirstName
|
||||
if result = <-a.Srv.Store.User().Update(user, true); result.Err != nil {
|
||||
if result := <-a.Srv.Store.User().Update(user, true); result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
result = <-a.Srv.Store.Bot().Update(bot)
|
||||
result := <-a.Srv.Store.Bot().Update(bot)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
@@ -79,17 +78,16 @@ func (a *App) GetBots(options *model.BotGetOptions) (model.BotList, *model.AppEr
|
||||
|
||||
// UpdateBotActive marks a bot as active or inactive, along with its corresponding user.
|
||||
func (a *App) UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError) {
|
||||
result := <-a.Srv.Store.User().Get(botUserId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
user, err := a.Srv.Store.User().Get(botUserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
if _, err := a.UpdateActive(user, active); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result = <-a.Srv.Store.Bot().Get(botUserId, true)
|
||||
result := <-a.Srv.Store.Bot().Get(botUserId, true)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
126
app/channel.go
126
app/channel.go
@@ -36,11 +36,11 @@ func (a *App) CreateDefaultChannels(teamId string) ([]*model.Channel, *model.App
|
||||
func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin bool, userRequestorId string) *model.AppError {
|
||||
var requestor *model.User
|
||||
if userRequestorId != "" {
|
||||
u := <-a.Srv.Store.User().Get(userRequestorId)
|
||||
if u.Err != nil {
|
||||
return u.Err
|
||||
var err *model.AppError
|
||||
requestor, err = a.Srv.Store.User().Get(userRequestorId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
requestor = u.Data.(*model.User)
|
||||
}
|
||||
|
||||
defaultChannelList := []string{"town-square"}
|
||||
@@ -312,8 +312,18 @@ func (a *App) GetOrCreateDirectChannel(userId, otherUserId string) (*model.Chann
|
||||
}
|
||||
|
||||
func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
||||
uc1 := a.Srv.Store.User().Get(userId)
|
||||
uc2 := a.Srv.Store.User().Get(otherUserId)
|
||||
uc1 := make(chan store.StoreResult, 1)
|
||||
uc2 := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
uc1 <- store.StoreResult{Data: user, Err: err}
|
||||
close(uc1)
|
||||
}()
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(otherUserId)
|
||||
uc2 <- store.StoreResult{Data: user, Err: err}
|
||||
close(uc2)
|
||||
}()
|
||||
|
||||
if result := <-uc1; result.Err != nil {
|
||||
return nil, model.NewAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, userId, http.StatusBadRequest)
|
||||
@@ -354,15 +364,15 @@ func (a *App) WaitForChannelMembership(channelId string, userId string) {
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
result := <-a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
_, err := a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
|
||||
// If the membership was found then return
|
||||
if result.Err == nil {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// If we received a error but it wasn't a missing channel member then return
|
||||
if result.Err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -761,12 +771,11 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
|
||||
|
||||
var user *model.User
|
||||
if userId != "" {
|
||||
uc := a.Srv.Store.User().Get(userId)
|
||||
uresult := <-uc
|
||||
if uresult.Err != nil {
|
||||
return uresult.Err
|
||||
var err *model.AppError
|
||||
user, err = a.Srv.Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
user = uresult.Data.(*model.User)
|
||||
}
|
||||
|
||||
ihcresult := <-ihc
|
||||
@@ -844,14 +853,12 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
|
||||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
cmchan := a.Srv.Store.Channel().GetMember(channel.Id, user.Id)
|
||||
|
||||
if result := <-cmchan; result.Err != nil {
|
||||
if result.Err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
return nil, result.Err
|
||||
channelMember, err := a.Srv.Store.Channel().GetMember(channel.Id, user.Id)
|
||||
if err != nil {
|
||||
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
channelMember := result.Data.(*model.ChannelMember)
|
||||
return channelMember, nil
|
||||
}
|
||||
|
||||
@@ -904,12 +911,12 @@ func (a *App) AddUserToChannel(user *model.User, channel *model.Channel) (*model
|
||||
}
|
||||
|
||||
func (a *App) AddChannelMember(userId string, channel *model.Channel, userRequestorId string, postRootId string, currentSessionId string) (*model.ChannelMember, *model.AppError) {
|
||||
if result := <-a.Srv.Store.Channel().GetMember(channel.Id, userId); result.Err != nil {
|
||||
if result.Err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
return nil, result.Err
|
||||
if member, err := a.Srv.Store.Channel().GetMember(channel.Id, userId); err != nil {
|
||||
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return result.Data.(*model.ChannelMember), nil
|
||||
return member, nil
|
||||
}
|
||||
|
||||
var user *model.User
|
||||
@@ -1003,15 +1010,11 @@ func (a *App) AddDirectChannels(teamId string, user *model.User) *model.AppError
|
||||
}
|
||||
|
||||
func (a *App) PostUpdateChannelHeaderMessage(userId string, channel *model.Channel, oldChannelHeader, newChannelHeader string) *model.AppError {
|
||||
uc := a.Srv.Store.User().Get(userId)
|
||||
|
||||
uresult := <-uc
|
||||
if uresult.Err != nil {
|
||||
return model.NewAppError("PostUpdateChannelHeaderMessage", "api.channel.post_update_channel_header_message_and_forget.retrieve_user.error", nil, uresult.Err.Error(), http.StatusBadRequest)
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return model.NewAppError("PostUpdateChannelHeaderMessage", "api.channel.post_update_channel_header_message_and_forget.retrieve_user.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
user := uresult.Data.(*model.User)
|
||||
|
||||
var message string
|
||||
if oldChannelHeader == "" {
|
||||
message = fmt.Sprintf(utils.T("api.channel.post_update_channel_header_message_and_forget.updated_to"), user.Username, newChannelHeader)
|
||||
@@ -1041,15 +1044,11 @@ func (a *App) PostUpdateChannelHeaderMessage(userId string, channel *model.Chann
|
||||
}
|
||||
|
||||
func (a *App) PostUpdateChannelPurposeMessage(userId string, channel *model.Channel, oldChannelPurpose string, newChannelPurpose string) *model.AppError {
|
||||
uc := a.Srv.Store.User().Get(userId)
|
||||
|
||||
uresult := <-uc
|
||||
if uresult.Err != nil {
|
||||
return model.NewAppError("PostUpdateChannelPurposeMessage", "app.channel.post_update_channel_purpose_message.retrieve_user.error", nil, uresult.Err.Error(), http.StatusBadRequest)
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return model.NewAppError("PostUpdateChannelPurposeMessage", "app.channel.post_update_channel_purpose_message.retrieve_user.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
user := uresult.Data.(*model.User)
|
||||
|
||||
var message string
|
||||
if oldChannelPurpose == "" {
|
||||
message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.updated_to"), user.Username, newChannelPurpose)
|
||||
@@ -1078,15 +1077,11 @@ func (a *App) PostUpdateChannelPurposeMessage(userId string, channel *model.Chan
|
||||
}
|
||||
|
||||
func (a *App) PostUpdateChannelDisplayNameMessage(userId string, channel *model.Channel, oldChannelDisplayName, newChannelDisplayName string) *model.AppError {
|
||||
uc := a.Srv.Store.User().Get(userId)
|
||||
|
||||
uresult := <-uc
|
||||
if uresult.Err != nil {
|
||||
return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error", nil, uresult.Err.Error(), http.StatusBadRequest)
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
user := uresult.Data.(*model.User)
|
||||
|
||||
message := fmt.Sprintf(utils.T("api.channel.post_update_channel_displayname_message_and_forget.updated_from"), user.Username, oldChannelDisplayName, newChannelDisplayName)
|
||||
|
||||
post := &model.Post{
|
||||
@@ -1234,11 +1229,7 @@ func (a *App) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*m
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) {
|
||||
result := <-a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.ChannelMember), nil
|
||||
return a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersPage(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
|
||||
@@ -1330,8 +1321,18 @@ func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread,
|
||||
}
|
||||
|
||||
func (a *App) JoinChannel(channel *model.Channel, userId string) *model.AppError {
|
||||
userChan := a.Srv.Store.User().Get(userId)
|
||||
memberChan := a.Srv.Store.Channel().GetMember(channel.Id, userId)
|
||||
userChan := make(chan store.StoreResult, 1)
|
||||
memberChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
userChan <- store.StoreResult{Data: user, Err: err}
|
||||
close(userChan)
|
||||
}()
|
||||
go func() {
|
||||
member, err := a.Srv.Store.Channel().GetMember(channel.Id, userId)
|
||||
memberChan <- store.StoreResult{Data: member, Err: err}
|
||||
close(memberChan)
|
||||
}()
|
||||
|
||||
uresult := <-userChan
|
||||
if uresult.Err != nil {
|
||||
@@ -1419,7 +1420,12 @@ func (a *App) postJoinTeamMessage(user *model.User, channel *model.Channel) *mod
|
||||
|
||||
func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
||||
sc := a.Srv.Store.Channel().Get(channelId, true)
|
||||
uc := a.Srv.Store.User().Get(userId)
|
||||
uc := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
uc <- store.StoreResult{Data: user, Err: err}
|
||||
close(uc)
|
||||
}()
|
||||
ccm := a.Srv.Store.Channel().GetMemberCount(channelId, false)
|
||||
|
||||
cresult := <-sc
|
||||
@@ -1759,12 +1765,11 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
|
||||
}
|
||||
channel := chanResult.Data.(*model.Channel)
|
||||
|
||||
result := <-a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
if result.Err != nil {
|
||||
mlog.Warn(fmt.Sprintf("Failed to get membership %v", result.Err))
|
||||
member, err := a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
if err != nil {
|
||||
mlog.Warn(fmt.Sprintf("Failed to get membership %v", err))
|
||||
continue
|
||||
}
|
||||
member := result.Data.(*model.ChannelMember)
|
||||
|
||||
notify := member.NotifyProps[model.PUSH_NOTIFY_PROP]
|
||||
if notify == model.CHANNEL_NOTIFY_DEFAULT {
|
||||
@@ -1951,14 +1956,11 @@ func (a *App) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError
|
||||
}
|
||||
|
||||
func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelMember {
|
||||
result := <-a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
|
||||
if result.Err != nil {
|
||||
member, err := a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
member := result.Data.(*model.ChannelMember)
|
||||
|
||||
if member.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
|
||||
member.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_ALL
|
||||
} else {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||
)
|
||||
@@ -219,7 +220,12 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
||||
|
||||
chanChan := a.Srv.Store.Channel().Get(args.ChannelId, true)
|
||||
teamChan := a.Srv.Store.Team().Get(args.TeamId)
|
||||
userChan := a.Srv.Store.User().Get(args.UserId)
|
||||
userChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(args.UserId)
|
||||
userChan <- store.StoreResult{Data: user, Err: err}
|
||||
close(userChan)
|
||||
}()
|
||||
|
||||
result := <-a.Srv.Store.Command().GetByTeam(args.TeamId)
|
||||
if result.Err != nil {
|
||||
|
||||
@@ -199,26 +199,24 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
|
||||
}
|
||||
|
||||
func (s *Server) sendBatchedEmailNotification(userId string, notifications []*batchedNotification) {
|
||||
result := <-s.Store.User().Get(userId)
|
||||
if result.Err != nil {
|
||||
user, err := s.Store.User().Get(userId)
|
||||
if err != nil {
|
||||
mlog.Warn("Unable to find recipient for batched email notification")
|
||||
return
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
translateFunc := utils.GetUserTranslations(user.Locale)
|
||||
displayNameFormat := *s.Config().TeamSettings.TeammateNameDisplay
|
||||
|
||||
var contents string
|
||||
for _, notification := range notifications {
|
||||
result := <-s.Store.User().Get(notification.post.UserId)
|
||||
if result.Err != nil {
|
||||
sender, err := s.Store.User().Get(notification.post.UserId)
|
||||
if err != nil {
|
||||
mlog.Warn("Unable to find sender of post for batched email notification")
|
||||
continue
|
||||
}
|
||||
sender := result.Data.(*model.User)
|
||||
|
||||
result = <-s.Store.Channel().Get(notification.post.ChannelId, true)
|
||||
result := <-s.Store.Channel().Get(notification.post.ChannelId, true)
|
||||
if result.Err != nil {
|
||||
mlog.Warn("Unable to find channel of post for batched email notification")
|
||||
continue
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHandleNewNotifications(t *testing.T) {
|
||||
@@ -109,7 +110,8 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
channelMember := store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember, err := th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = 9999999
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
@@ -128,7 +130,8 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
// test that notifications are cleared if the user has acted
|
||||
channelMember = store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember, err = th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = 10001000
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
@@ -208,7 +211,8 @@ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
|
||||
job := NewEmailBatchingJob(th.Server, 128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember := store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember, err := th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
@@ -246,7 +250,8 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
|
||||
job := NewEmailBatchingJob(th.Server, 128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember := store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember, err := th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
|
||||
@@ -415,11 +415,10 @@ func (a *App) BuildPostReactions(postId string) (*[]ReactionImportData, *model.A
|
||||
reactions := result.Data.([]*model.Reaction)
|
||||
|
||||
for _, reaction := range reactions {
|
||||
result := <-a.Srv.Store.User().Get(reaction.UserId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
user, err := a.Srv.Store.User().Get(reaction.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
reactionsOfPost = append(reactionsOfPost, *ImportReactionFromPost(user, reaction))
|
||||
}
|
||||
|
||||
|
||||
11
app/oauth.go
11
app/oauth.go
@@ -259,11 +259,11 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, c
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.redirect_uri.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
result = <-a.Srv.Store.User().Get(authData.UserId)
|
||||
if result.Err != nil {
|
||||
var err *model.AppError
|
||||
user, err = a.Srv.Store.User().Get(authData.UserId)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.internal_user.app_error", nil, "", http.StatusNotFound)
|
||||
}
|
||||
user = result.Data.(*model.User)
|
||||
|
||||
result = <-a.Srv.Store.OAuth().GetPreviousAccessData(user.Id, clientId)
|
||||
if result.Err != nil {
|
||||
@@ -318,11 +318,10 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, c
|
||||
}
|
||||
accessData = result.Data.(*model.AccessData)
|
||||
|
||||
result = <-a.Srv.Store.User().Get(accessData.UserId)
|
||||
if result.Err != nil {
|
||||
user, err := a.Srv.Store.User().Get(accessData.UserId)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.internal_user.app_error", nil, "", http.StatusNotFound)
|
||||
}
|
||||
user = result.Data.(*model.User)
|
||||
|
||||
access, err := a.newSessionUpdateToken(oauthApp.Name, accessData, user)
|
||||
if err != nil {
|
||||
|
||||
18
app/post.go
18
app/post.go
@@ -50,11 +50,10 @@ func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string) (*mode
|
||||
}
|
||||
|
||||
if err.Id == "api.post.create_post.town_square_read_only" {
|
||||
result := <-a.Srv.Store.User().Get(post.UserId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
user, userErr := a.Srv.Store.User().Get(post.UserId)
|
||||
if userErr != nil {
|
||||
return nil, userErr
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
T := utils.GetUserTranslations(user.Locale)
|
||||
a.SendEphemeralPost(
|
||||
@@ -164,11 +163,10 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
||||
pchan = a.Srv.Store.Post().Get(post.RootId)
|
||||
}
|
||||
|
||||
result := <-a.Srv.Store.User().Get(post.UserId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
user, err := a.Srv.Store.User().Get(post.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
if a.License() != nil && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly &&
|
||||
!post.IsSystemMessage() &&
|
||||
@@ -180,7 +178,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
||||
// Verify the parent/child relationships are correct
|
||||
var parentPostList *model.PostList
|
||||
if pchan != nil {
|
||||
result = <-pchan
|
||||
result := <-pchan
|
||||
if result.Err != nil {
|
||||
return nil, model.NewAppError("createPost", "api.post.create_post.root_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
@@ -245,7 +243,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
||||
}
|
||||
}
|
||||
|
||||
result = <-a.Srv.Store.Post().Save(post)
|
||||
result := <-a.Srv.Store.Post().Save(post)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
)
|
||||
|
||||
func (a *App) CreateSession(session *model.Session) (*model.Session, *model.AppError) {
|
||||
@@ -247,7 +248,12 @@ func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAc
|
||||
|
||||
token.Token = model.NewId()
|
||||
|
||||
uchan := a.Srv.Store.User().Get(token.UserId)
|
||||
uchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(token.UserId)
|
||||
uchan <- store.StoreResult{Data: user, Err: err}
|
||||
close(uchan)
|
||||
}()
|
||||
|
||||
result := <-a.Srv.Store.UserAccessToken().Save(token)
|
||||
if result.Err != nil {
|
||||
@@ -284,12 +290,10 @@ func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Sessio
|
||||
return nil, model.NewAppError("createSessionForUserAccessToken", "app.user_access_token.invalid_or_missing", nil, "inactive_token", http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
var user *model.User
|
||||
result = <-a.Srv.Store.User().Get(token.UserId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
user, err := a.Srv.Store.User().Get(token.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user = result.Data.(*model.User)
|
||||
|
||||
if user.DeleteAt != 0 {
|
||||
return nil, model.NewAppError("createSessionForUserAccessToken", "app.user_access_token.invalid_or_missing", nil, "inactive_user_id="+user.Id, http.StatusUnauthorized)
|
||||
|
||||
36
app/team.go
36
app/team.go
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/plugin"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
@@ -327,7 +328,12 @@ func (a *App) sendUpdatedMemberRoleEvent(userId string, member *model.TeamMember
|
||||
|
||||
func (a *App) AddUserToTeam(teamId string, userId string, userRequestorId string) (*model.Team, *model.AppError) {
|
||||
tchan := a.Srv.Store.Team().Get(teamId)
|
||||
uchan := a.Srv.Store.User().Get(userId)
|
||||
uchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
uchan <- store.StoreResult{Data: user, Err: err}
|
||||
close(uchan)
|
||||
}()
|
||||
|
||||
result := <-tchan
|
||||
if result.Err != nil {
|
||||
@@ -375,7 +381,12 @@ func (a *App) AddUserToTeamByToken(userId string, tokenId string) (*model.Team,
|
||||
tokenData := model.MapFromJson(strings.NewReader(token.Extra))
|
||||
|
||||
tchan := a.Srv.Store.Team().Get(tokenData["teamId"])
|
||||
uchan := a.Srv.Store.User().Get(userId)
|
||||
uchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
uchan <- store.StoreResult{Data: user, Err: err}
|
||||
close(uchan)
|
||||
}()
|
||||
|
||||
result = <-tchan
|
||||
if result.Err != nil {
|
||||
@@ -402,7 +413,12 @@ func (a *App) AddUserToTeamByToken(userId string, tokenId string) (*model.Team,
|
||||
|
||||
func (a *App) AddUserToTeamByInviteId(inviteId string, userId string) (*model.Team, *model.AppError) {
|
||||
tchan := a.Srv.Store.Team().GetByInviteId(inviteId)
|
||||
uchan := a.Srv.Store.User().Get(userId)
|
||||
uchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
uchan <- store.StoreResult{Data: user, Err: err}
|
||||
close(uchan)
|
||||
}()
|
||||
|
||||
result := <-tchan
|
||||
if result.Err != nil {
|
||||
@@ -761,7 +777,12 @@ func (a *App) GetTeamUnread(teamId, userId string) (*model.TeamUnread, *model.Ap
|
||||
|
||||
func (a *App) RemoveUserFromTeam(teamId string, userId string, requestorId string) *model.AppError {
|
||||
tchan := a.Srv.Store.Team().Get(teamId)
|
||||
uchan := a.Srv.Store.User().Get(userId)
|
||||
uchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
uchan <- store.StoreResult{Data: user, Err: err}
|
||||
close(uchan)
|
||||
}()
|
||||
|
||||
result := <-tchan
|
||||
if result.Err != nil {
|
||||
@@ -926,7 +947,12 @@ func (a *App) InviteNewUsersToTeam(emailList []string, teamId, senderId string)
|
||||
}
|
||||
|
||||
tchan := a.Srv.Store.Team().Get(teamId)
|
||||
uchan := a.Srv.Store.User().Get(senderId)
|
||||
uchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(senderId)
|
||||
uchan <- store.StoreResult{Data: user, Err: err}
|
||||
close(uchan)
|
||||
}()
|
||||
|
||||
result := <-tchan
|
||||
if result.Err != nil {
|
||||
|
||||
26
app/user.go
26
app/user.go
@@ -398,11 +398,7 @@ func (a *App) IsUsernameTaken(name string) bool {
|
||||
}
|
||||
|
||||
func (a *App) GetUser(userId string) (*model.User, *model.AppError) {
|
||||
result := <-a.Srv.Store.User().Get(userId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.User), nil
|
||||
return a.Srv.Store.User().Get(userId)
|
||||
}
|
||||
|
||||
func (a *App) GetUserByUsername(username string) (*model.User, *model.AppError) {
|
||||
@@ -655,11 +651,10 @@ func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppErro
|
||||
}
|
||||
|
||||
func (a *App) ActivateMfa(userId, token string) *model.AppError {
|
||||
result := <-a.Srv.Store.User().Get(userId)
|
||||
if result.Err != nil {
|
||||
return result.Err
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
if len(user.AuthService) > 0 && user.AuthService != model.USER_AUTH_SERVICE_LDAP {
|
||||
return model.NewAppError("ActivateMfa", "api.user.activate_mfa.email_and_ldap_only.app_error", nil, "", http.StatusBadRequest)
|
||||
@@ -1086,11 +1081,10 @@ func (a *App) sendUpdatedUserEvent(user model.User) {
|
||||
}
|
||||
|
||||
func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) {
|
||||
result := <-a.Srv.Store.User().Get(user.Id)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
prev, err := a.Srv.Store.User().Get(user.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prev := result.Data.(*model.User)
|
||||
|
||||
if !CheckUserDomain(user, *a.Config().TeamSettings.RestrictCreationToDomains) {
|
||||
if !prev.IsLDAPUser() && !prev.IsSAMLUser() && user.Email != prev.Email {
|
||||
@@ -1112,7 +1106,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
|
||||
user.Email = prev.Email
|
||||
}
|
||||
|
||||
result = <-a.Srv.Store.User().Update(user, false)
|
||||
result := <-a.Srv.Store.User().Update(user, false)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
@@ -1482,8 +1476,8 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Audit().PermanentDeleteByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
if err := a.Srv.Store.Audit().PermanentDeleteByUser(user.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Team().RemoveAllMembersByUser(user.Id); result.Err != nil {
|
||||
|
||||
@@ -610,7 +610,12 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
|
||||
hook = result.Data.(*model.IncomingWebhook)
|
||||
}
|
||||
|
||||
uchan := a.Srv.Store.User().Get(hook.UserId)
|
||||
uchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(hook.UserId)
|
||||
uchan <- store.StoreResult{Data: user, Err: err}
|
||||
close(uchan)
|
||||
}()
|
||||
|
||||
if len(req.Props) == 0 {
|
||||
req.Props = make(model.StringInterface)
|
||||
|
||||
Ссылка в новой задаче
Block a user