[MM-55303] channels/app/webhook: Make use of GenericStoreResult (#25722)

Make use of Generic store result in channels/app/webhook.go.
Introduce new variable resultU (result user) to workaround incompatible
assign error (since generics have been introduced).
Этот коммит содержится в:
Paul Stern
2023-12-18 09:08:38 +03:00
коммит произвёл GitHub
родитель cd8796bf0b
Коммит 000ee45b5d

Просмотреть файл

@@ -664,10 +664,10 @@ func (a *App) HandleIncomingWebhook(c request.CTX, hookID string, req *model.Inc
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
hchan := make(chan store.StoreResult, 1) hchan := make(chan store.GenericStoreResult[*model.IncomingWebhook], 1)
go func() { go func() {
webhook, err := a.Srv().Store().Webhook().GetIncoming(hookID, true) webhook, err := a.Srv().Store().Webhook().GetIncoming(hookID, true)
hchan <- store.StoreResult{Data: webhook, NErr: err} hchan <- store.GenericStoreResult[*model.IncomingWebhook]{Data: webhook, NErr: err}
close(hchan) close(hchan)
}() }()
@@ -688,12 +688,12 @@ func (a *App) HandleIncomingWebhook(c request.CTX, hookID string, req *model.Inc
if result.NErr != nil { if result.NErr != nil {
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.invalid.app_error", nil, "", http.StatusBadRequest).Wrap(result.NErr) return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.invalid.app_error", nil, "", http.StatusBadRequest).Wrap(result.NErr)
} }
hook = result.Data.(*model.IncomingWebhook) hook = result.Data
uchan := make(chan store.StoreResult, 1) uchan := make(chan store.GenericStoreResult[*model.User], 1)
go func() { go func() {
user, err := a.Srv().Store().User().Get(context.Background(), hook.UserId) user, err := a.Srv().Store().User().Get(context.Background(), hook.UserId)
uchan <- store.StoreResult{Data: user, NErr: err} uchan <- store.GenericStoreResult[*model.User]{Data: user, NErr: err}
close(uchan) close(uchan)
}() }()
@@ -712,7 +712,7 @@ func (a *App) HandleIncomingWebhook(c request.CTX, hookID string, req *model.Inc
} }
var channel *model.Channel var channel *model.Channel
var cchan chan store.StoreResult var cchan chan store.GenericStoreResult[*model.Channel]
if channelName != "" { if channelName != "" {
if channelName[0] == '@' { if channelName[0] == '@' {
@@ -726,17 +726,17 @@ func (a *App) HandleIncomingWebhook(c request.CTX, hookID string, req *model.Inc
} }
channel = ch channel = ch
} else if channelName[0] == '#' { } else if channelName[0] == '#' {
cchan = make(chan store.StoreResult, 1) cchan = make(chan store.GenericStoreResult[*model.Channel], 1)
go func() { go func() {
chnn, chnnErr := a.Srv().Store().Channel().GetByName(hook.TeamId, channelName[1:], true) chnn, chnnErr := a.Srv().Store().Channel().GetByName(hook.TeamId, channelName[1:], true)
cchan <- store.StoreResult{Data: chnn, NErr: chnnErr} cchan <- store.GenericStoreResult[*model.Channel]{Data: chnn, NErr: chnnErr}
close(cchan) close(cchan)
}() }()
} else { } else {
cchan = make(chan store.StoreResult, 1) cchan = make(chan store.GenericStoreResult[*model.Channel], 1)
go func() { go func() {
chnn, chnnErr := a.Srv().Store().Channel().GetByName(hook.TeamId, channelName, true) chnn, chnnErr := a.Srv().Store().Channel().GetByName(hook.TeamId, channelName, true)
cchan <- store.StoreResult{Data: chnn, NErr: chnnErr} cchan <- store.GenericStoreResult[*model.Channel]{Data: chnn, NErr: chnnErr}
close(cchan) close(cchan)
}() }()
} }
@@ -765,16 +765,16 @@ func (a *App) HandleIncomingWebhook(c request.CTX, hookID string, req *model.Inc
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "", http.StatusInternalServerError).Wrap(result2.NErr) return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "", http.StatusInternalServerError).Wrap(result2.NErr)
} }
} }
channel = result2.Data.(*model.Channel) channel = result2.Data
} }
if hook.ChannelLocked && hook.ChannelId != channel.Id { if hook.ChannelLocked && hook.ChannelId != channel.Id {
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel_locked.app_error", nil, "", http.StatusForbidden) return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel_locked.app_error", nil, "", http.StatusForbidden)
} }
result = <-uchan resultU := <-uchan
if result.NErr != nil { if resultU.NErr != nil {
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, "", http.StatusForbidden).Wrap(result.NErr) return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, "", http.StatusForbidden).Wrap(resultU.NErr)
} }
if channel.Type != model.ChannelTypeOpen && !a.HasPermissionToChannel(c, hook.UserId, channel.Id, model.PermissionReadChannelContent) { if channel.Type != model.ChannelTypeOpen && !a.HasPermissionToChannel(c, hook.UserId, channel.Id, model.PermissionReadChannelContent) {