public dashboards: finalize db schema & v1 feature complete (#50467)

This PR completes public dashboards v1 functionality and simplifies public dashboard conventions. It exists as a large PR so that we are not making constant changes to the database schema.

models.PublicDashboardConfig model replaced with models.PublicDashboard directly
dashboard_public_config table renamed to dashboard_public
models.Dashboard.IsPublic removed from the dashboard and replaced with models.PublicDashboard.isEnabled
Routing now uses a uuid v4 as an access token for viewing a public dashboard anonymously, PublicDashboard.Uid only used as database identifier
Frontend utilizes uuid for auth'd operations and access token for anonymous access
Default to time range defined on dashboard when viewing public dashboard
Add audit fields to public dashboard

Co-authored-by: Owen Smallwood <owen.smallwood@grafana.com>, Ezequiel Victorero <ezequiel.victorero@grafana.com>, Jesse Weaver <jesse.weaver@grafana.com>
This commit is contained in:
Jeff Levin
2022-06-22 13:58:52 -08:00
committed by GitHub
co-authored by Owen Smallwood <owen.smallwood@grafana.com>, Ezequiel Victorero <ezequiel.victorero@grafana.com>, Jesse Weaver
parent 773c269084
commit d076bedb5e
37 changed files with 1308 additions and 627 deletions
@@ -1,33 +0,0 @@
package migrations
import (
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
)
func addPublicDashboardMigration(mg *Migrator) {
var dashboardPublicCfgV1 = Table{
Name: "dashboard_public_config",
Columns: []*Column{
{Name: "uid", Type: DB_NVarchar, Length: 40, IsPrimaryKey: true},
{Name: "dashboard_uid", Type: DB_NVarchar, Length: 40, Nullable: false},
{Name: "org_id", Type: DB_BigInt, Nullable: false},
{Name: "time_settings", Type: DB_Text, Nullable: false},
{Name: "refresh_rate", Type: DB_Int, Nullable: false, Default: "30"},
{Name: "template_variables", Type: DB_MediumText, Nullable: true},
},
Indices: []*Index{
{Cols: []string{"uid"}, Type: UniqueIndex},
{Cols: []string{"org_id", "dashboard_uid"}},
},
}
mg.AddMigration("create dashboard public config v1", NewAddTableMigration(dashboardPublicCfgV1))
// table has no dependencies and was created with incorrect pkey type.
// drop then recreate with correct values
addDropAllIndicesMigrations(mg, "v1", dashboardPublicCfgV1)
mg.AddMigration("Drop old dashboard public config table", NewDropTableMigration("dashboard_public_config"))
// recreate table with proper primary key type
mg.AddMigration("recreate dashboard public config v1", NewAddTableMigration(dashboardPublicCfgV1))
addTableIndicesMigrations(mg, "v1", dashboardPublicCfgV1)
}
@@ -0,0 +1,52 @@
package migrations
import (
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
)
func addPublicDashboardMigration(mg *Migrator) {
var dashboardPublicCfgV1 = Table{
Name: "dashboard_public_config",
Columns: []*Column{
{Name: "uid", Type: DB_NVarchar, Length: 40, IsPrimaryKey: true},
{Name: "dashboard_uid", Type: DB_NVarchar, Length: 40, Nullable: false},
{Name: "org_id", Type: DB_BigInt, Nullable: false},
{Name: "time_settings", Type: DB_Text, Nullable: true},
{Name: "template_variables", Type: DB_MediumText, Nullable: true},
{Name: "access_token", Type: DB_NVarchar, Length: 32, Nullable: false},
{Name: "created_by", Type: DB_Int, Nullable: false},
{Name: "updated_by", Type: DB_Int, Nullable: true},
{Name: "created_at", Type: DB_DateTime, Nullable: false},
{Name: "updated_at", Type: DB_DateTime, Nullable: true},
{Name: "is_enabled", Type: DB_Bool, Nullable: false, Default: "0"},
},
Indices: []*Index{
{Cols: []string{"uid"}, Type: UniqueIndex},
{Cols: []string{"org_id", "dashboard_uid"}},
{Cols: []string{"access_token"}, Type: UniqueIndex},
},
}
// initial create table
mg.AddMigration("create dashboard public config v1", NewAddTableMigration(dashboardPublicCfgV1))
// recreate table - no dependencies and was created with incorrect pkey type
addDropAllIndicesMigrations(mg, "v1", dashboardPublicCfgV1)
mg.AddMigration("Drop old dashboard public config table", NewDropTableMigration("dashboard_public_config"))
mg.AddMigration("recreate dashboard public config v1", NewAddTableMigration(dashboardPublicCfgV1))
addTableIndicesMigrations(mg, "v1", dashboardPublicCfgV1)
// recreate table - schema finalized for public dashboards v1
addDropAllIndicesMigrations(mg, "v2", dashboardPublicCfgV1)
mg.AddMigration("Drop public config table", NewDropTableMigration("dashboard_public_config"))
mg.AddMigration("Recreate dashboard public config v2", NewAddTableMigration(dashboardPublicCfgV1))
addTableIndicesMigrations(mg, "v2", dashboardPublicCfgV1)
// rename table
addTableRenameMigration(mg, "dashboard_public_config", "dashboard_public", "v2")
}