[MM-41290] Add Endpoint to complete onboarding (#19435)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a733fb840d
Коммит
321b19e3db
@@ -438,6 +438,7 @@ type AppIface interface {
|
||||
CompareAndDeletePluginKey(pluginID string, key string, oldValue []byte) (bool, *model.AppError)
|
||||
CompareAndSetPluginKey(pluginID string, key string, oldValue, newValue []byte) (bool, *model.AppError)
|
||||
CompleteOAuth(c *request.Context, service string, body io.ReadCloser, teamID string, props map[string]string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
CompleteOnboarding(request *model.CompleteOnboardingRequest) *model.AppError
|
||||
CompleteSwitchWithOAuth(service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
Compliance() einterfaces.ComplianceInterface
|
||||
Config() *model.Config
|
||||
|
||||
46
app/onboarding.go
Обычный файл
46
app/onboarding.go
Обычный файл
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (a *App) CompleteOnboarding(request *model.CompleteOnboardingRequest) *model.AppError {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
if !*a.Config().PluginSettings.Enable {
|
||||
return model.NewAppError("completeOnboarding", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
for _, id := range request.InstallPlugins {
|
||||
wg.Add(1)
|
||||
|
||||
go func(id string) {
|
||||
defer wg.Done()
|
||||
installRequest := &model.InstallMarketplacePluginRequest{
|
||||
Id: id,
|
||||
}
|
||||
_, appErr := a.Channels().InstallMarketplacePlugin(installRequest)
|
||||
if appErr != nil {
|
||||
mlog.Error("Failed to install plugin for onboarding", mlog.String("id", id), mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
|
||||
appErr = a.Channels().enablePlugin(id)
|
||||
if appErr != nil {
|
||||
mlog.Error("Failed to enable plugin for onboarding", mlog.String("id", id), mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
}(id)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1671,6 +1671,28 @@ func (a *OpenTracingAppLayer) CompleteOAuth(c *request.Context, service string,
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CompleteOnboarding(request *model.CompleteOnboardingRequest) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CompleteOnboarding")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.CompleteOnboarding(request)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CompleteSwitchWithOAuth(service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CompleteSwitchWithOAuth")
|
||||
|
||||
@@ -538,6 +538,8 @@ func (a *App) GetMarketplacePlugins(filter *model.MarketplacePluginFilter) ([]*m
|
||||
}
|
||||
|
||||
// getPrepackagedPlugin returns a pre-packaged plugin.
|
||||
//
|
||||
// If version is empty, the first matching plugin is returned.
|
||||
func (ch *Channels) getPrepackagedPlugin(pluginID, version string) (*plugin.PrepackagedPlugin, *model.AppError) {
|
||||
pluginsEnvironment := ch.GetPluginsEnvironment()
|
||||
if pluginsEnvironment == nil {
|
||||
@@ -546,7 +548,7 @@ func (ch *Channels) getPrepackagedPlugin(pluginID, version string) (*plugin.Prep
|
||||
|
||||
prepackagedPlugins := pluginsEnvironment.PrepackagedPlugins()
|
||||
for _, p := range prepackagedPlugins {
|
||||
if p.Manifest.Id == pluginID && p.Manifest.Version == version {
|
||||
if p.Manifest.Id == pluginID && (version == "" || p.Manifest.Version == version) {
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
@@ -555,6 +557,8 @@ func (ch *Channels) getPrepackagedPlugin(pluginID, version string) (*plugin.Prep
|
||||
}
|
||||
|
||||
// getRemoteMarketplacePlugin returns plugin from marketplace-server.
|
||||
//
|
||||
// If version is empty, the latest compatible version is used.
|
||||
func (ch *Channels) getRemoteMarketplacePlugin(pluginID, version string) (*model.BaseMarketplacePlugin, *model.AppError) {
|
||||
marketplaceClient, err := marketplace.NewClient(
|
||||
*ch.srv.Config().PluginSettings.MarketplaceURL,
|
||||
@@ -566,9 +570,13 @@ func (ch *Channels) getRemoteMarketplacePlugin(pluginID, version string) (*model
|
||||
|
||||
filter := ch.getBaseMarketplaceFilter()
|
||||
filter.PluginId = pluginID
|
||||
filter.ReturnAllVersions = true
|
||||
|
||||
plugin, err := marketplaceClient.GetPlugin(filter, version)
|
||||
var plugin *model.BaseMarketplacePlugin
|
||||
if version != "" {
|
||||
plugin, err = marketplaceClient.GetPlugin(filter, version)
|
||||
} else {
|
||||
plugin, err = marketplaceClient.GetLatestPlugin(filter)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetMarketplacePlugin", "app.plugin.marketplace_plugins.not_found.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user