Migration of ChannelStore Part 1 (#15235)
* Lint: remove unnecessary use of sprintf * Fix i18n * Returning the right error (InternalServerError) * Doing some suggestions * Fix store layers * Fix missed translation Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f2a8e10216
Коммит
2cb655ed67
@@ -1632,15 +1632,36 @@ func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, lim
|
||||
}
|
||||
|
||||
func (a *App) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetPublicChannelsByIdsForTeam(teamId, channelIds)
|
||||
list, err := a.Srv().Store.Channel().GetPublicChannelsByIdsForTeam(teamId, channelIds)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("GetPublicChannelsByIdsForTeam", "app.channel.get_channels_by_ids.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return nil, model.NewAppError("GetPublicChannelsByIdsForTeam", "app.channel.get_channels_by_ids.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetPublicChannelsForTeam(teamId, offset, limit)
|
||||
list, err := a.Srv().Store.Channel().GetPublicChannelsForTeam(teamId, offset, limit)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetPublicChannelsForTeam", "app.channel.get_public_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (a *App) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetPrivateChannelsForTeam(teamId, offset, limit)
|
||||
list, err := a.Srv().Store.Channel().GetPrivateChannelsForTeam(teamId, offset, limit)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetPrivateChannelsForTeam", "app.channel.get_private_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) {
|
||||
@@ -1705,7 +1726,12 @@ func (a *App) GetChannelPinnedPostCount(channelId string) (int64, *model.AppErro
|
||||
}
|
||||
|
||||
func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetChannelCounts(teamId, userId)
|
||||
counts, err := a.Srv().Store.Channel().GetChannelCounts(teamId, userId)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetChannelCounts", "app.channel.get_channel_counts.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return counts, nil
|
||||
}
|
||||
|
||||
func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
||||
@@ -2094,7 +2120,13 @@ func (a *App) GetNumberOfChannelsOnTeam(teamId string) (int, *model.AppError) {
|
||||
// Get total number of channels on current team
|
||||
list, err := a.Srv().Store.Channel().GetTeamChannels(teamId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return 0, model.NewAppError("GetNumberOfChannelsOnTeam", "app.channel.get_channels.not_found.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
default:
|
||||
return 0, model.NewAppError("GetNumberOfChannelsOnTeam", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
return len(*list), nil
|
||||
}
|
||||
@@ -2415,8 +2447,8 @@ func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model.
|
||||
}
|
||||
}
|
||||
|
||||
if appErr := a.Srv().Store.Channel().UpdateSidebarChannelCategoryOnMove(channel, team.Id); appErr != nil {
|
||||
return appErr
|
||||
if nErr := a.Srv().Store.Channel().UpdateSidebarChannelCategoryOnMove(channel, team.Id); nErr != nil {
|
||||
return model.NewAppError("MoveChannel", "app.channel.sidebar_categories.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
channel.TeamId = team.Id
|
||||
|
||||
@@ -78,7 +78,7 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
||||
cchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
channel, err := a.Srv().Store.Channel().GetForPost(postId)
|
||||
cchan <- store.StoreResult{Data: channel, Err: err}
|
||||
cchan <- store.StoreResult{Data: channel, NErr: err}
|
||||
close(cchan)
|
||||
}()
|
||||
|
||||
@@ -133,8 +133,8 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
||||
} else {
|
||||
post := result.Data.(*model.Post)
|
||||
result = <-cchan
|
||||
if result.Err != nil {
|
||||
return "", result.Err
|
||||
if result.NErr != nil {
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get_for_post.app_error", nil, result.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
channel := result.Data.(*model.Channel)
|
||||
|
||||
|
||||
21
app/team.go
21
app/team.go
@@ -582,7 +582,7 @@ func (a *App) AddUserToTeamByToken(userId string, tokenId string) (*model.Team,
|
||||
if token.Type == TOKEN_TYPE_GUEST_INVITATION {
|
||||
channels, err := a.Srv().Store.Channel().GetChannelsByIds(strings.Split(tokenData["channels"], " "), false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, model.NewAppError("AddUserToTeamByToken", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, channel := range channels {
|
||||
@@ -1158,7 +1158,7 @@ func (a *App) RemoveTeamMemberFromTeam(teamMember *model.TeamMember, requestorId
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Channel().ClearSidebarOnTeamLeave(user.Id, teamMember.TeamId); err != nil {
|
||||
return err
|
||||
return model.NewAppError("RemoveTeamMemberFromTeam", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// delete the preferences that set the last channel used in the team and other team specific preferences
|
||||
@@ -1396,7 +1396,7 @@ func (a *App) prepareInviteGuestsToChannels(teamId string, guestsInvite *model.G
|
||||
cchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
channels, err := a.Srv().Store.Channel().GetChannelsByIds(guestsInvite.Channels, false)
|
||||
cchan <- store.StoreResult{Data: channels, Err: err}
|
||||
cchan <- store.StoreResult{Data: channels, NErr: err}
|
||||
close(cchan)
|
||||
}()
|
||||
uchan := make(chan store.StoreResult, 1)
|
||||
@@ -1407,8 +1407,8 @@ func (a *App) prepareInviteGuestsToChannels(teamId string, guestsInvite *model.G
|
||||
}()
|
||||
|
||||
result := <-cchan
|
||||
if result.Err != nil {
|
||||
return nil, nil, nil, result.Err
|
||||
if result.NErr != nil {
|
||||
return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "app.channel.get_channels_by_ids.app_error", nil, result.NErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
channels := result.Data.([]*model.Channel)
|
||||
|
||||
@@ -1432,7 +1432,7 @@ func (a *App) prepareInviteGuestsToChannels(teamId string, guestsInvite *model.G
|
||||
|
||||
for _, channel := range channels {
|
||||
if channel.TeamId != teamId {
|
||||
return nil, nil, nil, model.NewAppError("InviteGuestsToChannels", "api.team.invite_guests.channel_in_invalid_team.app_error", nil, "", http.StatusBadRequest)
|
||||
return nil, nil, nil, model.NewAppError("prepareInviteGuestsToChannels", "api.team.invite_guests.channel_in_invalid_team.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
return user, team, channels, nil
|
||||
@@ -1440,7 +1440,7 @@ func (a *App) prepareInviteGuestsToChannels(teamId string, guestsInvite *model.G
|
||||
|
||||
func (a *App) InviteGuestsToChannelsGracefully(teamId string, guestsInvite *model.GuestsInvite, senderId string) ([]*model.EmailInviteWithError, *model.AppError) {
|
||||
if !*a.Config().ServiceSettings.EnableEmailInvitations {
|
||||
return nil, model.NewAppError("InviteNewUsersToTeam", "api.team.invite_members.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
return nil, model.NewAppError("InviteGuestsToChannelsGracefully", "api.team.invite_members.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
user, team, channels, err := a.prepareInviteGuestsToChannels(teamId, guestsInvite, senderId)
|
||||
@@ -1456,7 +1456,7 @@ func (a *App) InviteGuestsToChannelsGracefully(teamId string, guestsInvite *mode
|
||||
Error: nil,
|
||||
}
|
||||
if !CheckEmailDomain(email, *a.Config().GuestAccountsSettings.RestrictCreationToDomains) {
|
||||
invite.Error = model.NewAppError("InviteNewUsersToTeam", "api.team.invite_members.invalid_email.app_error", map[string]interface{}{"Addresses": email}, "", http.StatusBadRequest)
|
||||
invite.Error = model.NewAppError("InviteGuestsToChannelsGracefully", "api.team.invite_members.invalid_email.app_error", map[string]interface{}{"Addresses": email}, "", http.StatusBadRequest)
|
||||
} else {
|
||||
goodEmails = append(goodEmails, email)
|
||||
}
|
||||
@@ -1621,8 +1621,9 @@ func (a *App) PermanentDeleteTeam(team *model.Team) *model.AppError {
|
||||
}
|
||||
|
||||
if channels, err := a.Srv().Store.Channel().GetTeamChannels(team.Id); err != nil {
|
||||
if err.Id != "app.channel.get_channels.not_found.app_error" {
|
||||
return err
|
||||
var nfErr *store.ErrNotFound
|
||||
if !errors.As(err, &nfErr) {
|
||||
return model.NewAppError("PermanentDeleteTeam", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
for _, c := range *channels {
|
||||
|
||||
@@ -75,9 +75,9 @@ func (a *App) CreateUserWithToken(user *model.User, token *model.Token) (*model.
|
||||
}
|
||||
}
|
||||
|
||||
channels, err := a.Srv().Store.Channel().GetChannelsByIds(strings.Split(tokenData["channels"], " "), false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
channels, nErr := a.Srv().Store.Channel().GetChannelsByIds(strings.Split(tokenData["channels"], " "), false)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("CreateUserWithToken", "app.channel.get_channels_by_ids.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
user.Email = tokenData["email"]
|
||||
|
||||
Ссылка в новой задаче
Block a user