Merge branch 'master' into alerting_definitions

This commit is contained in:
bergquist 2016-04-25 16:42:33 +02:00
commit bb42579b0f
4 changed files with 49 additions and 12 deletions

View File

@ -103,6 +103,10 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
} }
for _, include := range plugin.Includes { for _, include := range plugin.Includes {
if !c.HasUserRole(include.Role) {
continue
}
if include.Type == "page" && include.AddToNav { if include.Type == "page" && include.AddToNav {
link := &dtos.NavLink{ link := &dtos.NavLink{
Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/page/" + include.Slug, 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) appLink.Children = append(appLink.Children, link)
} }
if include.Type == "dashboard" && include.AddToNav { if include.Type == "dashboard" && include.AddToNav {
link := &dtos.NavLink{ link := &dtos.NavLink{
Url: setting.AppSubUrl + "/dashboard/db/" + include.Slug, 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"}) 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)
}
} }
} }

View File

@ -1,7 +1,9 @@
package models package models
import ( import (
"encoding/json"
"errors" "errors"
"fmt"
"time" "time"
) )
@ -37,6 +39,26 @@ func (r RoleType) Includes(other RoleType) bool {
return r == other 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 { type OrgUser struct {
Id int64 Id int64
OrgId int64 OrgId int64

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
"github.com/grafana/grafana/pkg/log" "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" "github.com/grafana/grafana/pkg/setting"
) )
@ -69,6 +69,12 @@ func (pb *PluginBase) registerPlugin(pluginDir string) error {
pb.Dependencies.GrafanaVersion = "*" pb.Dependencies.GrafanaVersion = "*"
} }
for _, include := range pb.Includes {
if include.Role == "" {
include.Role = m.RoleType(m.ROLE_VIEWER)
}
}
pb.PluginDir = pluginDir pb.PluginDir = pluginDir
Plugins[pb.Id] = pb Plugins[pb.Id] = pb
return nil return nil
@ -80,14 +86,14 @@ type PluginDependencies struct {
} }
type PluginInclude struct { type PluginInclude struct {
Name string `json:"name"` Name string `json:"name"`
Path string `json:"path"` Path string `json:"path"`
Type string `json:"type"` Type string `json:"type"`
Component string `json:"component"` Component string `json:"component"`
Role models.RoleType `json:"role"` Role m.RoleType `json:"role"`
AddToNav bool `json:"addToNav"` AddToNav bool `json:"addToNav"`
DefaultNav bool `json:"defaultNav"` DefaultNav bool `json:"defaultNav"`
Slug string `json:"slug"` Slug string `json:"slug"`
Id string `json:"-"` Id string `json:"-"`
} }

View File

@ -162,12 +162,14 @@ export default class InfluxQuery {
return str + '"' + tag.key + '" ' + operator + ' ' + value; return str + '"' + tag.key + '" ' + operator + ' ' + value;
} }
getMeasurementAndPolicy() { getMeasurementAndPolicy(interpolate) {
var policy = this.target.policy; var policy = this.target.policy;
var measurement = this.target.measurement; var measurement = this.target.measurement;
if (!measurement.match('^/.*/')) { if (!measurement.match('^/.*/')) {
measurement = '"' + measurement+ '"'; measurement = '"' + measurement+ '"';
} else if (interpolate) {
measurement = this.templateSrv.replace(measurement, this.scopedVars, 'regex');
} }
if (policy !== 'default') { if (policy !== 'default') {
@ -210,7 +212,7 @@ export default class InfluxQuery {
query += selectText; query += selectText;
} }
query += ' FROM ' + this.getMeasurementAndPolicy() + ' WHERE '; query += ' FROM ' + this.getMeasurementAndPolicy(interpolate) + ' WHERE ';
var conditions = _.map(target.tags, (tag, index) => { var conditions = _.map(target.tags, (tag, index) => {
return this.renderTagCondition(tag, index, interpolate); return this.renderTagCondition(tag, index, interpolate);
}); });