ChannelStore migration Part 2 (#15405)
* Migration completed * Several corrections in tests * Fix imports * Fix some errors after testing * Trigger CI * Fix tests * Suggestions * Suggestions * Add license Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7abc4f5383
Коммит
9ee9c78412
@@ -47,12 +47,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
privateChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
openChan <- store.StoreResult{Data: count, Err: err2}
|
||||
openChan <- store.StoreResult{Data: count, NErr: err2}
|
||||
close(openChan)
|
||||
}()
|
||||
go func() {
|
||||
count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
privateChan <- store.StoreResult{Data: count, Err: err2}
|
||||
privateChan <- store.StoreResult{Data: count, NErr: err2}
|
||||
close(privateChan)
|
||||
}()
|
||||
|
||||
@@ -106,14 +106,14 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
}()
|
||||
|
||||
r := <-openChan
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
if r.NErr != nil {
|
||||
return nil, model.NewAppError("GetAnalytics", "app.channel.analytics_type_count.app_error", nil, r.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
rows[0].Value = float64(r.Data.(int64))
|
||||
|
||||
r = <-privateChan
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
if r.NErr != nil {
|
||||
return nil, model.NewAppError("GetAnalytics", "app.channel.analytics_type_count.app_error", nil, r.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
rows[1].Value = float64(r.Data.(int64))
|
||||
|
||||
|
||||
@@ -71,8 +71,8 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
|
||||
}
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(channelId)
|
||||
if err != nil && err.StatusCode == http.StatusNotFound {
|
||||
channel, appErr := a.GetChannel(channelId)
|
||||
if appErr != nil && appErr.StatusCode == http.StatusNotFound {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
224
app/channel.go
224
app/channel.go
@@ -74,6 +74,7 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
||||
}
|
||||
|
||||
var err *model.AppError
|
||||
var nErr error
|
||||
for _, channelName := range a.DefaultChannelNames() {
|
||||
channel, channelErr := a.Srv().Store.Channel().GetByName(teamId, channelName, true)
|
||||
if channelErr != nil {
|
||||
@@ -100,7 +101,7 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
||||
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
||||
}
|
||||
|
||||
_, err = a.Srv().Store.Channel().SaveMember(cm)
|
||||
_, nErr = a.Srv().Store.Channel().SaveMember(cm)
|
||||
if histErr := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); histErr != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(histErr))
|
||||
return model.NewAppError("JoinDefaultChannels", "app.channel_member_history.log_join_event.internal_error", nil, histErr.Error(), http.StatusInternalServerError)
|
||||
@@ -119,7 +120,22 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
||||
|
||||
}
|
||||
|
||||
return err
|
||||
if nErr != nil {
|
||||
var appErr *model.AppError
|
||||
var cErr *store.ErrConflict
|
||||
switch {
|
||||
case errors.As(nErr, &cErr):
|
||||
if cErr.Resource == "ChannelMembers" {
|
||||
return model.NewAppError("JoinDefaultChannels", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
case errors.As(nErr, &appErr):
|
||||
return appErr
|
||||
default:
|
||||
return model.NewAppError("JoinDefaultChannels", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) postJoinMessageForDefaultChannel(user *model.User, requestor *model.User, channel *model.Channel) {
|
||||
@@ -254,9 +270,22 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
|
||||
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
||||
}
|
||||
|
||||
if _, err := a.Srv().Store.Channel().SaveMember(cm); err != nil {
|
||||
return nil, err
|
||||
if _, nErr := a.Srv().Store.Channel().SaveMember(cm); nErr != nil {
|
||||
var appErr *model.AppError
|
||||
var cErr *store.ErrConflict
|
||||
switch {
|
||||
case errors.As(nErr, &cErr):
|
||||
switch cErr.Resource {
|
||||
case "ChannelMembers":
|
||||
return nil, model.NewAppError("CreateChannel", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
case errors.As(nErr, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("CreateChannel", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(channel.CreatorId, sc.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, model.NewAppError("CreateChannel", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -365,7 +394,7 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
||||
case "Channel":
|
||||
return channel, model.NewAppError("CreateChannel", store.CHANNEL_EXISTS_ERROR, nil, cErr.Error(), http.StatusBadRequest)
|
||||
case "ChannelMembers":
|
||||
return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("CreateChannel", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
case errors.As(nErr, <Err):
|
||||
return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.limit.app_error", nil, ltErr.Error(), http.StatusBadRequest)
|
||||
@@ -409,7 +438,8 @@ func (a *App) WaitForChannelMembership(channelId string, userId string) {
|
||||
}
|
||||
|
||||
// If we received an error, but it wasn't a missing channel member then return
|
||||
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
var nfErr *store.ErrNotFound
|
||||
if !errors.As(err, &nfErr) {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -497,8 +527,20 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
|
||||
SchemeUser: !user.IsGuest(),
|
||||
}
|
||||
|
||||
if _, err := a.Srv().Store.Channel().SaveMember(cm); err != nil {
|
||||
return nil, err
|
||||
if _, nErr = a.Srv().Store.Channel().SaveMember(cm); nErr != nil {
|
||||
var appErr *model.AppError
|
||||
var cErr *store.ErrConflict
|
||||
switch {
|
||||
case errors.As(nErr, &cErr):
|
||||
switch cErr.Resource {
|
||||
case "ChannelMembers":
|
||||
return nil, model.NewAppError("createGroupChannel", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
case errors.As(nErr, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("createGroupChannel", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
@@ -1038,9 +1080,18 @@ func (a *App) UpdateChannelMemberRoles(channelId string, userId string, newRoles
|
||||
|
||||
member.ExplicitRoles = strings.Join(newExplicitRoles, " ")
|
||||
|
||||
member, err = a.Srv().Store.Channel().UpdateMember(member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
member, nErr := a.Srv().Store.Channel().UpdateMember(member)
|
||||
if nErr != nil {
|
||||
var appErr *model.AppError
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(nErr, &nfErr):
|
||||
return nil, model.NewAppError("UpdateChannelMemberRoles", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("UpdateChannelMemberRoles", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
a.InvalidateCacheForUser(userId)
|
||||
@@ -1066,9 +1117,18 @@ func (a *App) UpdateChannelMemberSchemeRoles(channelId string, userId string, is
|
||||
member.ExplicitRoles = RemoveRoles([]string{model.CHANNEL_GUEST_ROLE_ID, model.CHANNEL_USER_ROLE_ID, model.CHANNEL_ADMIN_ROLE_ID}, member.ExplicitRoles)
|
||||
}
|
||||
|
||||
member, err = a.Srv().Store.Channel().UpdateMember(member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
member, nErr := a.Srv().Store.Channel().UpdateMember(member)
|
||||
if nErr != nil {
|
||||
var appErr *model.AppError
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(nErr, &nfErr):
|
||||
return nil, model.NewAppError("UpdateChannelMemberSchemeRoles", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("UpdateChannelMemberSchemeRoles", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// Notify the clients that the member notify props changed
|
||||
@@ -1108,9 +1168,18 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelId s
|
||||
member.NotifyProps[model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP] = ignoreChannelMentions
|
||||
}
|
||||
|
||||
member, err = a.Srv().Store.Channel().UpdateMember(member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
member, nErr := a.Srv().Store.Channel().UpdateMember(member)
|
||||
if nErr != nil {
|
||||
var appErr *model.AppError
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(nErr, &nfErr):
|
||||
return nil, model.NewAppError("UpdateChannelMemberNotifyProps", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("UpdateChannelMemberNotifyProps", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
a.InvalidateCacheForUser(userId)
|
||||
@@ -1222,10 +1291,11 @@ 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)
|
||||
}
|
||||
|
||||
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
|
||||
channelMember, nErr := a.Srv().Store.Channel().GetMember(channel.Id, user.Id)
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
if !errors.As(nErr, &nfErr) {
|
||||
return nil, model.NewAppError("AddUserToChannel", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
return channelMember, nil
|
||||
@@ -1251,16 +1321,16 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
|
||||
|
||||
if !user.IsGuest() {
|
||||
var userShouldBeAdmin bool
|
||||
userShouldBeAdmin, err = a.UserIsInAdminRoleGroup(user.Id, channel.Id, model.GroupSyncableTypeChannel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
userShouldBeAdmin, appErr := a.UserIsInAdminRoleGroup(user.Id, channel.Id, model.GroupSyncableTypeChannel)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
newMember.SchemeAdmin = userShouldBeAdmin
|
||||
}
|
||||
|
||||
newMember, err = a.Srv().Store.Channel().SaveMember(newMember)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to add member", mlog.String("user_id", user.Id), mlog.String("channel_id", channel.Id), mlog.Err(err))
|
||||
newMember, nErr = a.Srv().Store.Channel().SaveMember(newMember)
|
||||
if nErr != nil {
|
||||
mlog.Error("Failed to add member", mlog.String("user_id", user.Id), mlog.String("channel_id", channel.Id), mlog.Err(nErr))
|
||||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
a.WaitForChannelMembership(channel.Id, user.Id)
|
||||
@@ -1301,8 +1371,9 @@ func (a *App) AddUserToChannel(user *model.User, channel *model.Channel) (*model
|
||||
|
||||
func (a *App) AddChannelMember(userId string, channel *model.Channel, userRequestorId string, postRootId string) (*model.ChannelMember, *model.AppError) {
|
||||
if member, err := a.Srv().Store.Channel().GetMember(channel.Id, userId); err != nil {
|
||||
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
return nil, err
|
||||
var nfErr *store.ErrNotFound
|
||||
if !errors.As(err, &nfErr) {
|
||||
return nil, model.NewAppError("AddChannelMember", "app.channel.get_member.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
return member, nil
|
||||
@@ -1665,17 +1736,33 @@ func (a *App) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
channelMember, err := a.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetChannelMember", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetChannelMember", "app.channel.get_member.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return channelMember, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersPage(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetMembers(channelId, page*perPage, perPage)
|
||||
channelMembers, err := a.Srv().Store.Channel().GetMembers(channelId, page*perPage, perPage)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetChannelMembersPage", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelMembers, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersTimezones(channelId string) ([]string, *model.AppError) {
|
||||
membersTimezones, err := a.Srv().Store.Channel().GetChannelMembersTimezones(channelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, model.NewAppError("GetChannelMembersTimezones", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
var timezones []string
|
||||
@@ -1694,13 +1781,18 @@ func (a *App) GetChannelMembersByIds(channelId string, userIds []string) (*model
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetMembersForUser(teamId, userId)
|
||||
channelMembers, err := a.Srv().Store.Channel().GetMembersForUser(teamId, userId)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetChannelMembersForUser", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return channelMembers, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersForUserWithPagination(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError) {
|
||||
m, err := a.Srv().Store.Channel().GetMembersForUserWithPagination(teamId, userId, page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, model.NewAppError("GetChannelMembersForUserWithPagination", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
members := make([]*model.ChannelMember, 0)
|
||||
@@ -1714,15 +1806,30 @@ func (a *App) GetChannelMembersForUserWithPagination(teamId, userId string, page
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMemberCount(channelId string) (int64, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetMemberCount(channelId, true)
|
||||
count, err := a.Srv().Store.Channel().GetMemberCount(channelId, true)
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("GetChannelMemberCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelGuestCount(channelId string) (int64, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetGuestCount(channelId, true)
|
||||
count, err := a.Srv().Store.Channel().GetGuestCount(channelId, true)
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlChannelStore.GetGuestCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelPinnedPostCount(channelId string) (int64, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetPinnedPostCount(channelId, true)
|
||||
count, err := a.Srv().Store.Channel().GetPinnedPostCount(channelId, true)
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("GetChannelPinnedPostCount", "app.channel.get_pinnedpost_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
|
||||
@@ -1757,7 +1864,7 @@ func (a *App) JoinChannel(channel *model.Channel, userId string) *model.AppError
|
||||
}()
|
||||
go func() {
|
||||
member, err := a.Srv().Store.Channel().GetMember(channel.Id, userId)
|
||||
memberChan <- store.StoreResult{Data: member, Err: err}
|
||||
memberChan <- store.StoreResult{Data: member, NErr: err}
|
||||
close(memberChan)
|
||||
}()
|
||||
|
||||
@@ -1767,7 +1874,7 @@ func (a *App) JoinChannel(channel *model.Channel, userId string) *model.AppError
|
||||
}
|
||||
|
||||
mresult := <-memberChan
|
||||
if mresult.Err == nil && mresult.Data != nil {
|
||||
if mresult.NErr == nil && mresult.Data != nil {
|
||||
// user is already in the channel
|
||||
return nil
|
||||
}
|
||||
@@ -1862,7 +1969,7 @@ func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
||||
mcc := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv().Store.Channel().GetMemberCount(channelId, false)
|
||||
mcc <- store.StoreResult{Data: count, Err: err}
|
||||
mcc <- store.StoreResult{Data: count, NErr: err}
|
||||
close(mcc)
|
||||
}()
|
||||
|
||||
@@ -1881,8 +1988,8 @@ func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
||||
}
|
||||
}
|
||||
ccresult := <-mcc
|
||||
if ccresult.Err != nil {
|
||||
return ccresult.Err
|
||||
if ccresult.NErr != nil {
|
||||
return model.NewAppError("LeaveChannel", "app.channel.get_member_count.app_error", nil, ccresult.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
channel := cresult.Data.(*model.Channel)
|
||||
@@ -2038,7 +2145,7 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Channel().RemoveMember(channel.Id, userIdToRemove); err != nil {
|
||||
return err
|
||||
return model.NewAppError("removeUserFromChannel", "app.channel.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogLeaveEvent(userIdToRemove, channel.Id, model.GetMillis()); err != nil {
|
||||
return model.NewAppError("removeUserFromChannel", "app.channel_member_history.log_leave_event.internal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -2158,7 +2265,13 @@ func (a *App) SetActiveChannel(userId string, channelId string) *model.AppError
|
||||
|
||||
func (a *App) UpdateChannelLastViewedAt(channelIds []string, userId string) *model.AppError {
|
||||
if _, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userId); err != nil {
|
||||
return err
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return model.NewAppError("UpdateChannelLastViewedAt", "app.channel.update_last_viewed_at.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
default:
|
||||
return model.NewAppError("UpdateChannelLastViewedAt", "app.channel.update_last_viewed_at.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.EnableChannelViewedMessages {
|
||||
@@ -2189,9 +2302,9 @@ func (a *App) MarkChannelAsUnreadFromPost(postID string, userID string) (*model.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channelUnread, updateErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions)
|
||||
if updateErr != nil {
|
||||
return channelUnread, updateErr
|
||||
channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions)
|
||||
if nErr != nil {
|
||||
return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_UNREAD, channelUnread.TeamId, channelUnread.ChannelId, channelUnread.UserId, nil)
|
||||
@@ -2327,7 +2440,13 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
|
||||
}
|
||||
times, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
default:
|
||||
return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.EnableChannelViewedMessages {
|
||||
@@ -2371,7 +2490,7 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Channel().PermanentDeleteMembersByChannel(channel.Id); err != nil {
|
||||
return err
|
||||
return model.NewAppError("PermanentDeleteChannel", "app.channel.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Webhook().PermanentDeleteIncomingByChannel(channel.Id); err != nil {
|
||||
@@ -2563,7 +2682,12 @@ func (a *App) RemoveUsersFromChannelNotMemberOfTeam(remover *model.User, channel
|
||||
}
|
||||
|
||||
func (a *App) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetPinnedPosts(channelId)
|
||||
posts, err := a.Srv().Store.Channel().GetPinnedPosts(channelId)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetPinnedPosts", "app.channel.pinned_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelMember {
|
||||
|
||||
6
app/constants.go
Обычный файл
6
app/constants.go
Обычный файл
@@ -0,0 +1,6 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
const MISSING_CHANNEL_MEMBER_ERROR = "app.channel.get_member.missing.app_error"
|
||||
@@ -822,9 +822,9 @@ func (a *App) importUserChannels(user *model.User, team *model.Team, teamMember
|
||||
isGuestByChannelId := map[string]bool{}
|
||||
isUserByChannelId := map[string]bool{}
|
||||
isAdminByChannelId := map[string]bool{}
|
||||
existingMemberships, err := a.Srv().Store.Channel().GetMembersForUser(team.Id, user.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
existingMemberships, nErr := a.Srv().Store.Channel().GetMembersForUser(team.Id, user.Id)
|
||||
if nErr != nil {
|
||||
return model.NewAppError("importUserChannels", "app.channel.get_members.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
existingMembershipsByChannelId := map[string]model.ChannelMember{}
|
||||
for _, channelMembership := range *existingMemberships {
|
||||
@@ -913,16 +913,37 @@ func (a *App) importUserChannels(user *model.User, team *model.Team, teamMember
|
||||
}
|
||||
}
|
||||
|
||||
oldMembers, err := a.Srv().Store.Channel().UpdateMultipleMembers(oldChannelMembers)
|
||||
if err != nil {
|
||||
return err
|
||||
oldMembers, nErr := a.Srv().Store.Channel().UpdateMultipleMembers(oldChannelMembers)
|
||||
if nErr != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
return appErr
|
||||
case errors.As(nErr, &nfErr):
|
||||
return model.NewAppError("importUserChannels", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return model.NewAppError("importUserChannels", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
newMembers := []*model.ChannelMember{}
|
||||
if len(newChannelMembers) > 0 {
|
||||
newMembers, err = a.Srv().Store.Channel().SaveMultipleMembers(newChannelMembers)
|
||||
if err != nil {
|
||||
return err
|
||||
newMembers, nErr = a.Srv().Store.Channel().SaveMultipleMembers(newChannelMembers)
|
||||
if nErr != nil {
|
||||
var cErr *store.ErrConflict
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(nErr, &cErr):
|
||||
switch cErr.Resource {
|
||||
case "ChannelMembers":
|
||||
return model.NewAppError("importUserChannels", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
case errors.As(nErr, &appErr):
|
||||
return appErr
|
||||
default:
|
||||
return model.NewAppError("importUserChannels", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -604,8 +604,8 @@ func TestImportImportChannel(t *testing.T) {
|
||||
require.Nil(t, err, "Failed to get team from database.")
|
||||
|
||||
// Check how many channels are in the database.
|
||||
channelCount, err := th.App.Srv().Store.Channel().AnalyticsTypeCount("", model.CHANNEL_OPEN)
|
||||
require.Nil(t, err, "Failed to get team count.")
|
||||
channelCount, nErr := th.App.Srv().Store.Channel().AnalyticsTypeCount("", model.CHANNEL_OPEN)
|
||||
require.Nil(t, nErr, "Failed to get team count.")
|
||||
|
||||
// Do an invalid channel in dry-run mode.
|
||||
data := ChannelImportData{
|
||||
@@ -3043,8 +3043,8 @@ func TestImportImportDirectChannel(t *testing.T) {
|
||||
th.BasicUser2.Id,
|
||||
user3.Id,
|
||||
}
|
||||
channel, err = th.App.createGroupChannel(userIds, th.BasicUser.Id)
|
||||
require.Equal(t, err.Id, store.CHANNEL_EXISTS_ERROR)
|
||||
channel, appErr := th.App.createGroupChannel(userIds, th.BasicUser.Id)
|
||||
require.Equal(t, appErr.Id, store.CHANNEL_EXISTS_ERROR)
|
||||
require.Equal(t, channel.Header, *data.Header)
|
||||
|
||||
// Import a channel with some favorites.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
@@ -32,7 +33,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
cmnchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
props, err := a.Srv().Store.Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true)
|
||||
cmnchan <- store.StoreResult{Data: props, Err: err}
|
||||
cmnchan <- store.StoreResult{Data: props, NErr: err}
|
||||
close(cmnchan)
|
||||
}()
|
||||
|
||||
@@ -63,8 +64,8 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
profileMap := result.Data.(map[string]*model.User)
|
||||
|
||||
result = <-cmnchan
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
if result.NErr != nil {
|
||||
return nil, result.NErr
|
||||
}
|
||||
channelMemberNotifyPropsMap := result.Data.(map[string]model.StringMap)
|
||||
|
||||
@@ -164,7 +165,13 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
|
||||
umc := make(chan *model.AppError, 1)
|
||||
go func(userId string) {
|
||||
umc <- a.Srv().Store.Channel().IncrementMentionCount(post.ChannelId, userId)
|
||||
nErr := a.Srv().Store.Channel().IncrementMentionCount(post.ChannelId, userId)
|
||||
if nErr != nil {
|
||||
umc <- model.NewAppError("SendNotifications", "app.channel.increment_mention_count.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
umc <- nil
|
||||
}
|
||||
|
||||
close(umc)
|
||||
}(id)
|
||||
updateMentionChans = append(updateMentionChans, umc)
|
||||
|
||||
@@ -1292,12 +1292,12 @@ func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, *m
|
||||
|
||||
if channel.Type == model.CHANNEL_DIRECT {
|
||||
// In a DM channel, every post made by the other user is a mention
|
||||
count, countErr := a.Srv().Store.Channel().CountPostsAfter(post.ChannelId, post.CreateAt-1, channel.GetOtherUserIdForDM(user.Id))
|
||||
if countErr != nil {
|
||||
return 0, countErr
|
||||
count, nErr := a.Srv().Store.Channel().CountPostsAfter(post.ChannelId, post.CreateAt-1, channel.GetOtherUserIdForDM(user.Id))
|
||||
if nErr != nil {
|
||||
return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return count, countErr
|
||||
return count, nil
|
||||
}
|
||||
|
||||
channelMember, err := a.GetChannelMember(channel.Id, user.Id)
|
||||
|
||||
@@ -893,15 +893,15 @@ func TestCreatePostAsUser(t *testing.T) {
|
||||
UserId: bot.UserId,
|
||||
}
|
||||
|
||||
channelMemberBefore, appErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, appErr)
|
||||
channelMemberBefore, nErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
_, appErr = th.App.CreatePostAsUser(post, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
channelMemberAfter, appErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, appErr)
|
||||
channelMemberAfter, nErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
require.Equal(t, channelMemberAfter.LastViewedAt, channelMemberBefore.LastViewedAt)
|
||||
})
|
||||
|
||||
@@ -82,7 +82,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
|
||||
_, err = th.App.GetChannelMember(publicChannel.Id, th.BasicUser.Id)
|
||||
assert.NotNil(t, err)
|
||||
assert.NotNil(t, err.Id, "store.sql_channel.get_member.missing.app_error")
|
||||
assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
|
||||
})
|
||||
|
||||
t.Run("Leave a private channel", func(t *testing.T) {
|
||||
@@ -124,7 +124,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
|
||||
_, err = th.App.GetChannelMember(defaultChannel.Id, guest.Id)
|
||||
assert.NotNil(t, err)
|
||||
assert.NotNil(t, err.Id, "store.sql_channel.get_member.missing.app_error")
|
||||
assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
|
||||
})
|
||||
|
||||
t.Run("Should redirect to the team if is the last channel", func(t *testing.T) {
|
||||
@@ -142,6 +142,6 @@ func TestLeaveProviderDoCommand(t *testing.T) {
|
||||
|
||||
_, err = th.App.GetChannelMember(publicChannel.Id, guest.Id)
|
||||
assert.NotNil(t, err)
|
||||
assert.NotNil(t, err.Id, "store.sql_channel.get_member.missing.app_error")
|
||||
assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id)
|
||||
if err.Id != "store.sql_channel.get_member.missing.app_error" {
|
||||
if err.Id != "app.channel.get_member.missing.app_error" {
|
||||
t.Errorf("wrong error: %s", err.Id)
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id)
|
||||
if err.Id != "store.sql_channel.get_member.missing.app_error" {
|
||||
if err.Id != "app.channel.get_member.missing.app_error" {
|
||||
t.Errorf("wrong error: %s", err.Id)
|
||||
}
|
||||
|
||||
|
||||
@@ -1194,8 +1194,8 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User, requestorId string)
|
||||
for _, channel := range *channelList {
|
||||
if !channel.IsGroupOrDirect() {
|
||||
a.invalidateCacheForChannelMembers(channel.Id)
|
||||
if err = a.Srv().Store.Channel().RemoveMember(channel.Id, user.Id); err != nil {
|
||||
return err
|
||||
if nErr = a.Srv().Store.Channel().RemoveMember(channel.Id, user.Id); nErr != nil {
|
||||
return model.NewAppError("LeaveTeam", "app.channel.remove_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1514,7 +1514,7 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Channel().PermanentDeleteMembersByUser(user.Id); err != nil {
|
||||
return err
|
||||
return model.NewAppError("PermanentDeleteUser", "app.channel.permanent_delete_members_by_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Group().PermanentDeleteMembersByUser(user.Id); err != nil {
|
||||
@@ -2028,7 +2028,7 @@ func (a *App) GetViewUsersRestrictions(userId string) (*model.ViewUsersRestricti
|
||||
|
||||
userChannelMembers, err := a.Srv().Store.Channel().GetAllChannelMembersForUser(userId, true, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, model.NewAppError("GetViewUsersRestrictions", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
channelIds := []string{}
|
||||
|
||||
Ссылка в новой задаче
Block a user