Commit ccfcf02e by Leonard Gram

Refactors ds permissions to a filter.

parent f150f351
......@@ -17,18 +17,21 @@ func GetDataSources(c *m.ReqContext) Response {
return Error(500, "Failed to query datasources", err)
}
permissions := map[int64]m.DsPermissionType{}
permissionsQuery := m.GetDataSourcePermissionsForUserQuery{User: c.SignedInUser}
if err := bus.Dispatch(&permissionsQuery); err != nil {
dsFilterQuery := m.DatasourcesPermissionFilterQuery{
User: c.SignedInUser,
Datasources: query.Result,
}
if err := bus.Dispatch(&dsFilterQuery); err != nil {
if err != bus.ErrHandlerNotFound {
return Error(500, "failed to read datasource permissions", err)
return Error(500, "Could not get datasources", err)
}
} else {
permissions = permissionsQuery.Result
dsFilterQuery.Result = query.Result
}
result := make(dtos.DataSourceList, 0)
for _, ds := range query.Result {
for _, ds := range dsFilterQuery.Result {
dsItem := dtos.DataSourceListItemDTO{
OrgId: ds.OrgId,
Id: ds.Id,
......@@ -45,13 +48,6 @@ func GetDataSources(c *m.ReqContext) Response {
ReadOnly: ds.ReadOnly,
}
if permission, ok := permissions[ds.Id]; ok {
c.Logger.Info("Found permission", "permission", permission)
if permission == m.DsPermissionNoAccess {
continue
}
}
if plugin, exists := plugins.DataSources[ds.Type]; exists {
dsItem.TypeLogoUrl = plugin.Info.Logos.Small
} else {
......
......@@ -217,3 +217,9 @@ type GetDataSourcePermissionsForUserQuery struct {
User *SignedInUser
Result map[int64]DsPermissionType
}
type DatasourcesPermissionFilterQuery struct {
User *SignedInUser
Datasources []*DataSource
Result []*DataSource
}
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