Skip to content

Commit

Permalink
added setting top hide plugins in alpha state
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelo committed Oct 9, 2018
1 parent d2bdf8c commit 565edc1
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 90 deletions.
3 changes: 3 additions & 0 deletions conf/defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,6 @@ container_name =
# Options to configure external image rendering server like https://github.com/grafana/grafana-image-renderer
server_url =
callback_url =

[panels]
enable_alpha = false
116 changes: 58 additions & 58 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,66 +22,66 @@ func (hs *HTTPServer) registerRoutes() {
r := hs.RouteRegister

// not logged in views
r.Get("/", reqSignedIn, Index)
r.Get("/", reqSignedIn, hs.Index)
r.Get("/logout", Logout)
r.Post("/login", quota("session"), bind(dtos.LoginCommand{}), Wrap(LoginPost))
r.Get("/login/:name", quota("session"), OAuthLogin)
r.Get("/login", LoginView)
r.Get("/invite/:code", Index)
r.Get("/login", hs.LoginView)
r.Get("/invite/:code", hs.Index)

// authed views
r.Get("/profile/", reqSignedIn, Index)
r.Get("/profile/password", reqSignedIn, Index)
r.Get("/profile/switch-org/:id", reqSignedIn, ChangeActiveOrgAndRedirectToHome)
r.Get("/org/", reqSignedIn, Index)
r.Get("/org/new", reqSignedIn, Index)
r.Get("/datasources/", reqSignedIn, Index)
r.Get("/datasources/new", reqSignedIn, Index)
r.Get("/datasources/edit/*", reqSignedIn, Index)
r.Get("/org/users", reqSignedIn, Index)
r.Get("/org/users/new", reqSignedIn, Index)
r.Get("/org/users/invite", reqSignedIn, Index)
r.Get("/org/teams", reqSignedIn, Index)
r.Get("/org/teams/*", reqSignedIn, Index)
r.Get("/org/apikeys/", reqSignedIn, Index)
r.Get("/dashboard/import/", reqSignedIn, Index)
r.Get("/configuration", reqGrafanaAdmin, Index)
r.Get("/admin", reqGrafanaAdmin, Index)
r.Get("/admin/settings", reqGrafanaAdmin, Index)
r.Get("/admin/users", reqGrafanaAdmin, Index)
r.Get("/admin/users/create", reqGrafanaAdmin, Index)
r.Get("/admin/users/edit/:id", reqGrafanaAdmin, Index)
r.Get("/admin/orgs", reqGrafanaAdmin, Index)
r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, Index)
r.Get("/admin/stats", reqGrafanaAdmin, Index)

r.Get("/styleguide", reqSignedIn, Index)

r.Get("/plugins", reqSignedIn, Index)
r.Get("/plugins/:id/edit", reqSignedIn, Index)
r.Get("/plugins/:id/page/:page", reqSignedIn, Index)

r.Get("/d/:uid/:slug", reqSignedIn, Index)
r.Get("/d/:uid", reqSignedIn, Index)
r.Get("/dashboard/db/:slug", reqSignedIn, redirectFromLegacyDashboardURL, Index)
r.Get("/dashboard/script/*", reqSignedIn, Index)
r.Get("/dashboard-solo/snapshot/*", Index)
r.Get("/d-solo/:uid/:slug", reqSignedIn, Index)
r.Get("/dashboard-solo/db/:slug", reqSignedIn, redirectFromLegacyDashboardSoloURL, Index)
r.Get("/dashboard-solo/script/*", reqSignedIn, Index)
r.Get("/import/dashboard", reqSignedIn, Index)
r.Get("/dashboards/", reqSignedIn, Index)
r.Get("/dashboards/*", reqSignedIn, Index)

r.Get("/explore", reqEditorRole, Index)

