From 04a79175bfdfa0fa705eb3c0852e599d9108d91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 25 Apr 2016 14:00:49 +0200 Subject: [PATCH 1/3] fix(plugins): only add app nav link if it has any pages/dashboards with role matching current user, fixes #4784 --- pkg/api/index.go | 9 ++++++++- pkg/models/org_user.go | 22 ++++++++++++++++++++++ pkg/plugins/models.go | 24 +++++++++++++++--------- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/pkg/api/index.go b/pkg/api/index.go index 575ea35cfaf..53538fd2775 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -103,6 +103,10 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { } for _, include := range plugin.Includes { + if !c.HasUserRole(include.Role) { + continue + } + if include.Type == "page" && include.AddToNav { link := &dtos.NavLink{ Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/page/" + include.Slug, @@ -110,6 +114,7 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { } appLink.Children = append(appLink.Children, link) } + if include.Type == "dashboard" && include.AddToNav { link := &dtos.NavLink{ Url: setting.AppSubUrl + "/dashboard/db/" + include.Slug, @@ -124,7 +129,9 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { appLink.Children = append(appLink.Children, &dtos.NavLink{Text: "Plugin Config", Icon: "fa fa-cog", Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/edit"}) } - data.MainNavLinks = append(data.MainNavLinks, appLink) + if len(appLink.Children) > 0 { + data.MainNavLinks = append(data.MainNavLinks, appLink) + } } } diff --git a/pkg/models/org_user.go b/pkg/models/org_user.go index 48d17deb9db..d7a918751ef 100644 --- a/pkg/models/org_user.go +++ b/pkg/models/org_user.go @@ -1,7 +1,9 @@ package models import ( + "encoding/json" "errors" + "fmt" "time" ) @@ -37,6 +39,26 @@ func (r RoleType) Includes(other RoleType) bool { return r == other } +func (r *RoleType) UnmarshalJSON(data []byte) error { + var str string + err := json.Unmarshal(data, &str) + if err != nil { + return err + } + + *r = RoleType(str) + + if (*r).IsValid() == false { + if (*r) != "" { + return errors.New(fmt.Sprintf("JSON validation error: invalid role value: %s", *r)) + } + + *r = ROLE_VIEWER + } + + return nil +} + type OrgUser struct { Id int64 OrgId int64 diff --git a/pkg/plugins/models.go b/pkg/plugins/models.go index 68268239c51..aa381abacc7 100644 --- a/pkg/plugins/models.go +++ b/pkg/plugins/models.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/grafana/grafana/pkg/log" - "github.com/grafana/grafana/pkg/models" + m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/setting" ) @@ -69,6 +69,12 @@ func (pb *PluginBase) registerPlugin(pluginDir string) error { pb.Dependencies.GrafanaVersion = "*" } + for _, include := range pb.Includes { + if include.Role == "" { + include.Role = m.RoleType(m.ROLE_VIEWER) + } + } + pb.PluginDir = pluginDir Plugins[pb.Id] = pb return nil @@ -80,14 +86,14 @@ type PluginDependencies struct { } type PluginInclude struct { - Name string `json:"name"` - Path string `json:"path"` - Type string `json:"type"` - Component string `json:"component"` - Role models.RoleType `json:"role"` - AddToNav bool `json:"addToNav"` - DefaultNav bool `json:"defaultNav"` - Slug string `json:"slug"` + Name string `json:"name"` + Path string `json:"path"` + Type string `json:"type"` + Component string `json:"component"` + Role m.RoleType `json:"role"` + AddToNav bool `json:"addToNav"` + DefaultNav bool `json:"defaultNav"` + Slug string `json:"slug"` Id string `json:"-"` } From 4d802df040921779434ba223bece0a94a56ae47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 25 Apr 2016 14:22:15 +0200 Subject: [PATCH 2/3] fix(influxdb): fixed issue with using multi value template vars in influxdb measurement clause, fixes #4797 --- public/app/plugins/datasource/influxdb/influx_query.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/app/plugins/datasource/influxdb/influx_query.ts b/public/app/plugins/datasource/influxdb/influx_query.ts index 8143e187b76..68392348f1a 100644 --- a/public/app/plugins/datasource/influxdb/influx_query.ts +++ b/public/app/plugins/datasource/influxdb/influx_query.ts @@ -168,6 +168,8 @@ export default class InfluxQuery { if (!measurement.match('^/.*/')) { measurement = '"' + measurement+ '"'; + } else { + measurement = this.templateSrv.replace(measurement, this.scopedVars, 'regex'); } if (policy !== 'default') { From 6bc898b215877b06c6731d252a8b362393eea4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 25 Apr 2016 14:29:51 +0200 Subject: [PATCH 3/3] fix(influxdb): fixed issue with using multi value template vars in influxdb measurement clause, fixes #4797 --- public/app/plugins/datasource/influxdb/influx_query.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/influx_query.ts b/public/app/plugins/datasource/influxdb/influx_query.ts index 68392348f1a..407861f22df 100644 --- a/public/app/plugins/datasource/influxdb/influx_query.ts +++ b/public/app/plugins/datasource/influxdb/influx_query.ts @@ -162,13 +162,13 @@ export default class InfluxQuery { return str + '"' + tag.key + '" ' + operator + ' ' + value; } - getMeasurementAndPolicy() { + getMeasurementAndPolicy(interpolate) { var policy = this.target.policy; var measurement = this.target.measurement; if (!measurement.match('^/.*/')) { measurement = '"' + measurement+ '"'; - } else { + } else if (interpolate) { measurement = this.templateSrv.replace(measurement, this.scopedVars, 'regex'); } @@ -212,7 +212,7 @@ export default class InfluxQuery { query += selectText; } - query += ' FROM ' + this.getMeasurementAndPolicy() + ' WHERE '; + query += ' FROM ' + this.getMeasurementAndPolicy(interpolate) + ' WHERE '; var conditions = _.map(target.tags, (tag, index) => { return this.renderTagCondition(tag, index, interpolate); });