process app plugins first (#41346)

This commit is contained in:
Will Browne 2021-11-05 14:07:53 +00:00 committed by GitHub
parent 14742ea44a
commit 8a42fca485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -398,46 +398,59 @@ func (hs *HTTPServer) enabledPlugins(ctx context.Context, orgID int64) (EnabledP
} }
func (hs *HTTPServer) pluginSettings(ctx context.Context, orgID int64) (map[string]*models.PluginSettingInfoDTO, error) { func (hs *HTTPServer) pluginSettings(ctx context.Context, orgID int64) (map[string]*models.PluginSettingInfoDTO, error) {
pluginSettings, err := hs.SQLStore.GetPluginSettings(ctx, orgID) pluginSettings := make(map[string]*models.PluginSettingInfoDTO)
if err != nil {
// fill settings from database
if pss, err := hs.SQLStore.GetPluginSettings(ctx, orgID); err != nil {
return nil, err return nil, err
} else {
for _, ps := range pss {
pluginSettings[ps.PluginId] = ps
}
} }
pluginMap := make(map[string]*models.PluginSettingInfoDTO) // fill settings from app plugins
for _, plug := range pluginSettings { for _, plugin := range hs.pluginStore.Plugins(plugins.App) {
pluginMap[plug.PluginId] = plug // ignore settings that already exist
} if _, exists := pluginSettings[plugin.ID]; exists {
for _, pluginDef := range hs.pluginStore.Plugins() {
// ignore entries that already exist
if _, ok := pluginMap[pluginDef.ID]; ok {
continue continue
} }
// enabled by default // add new setting which is enabled depending on if AutoEnabled: true
opt := &models.PluginSettingInfoDTO{ pluginSetting := &models.PluginSettingInfoDTO{
PluginId: pluginDef.ID, PluginId: plugin.ID,
OrgId: orgID,
Enabled: plugin.AutoEnabled,
Pinned: plugin.AutoEnabled,
}
pluginSettings[plugin.ID] = pluginSetting
}
// fill settings from all remaining plugins (including potential app child plugins)
for _, plugin := range hs.pluginStore.Plugins() {
// ignore settings that already exist
if _, exists := pluginSettings[plugin.ID]; exists {
continue
}
// add new setting which is enabled by default
pluginSetting := &models.PluginSettingInfoDTO{
PluginId: plugin.ID,
OrgId: orgID, OrgId: orgID,
Enabled: true, Enabled: true,
} }
// apps are disabled by default unless autoEnabled: true // if plugin is included in an app, check app settings
if p := hs.pluginStore.Plugin(pluginDef.ID); p != nil && p.IsApp() { if plugin.IncludedInAppID != "" {
opt.Enabled = p.AutoEnabled // app child plugins are disabled unless app is enabled
opt.Pinned = p.AutoEnabled pluginSetting.Enabled = false
} if p, exists := pluginSettings[plugin.IncludedInAppID]; exists {
pluginSetting.Enabled = p.Enabled
// if it's included in app, check app settings
if pluginDef.IncludedInAppID != "" {
// app components are by default disabled
opt.Enabled = false
if appSettings, ok := pluginMap[pluginDef.IncludedInAppID]; ok {
opt.Enabled = appSettings.Enabled
} }
} }
pluginMap[pluginDef.ID] = opt pluginSettings[plugin.ID] = pluginSetting
} }
return pluginMap, nil return pluginSettings, nil
} }