r.Get("/playlists/", reqSignedIn, Index)
r.Get("/playlists/*", reqSignedIn, Index)
r.Get("/alerting/", reqSignedIn, Index)
r.Get("/alerting/*", reqSignedIn, Index)
r.Get("/profile/", reqSignedIn, hs.Index)
r.Get("/profile/password", reqSignedIn, hs.Index)
r.Get("/profile/switch-org/:id", reqSignedIn, hs.ChangeActiveOrgAndRedirectToHome)
r.Get("/org/", reqSignedIn, hs.Index)
r.Get("/org/new", reqSignedIn, hs.Index)
r.Get("/datasources/", reqSignedIn, hs.Index)
r.Get("/datasources/new", reqSignedIn, hs.Index)
r.Get("/datasources/edit/*", reqSignedIn, hs.Index)
r.Get("/org/users", reqSignedIn, hs.Index)
r.Get("/org/users/new", reqSignedIn, hs.Index)
r.Get("/org/users/invite", reqSignedIn, hs.Index)
r.Get("/org/teams", reqSignedIn, hs.Index)
r.Get("/org/teams/*", reqSignedIn, hs.Index)
r.Get("/org/apikeys/", reqSignedIn, hs.Index)
r.Get("/dashboard/import/", reqSignedIn, hs.Index)
r.Get("/configuration", reqGrafanaAdmin, hs.Index)
r.Get("/admin", reqGrafanaAdmin, hs.Index)
r.Get("/admin/settings", reqGrafanaAdmin, hs.Index)
r.Get("/admin/users", reqGrafanaAdmin, hs.Index)
r.Get("/admin/users/create", reqGrafanaAdmin, hs.Index)
r.Get("/admin/users/edit/:id", reqGrafanaAdmin, hs.Index)
r.Get("/admin/orgs", reqGrafanaAdmin, hs.Index)
r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, hs.Index)
r.Get("/admin/stats", reqGrafanaAdmin, hs.Index)

r.Get("/styleguide", reqSignedIn, hs.Index)

r.Get("/plugins", reqSignedIn, hs.Index)
r.Get("/plugins/:id/edit", reqSignedIn, hs.Index)
r.Get("/plugins/:id/page/:page", reqSignedIn, hs.Index)

r.Get("/d/:uid/:slug", reqSignedIn, hs.Index)
r.Get("/d/:uid", reqSignedIn, hs.Index)
r.Get("/dashboard/db/:slug", reqSignedIn, redirectFromLegacyDashboardURL, hs.Index)
r.Get("/dashboard/script/*", reqSignedIn, hs.Index)
r.Get("/dashboard-solo/snapshot/*", hs.Index)
r.Get("/d-solo/:uid/:slug", reqSignedIn, hs.Index)
r.Get("/dashboard-solo/db/:slug", reqSignedIn, redirectFromLegacyDashboardSoloURL, hs.Index)
r.Get("/dashboard-solo/script/*", reqSignedIn, hs.Index)
r.Get("/import/dashboard", reqSignedIn, hs.Index)
r.Get("/dashboards/", reqSignedIn, hs.Index)
r.Get("/dashboards/*", reqSignedIn, hs.Index)

r.Get("/explore", reqEditorRole, hs.Index)

r.Get("/playlists/", reqSignedIn, hs.Index)
r.Get("/playlists/*", reqSignedIn, hs.Index)
r.Get("/alerting/", reqSignedIn, hs.Index)
r.Get("/alerting/*", reqSignedIn, hs.Index)

