[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).
Этот коммит содержится в:
@@ -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)
|
||||
}
|
||||
|
||||
hchan := make(chan store.StoreResult, 1)
|
||||
hchan := make(chan store.GenericStoreResult[*model.IncomingWebhook], 1)
|
||||
go func() {
|
||||
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)
|
||||
}()
|
||||
|
||||
@@ -688,12 +688,12 @@ func (a *App) HandleIncomingWebhook(c request.CTX, hookID string, req *model.Inc
|
||||
if result.NErr != nil {
|
||||
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() {
|
||||
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)
|
||||
}()
|
||||
|
||||
@@ -712,7 +712,7 @@ func (a *App) HandleIncomingWebhook(c request.CTX, hookID string, req *model.Inc
|
||||
}
|
||||
|
||||
var channel *model.Channel
|
||||
var cchan chan store.StoreResult
|
||||
var cchan chan store.GenericStoreResult[*model.Channel]
|
||||
|
||||
if channelName != "" {
|
||||
if channelName[0] == '@' {
|
||||
@@ -726,17 +726,17 @@ func (a *App) HandleIncomingWebhook(c request.CTX, hookID string, req *model.Inc
|
||||
}
|
||||
channel = ch
|
||||
} else if channelName[0] == '#' {
|
||||
cchan = make(chan store.StoreResult, 1)
|
||||
cchan = make(chan store.GenericStoreResult[*model.Channel], 1)
|
||||
go func() {
|
||||
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)
|
||||
}()
|
||||
} else {
|
||||
cchan = make(chan store.StoreResult, 1)
|
||||
cchan = make(chan store.GenericStoreResult[*model.Channel], 1)
|
||||
go func() {
|
||||
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)
|
||||
}()
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
channel = result2.Data.(*model.Channel)
|
||||
channel = result2.Data
|
||||
}
|
||||
|
||||
if hook.ChannelLocked && hook.ChannelId != channel.Id {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel_locked.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
result = <-uchan
|
||||
if result.NErr != nil {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, "", http.StatusForbidden).Wrap(result.NErr)
|
||||
resultU := <-uchan
|
||||
if resultU.NErr != nil {
|
||||
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) {
|
||||
|
||||
Ссылка в новой задаче
Block a user