Plugins: Add plugin settings DTO (#46283)

* add clearer service layer

* re-order frontend settings for clarity

* fix fetch fail

* fix API response

* fix mockstore

* in -> where
This commit is contained in:
Will Browne
2022-03-18 20:49:13 +01:00
committed by GitHub
parent 1afd278bd0
commit bda3f860a8
16 changed files with 426 additions and 308 deletions
+1 -1
View File
@@ -291,7 +291,7 @@ func (m *SQLStoreMock) PatchPreferences(ctx context.Context, cmd *models.PatchPr
return m.ExpectedError
}
func (m *SQLStoreMock) GetPluginSettings(ctx context.Context, orgID int64) ([]*models.PluginSettingInfoDTO, error) {
func (m *SQLStoreMock) GetPluginSettings(ctx context.Context, orgID int64) ([]*models.PluginSetting, error) {
return nil, m.ExpectedError
}
+14 -17
View File
@@ -7,25 +7,22 @@ import (
"github.com/grafana/grafana/pkg/models"
)
func (ss *SQLStore) GetPluginSettings(ctx context.Context, orgID int64) ([]*models.PluginSettingInfoDTO, error) {
sql := `SELECT org_id, plugin_id, enabled, pinned, plugin_version
FROM plugin_setting `
params := make([]interface{}, 0)
if orgID != 0 {
sql += "WHERE org_id=?"
params = append(params, orgID)
}
var rslt []*models.PluginSettingInfoDTO
func (ss *SQLStore) GetPluginSettings(ctx context.Context, orgID int64) ([]*models.PluginSetting, error) {
var rslt = make([]*models.PluginSetting, 0)
err := ss.WithDbSession(ctx, func(sess *DBSession) error {
return sess.SQL(sql, params...).Find(&rslt)
})
if err != nil {
return nil, err
}
if orgID != 0 {
sess.Where("org_id", orgID)
}
return rslt, nil
err := sess.Find(&rslt)
if err != nil {
return err
}
return nil
})
return rslt, err
}
func (ss *SQLStore) GetPluginSettingById(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
+1 -1
View File
@@ -64,7 +64,7 @@ type Store interface {
GetPreferences(ctx context.Context, query *models.GetPreferencesQuery) error
SavePreferences(ctx context.Context, cmd *models.SavePreferencesCommand) error
PatchPreferences(ctx context.Context, cmd *models.PatchPreferencesCommand) error
GetPluginSettings(ctx context.Context, orgID int64) ([]*models.PluginSettingInfoDTO, error)
GetPluginSettings(ctx context.Context, orgID int64) ([]*models.PluginSetting, error)
GetPluginSettingById(ctx context.Context, query *models.GetPluginSettingByIdQuery) error
UpdatePluginSetting(ctx context.Context, cmd *models.UpdatePluginSettingCmd) error
UpdatePluginSettingVersion(ctx context.Context, cmd *models.UpdatePluginSettingVersionCmd) error