// sign up
r.Get("/signup", Index)
r.Get("/signup", hs.Index)
r.Get("/api/user/signup/options", Wrap(GetSignUpOptions))
r.Post("/api/user/signup", quota("user"), bind(dtos.SignUpForm{}), Wrap(SignUp))
r.Post("/api/user/signup/step2", bind(dtos.SignUpStep2Form{}), Wrap(SignUpStep2))
Expand All @@ -91,15 +91,15 @@ func (hs *HTTPServer) registerRoutes() {
r.Post("/api/user/invite/complete", bind(dtos.CompleteInviteForm{}), Wrap(CompleteInvite))

// reset password
r.Get("/user/password/send-reset-email", Index)
r.Get("/user/password/reset", Index)
r.Get("/user/password/send-reset-email", hs.Index)
r.Get("/user/password/reset", hs.Index)

r.Post("/api/user/password/send-reset-email", bind(dtos.SendResetPasswordEmailForm{}), Wrap(SendResetPasswordEmail))
r.Post("/api/user/password/reset", bind(dtos.ResetUserPasswordForm{}), Wrap(ResetPassword))

// dashboard snapshots
r.Get("/dashboard/snapshot/*", Index)
r.Get("/dashboard/snapshots/", reqSignedIn, Index)
r.Get("/dashboard/snapshot/*", hs.Index)
r.Get("/dashboard/snapshots/", reqSignedIn, hs.Index)

// api for dashboard snapshots
r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot)
Expand Down Expand Up @@ -251,7 +251,7 @@ func (hs *HTTPServer) registerRoutes() {
pluginRoute.Post("/:pluginId/settings", bind(m.UpdatePluginSettingCmd{}), Wrap(UpdatePluginSetting))
}, reqOrgAdmin)

apiRoute.Get("/frontend/settings/", GetFrontendSettings)
apiRoute.Get("/frontend/settings/", hs.GetFrontendSettings)
apiRoute.Any("/datasources/proxy/:id/*", reqSignedIn, hs.ProxyDataSourceRequest)
apiRoute.Any("/datasources/proxy/:id", reqSignedIn, hs.ProxyDataSourceRequest)

Expand Down
10 changes: 7 additions & 3 deletions pkg/api/frontendsettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/grafana/grafana/pkg/util"
)

func getFrontendSettingsMap(c *m.ReqContext) (map[string]interface{}, error) {
func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interface{}, error) {
orgDataSources := make([]*m.DataSource, 0)

if c.OrgId != 0 {
Expand Down Expand Up @@ -120,6 +120,10 @@ func getFrontendSettingsMap(c *m.ReqContext) (map[string]interface{}, error) {

panels := map[string]interface{}{}
for _, panel := range enabledPlugins.Panels {
if panel.State == "alpha" && !hs.Cfg.EnableAlphaPanels {
continue
}

panels[panel.Id] = map[string]interface{}{
"module": panel.Module,
"baseUrl": panel.BaseUrl,
Expand Down Expand Up @@ -183,8 +187,8 @@ func getPanelSort(id string) int {
return sort
}

func GetFrontendSettings(c *m.ReqContext) {
settings, err := getFrontendSettingsMap(c)
func (hs *HTTPServer) GetFrontendSettings(c *m.ReqContext) {
settings, err := hs.getFrontendSettingsMap(c)
if err != nil {
c.JsonApiErr(400, "Failed to get frontend settings", err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (hs *HTTPServer) applyRoutes() {
// then custom app proxy routes
hs.initAppPluginRoutes(hs.macaron)
// lastly not found route
hs.macaron.NotFound(NotFoundHandler)
hs.macaron.NotFound(hs.NotFoundHandler)
}

func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const (
darkName = "dark"
)

func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
settings, err := getFrontendSettingsMap(c)
func (hs *HTTPServer) setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
settings, err := hs.getFrontendSettingsMap(c)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -353,22 +353,22 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
return &data, nil
}

func Index(c *m.ReqContext) {
data, err := setIndexViewData(c)
func (hs *HTTPServer) Index(c *m.ReqContext) {
data, err := hs.setIndexViewData(c)
if err != nil {
c.Handle(500, "Failed to get settings", err)
return
}
c.HTML(200, "index", data)
}

func NotFoundHandler(c *m.ReqContext) {
func (hs *HTTPServer) NotFoundHandler(c *m.ReqContext) {
if c.IsApiRequest() {
c.JsonApiErr(404, "Not found", nil)
return
}

data, err := setIndexViewData(c)
data, err := hs.setIndexViewData(c)
if err != nil {
c.Handle(500, "Failed to get settings", err)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const (
ViewIndex = "index"
)

func LoginView(c *m.ReqContext) {
viewData, err := setIndexViewData(c)
func (hs *HTTPServer) LoginView(c *m.ReqContext) {
viewData, err := hs.setIndexViewData(c)
if err != nil {
c.Handle(500, "Failed to get settings", err)
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ func UserSetUsingOrg(c *m.ReqContext) Response {
}

// GET /profile/switch-org/:id
func ChangeActiveOrgAndRedirectToHome(c *m.ReqContext) {
func (hs *HTTPServer) ChangeActiveOrgAndRedirectToHome(c *m.ReqContext) {
orgID := c.ParamsInt64(":id")

if !validateUsingOrg(c.UserId, orgID) {
NotFoundHandler(c)
hs.NotFoundHandler(c)
}

cmd := m.SetUsingOrgCommand{UserId: c.UserId, OrgId: orgID}

if err := bus.Dispatch(&cmd); err != nil {
NotFoundHandler(c)
hs.NotFoundHandler(c)
}

c.Redirect(setting.AppSubUrl + "/")
Expand Down
5 changes: 5 additions & 0 deletions pkg/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ type Cfg struct {
TempDataLifetime time.Duration

MetricsEndpointEnabled bool

EnableAlphaPanels bool
}

type CommandLineArgs struct {
Expand Down Expand Up @@ -688,6 +690,9 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
explore := iniFile.Section("explore")
ExploreEnabled = explore.Key("enabled").MustBool(false)

panels := iniFile.Section("panels")
cfg.EnableAlphaPanels = panels.Key("enable_alpha").MustBool(false)

cfg.readSessionConfig()
cfg.readSmtpSettings()
cfg.readQuotaSettings()
Expand Down
12 changes: 9 additions & 3 deletions public/app/plugins/panel/graph2/module.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PureComponent } from 'react';
import { PanelProps } from 'app/features/dashboard/dashgrid/DataPanel';

export class ReactTestPanel extends PureComponent<PanelProps> {
export class Graph2 extends PureComponent<PanelProps> {
constructor(props) {
super(props);
}
Expand All @@ -14,8 +14,14 @@ export class ReactTestPanel extends PureComponent<PanelProps> {
value = data[0].value;
}

return <h2>Graph Panel! {value}</h2>;
return <h2>Text Panel {value}</h2>;
}
}

export { ReactTestPanel as PanelComponent };
export class TextOptions extends PureComponent<any> {
render() {
return <p>Text2 Options component</p>;
}
}

export { Graph2 as PanelComponent, TextOptions as PanelOptions };
4 changes: 2 additions & 2 deletions public/app/plugins/panel/graph2/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"url": "https://grafana.com"
},
"logos": {
"small": "img/icn-graph-panel.svg",
"large": "img/icn-graph-panel.svg"
"small": "img/icn-text-panel.svg",
"large": "img/icn-text-panel.svg"
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions public/app/plugins/panel/text2/module.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PureComponent } from 'react';
import { PanelProps } from 'app/features/dashboard/dashgrid/DataPanel';

export class ReactTestPanel extends PureComponent<PanelProps> {
export class Text2 extends PureComponent<PanelProps> {
constructor(props) {
super(props);
}
Expand All @@ -14,14 +14,8 @@ export class ReactTestPanel extends PureComponent<PanelProps> {
value = data[0].value;
}

return <h2>Text Panel {value}</h2>;
return <h2>Graph Panel! {value}</h2>;
}
}

export class TextOptions extends PureComponent<any> {
render() {
return <p>Text2 Options component</p>;
}
}

export { ReactTestPanel as PanelComponent, TextOptions as PanelOptions };
export { Text2 as PanelComponent };
8 changes: 5 additions & 3 deletions public/app/plugins/panel/text2/plugin.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"type": "panel",
"name": "Text2",
"name": "Text v2",
"id": "text2",

"state": "alpha",

"info": {
"author": {
"name": "Grafana Project",
"url": "https://grafana.com"
},
"logos": {
"small": "img/icn-text-panel.svg",
"large": "img/icn-text-panel.svg"
"small": "img/icn-graph-panel.svg",
"large": "img/icn-graph-panel.svg"
}
}
}
Expand Down

0 comments on commit 565edc1

Please sign in to comment.