add isPublic to dashboard (#48012)
adds toggle to make a dashboard public * config struct for public dashboard config * api endpoints for public dashboard configuration * ui for toggling public dashboard on and off * load public dashboard config on share modal Co-authored-by: Owen Smallwood <owen.smallwood@grafana.com> Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
co-authored by
Owen Smallwood
Torkel Ödegaard
parent
156e14e296
commit
c7f8c2cc73
@@ -187,6 +187,47 @@ func (d *DashboardStore) SaveDashboard(cmd models.SaveDashboardCommand) (*models
|
||||
return cmd.Result, err
|
||||
}
|
||||
|
||||
// retrieves public dashboard configuration
|
||||
func (d *DashboardStore) GetPublicDashboardConfig(orgId int64, dashboardUid string) (*models.PublicDashboardConfig, error) {
|
||||
var result []*models.Dashboard
|
||||
|
||||
err := d.sqlStore.WithTransactionalDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||
return sess.Where("org_id = ? AND uid= ?", orgId, dashboardUid).Find(&result)
|
||||
})
|
||||
|
||||
if len(result) == 0 {
|
||||
return nil, models.ErrDashboardNotFound
|
||||
}
|
||||
|
||||
pdc := &models.PublicDashboardConfig{
|
||||
IsPublic: result[0].IsPublic,
|
||||
}
|
||||
|
||||
return pdc, err
|
||||
}
|
||||
|
||||
// stores public dashboard configuration
|
||||
func (d *DashboardStore) SavePublicDashboardConfig(cmd models.SavePublicDashboardConfigCommand) (*models.PublicDashboardConfig, error) {
|
||||
err := d.sqlStore.WithTransactionalDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||
affectedRowCount, err := sess.Table("dashboard").Where("org_id = ? AND uid = ?", cmd.OrgId, cmd.Uid).Update(map[string]interface{}{"is_public": cmd.PublicDashboardConfig.IsPublic})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if affectedRowCount == 0 {
|
||||
return models.ErrDashboardNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &cmd.PublicDashboardConfig, nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) UpdateDashboardACL(ctx context.Context, dashboardID int64, items []*models.DashboardAcl) error {
|
||||
return d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
// delete existing items
|
||||
|
||||
Reference in New Issue
Block a user