Commit 0f136a94 by bergquist

datasource as cfg: enable editable ds's

parent b72cdae5
......@@ -39,6 +39,10 @@ datasources:
# # <int> including this value garantees that instance with old configs cannot
# # overwrite your last change.
# version: 1
# # <bool> allow users to edit datasources from the UI.
# editable: true
# - name: Prometheus
# type: prometheus
# access: proxy
......
......@@ -137,6 +137,7 @@ func TestDatasourceAsConfig(t *testing.T) {
So(ds.BasicAuthPassword, ShouldEqual, "basic_auth_password")
So(ds.WithCredentials, ShouldBeTrue)
So(ds.IsDefault, ShouldBeTrue)
So(ds.Editable, ShouldBeTrue)
})
})
}
......
......@@ -15,3 +15,4 @@ datasources:
is_default: true
json_data: '{"graphiteVersion":"0.9"}'
secure_json_fields: ''
editable: true
......@@ -26,6 +26,7 @@ type DataSourceFromConfig struct {
IsDefault bool `json:"is_default" yaml:"is_default"`
JsonData string `json:"json_data" yaml:"json_data"`
SecureJsonData map[string]string `json:"secure_json_data" yaml:"secure_json_data"`
Editable bool `json:"editable" yaml:"editable"`
}
func createInsertCommand(ds DataSourceFromConfig) *models.AddDataSourceCommand {
......@@ -50,7 +51,7 @@ func createInsertCommand(ds DataSourceFromConfig) *models.AddDataSourceCommand {
IsDefault: ds.IsDefault,
JsonData: jsonData,
SecureJsonData: ds.SecureJsonData,
ReadOnly: true,
ReadOnly: !ds.Editable,
}
}
......@@ -77,6 +78,6 @@ func createUpdateCommand(ds DataSourceFromConfig, id int64) *models.UpdateDataSo
IsDefault: ds.IsDefault,
JsonData: jsonData,
SecureJsonData: ds.SecureJsonData,
ReadOnly: true,
ReadOnly: !ds.Editable,
}
}
......@@ -159,6 +159,7 @@ func UpdateDataSource(cmd *m.UpdateDataSourceCommand) error {
sess.UseBool("is_default")
sess.UseBool("basic_auth")
sess.UseBool("with_credentials")
sess.UseBool("read_only")
var updateSession *xorm.Session
if cmd.Version != 0 {
......
......@@ -45,6 +45,7 @@ func TestDataAccess(t *testing.T) {
Access: m.DS_ACCESS_DIRECT,
Url: "http://test",
Database: "site",
ReadOnly: true,
})
So(err, ShouldBeNil)
......@@ -59,6 +60,7 @@ func TestDataAccess(t *testing.T) {
So(ds.OrgId, ShouldEqual, 10)
So(ds.Database, ShouldEqual, "site")
So(ds.ReadOnly, ShouldBeTrue)
})
Convey("Given a datasource", func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment