2019-03-05 09:44:41 -06:00
|
|
|
package dashboards
|
|
|
|
|
|
|
|
import (
|
2021-09-14 09:08:04 -05:00
|
|
|
"context"
|
2020-06-29 07:08:32 -05:00
|
|
|
"time"
|
|
|
|
|
2019-03-05 09:44:41 -06:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
)
|
|
|
|
|
2021-09-14 09:08:04 -05:00
|
|
|
func (dr *dashboardServiceImpl) MakeUserAdmin(ctx context.Context, orgID int64, userID int64, dashboardID int64, setViewAndEditPermissions bool) error {
|
2019-03-05 09:44:41 -06:00
|
|
|
rtEditor := models.ROLE_EDITOR
|
|
|
|
rtViewer := models.ROLE_VIEWER
|
|
|
|
|
|
|
|
items := []*models.DashboardAcl{
|
|
|
|
{
|
2020-11-17 10:09:14 -06:00
|
|
|
OrgID: orgID,
|
|
|
|
DashboardID: dashboardID,
|
|
|
|
UserID: userID,
|
2019-03-05 09:44:41 -06:00
|
|
|
Permission: models.PERMISSION_ADMIN,
|
|
|
|
Created: time.Now(),
|
|
|
|
Updated: time.Now(),
|
|
|
|
},
|
2019-03-11 09:34:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if setViewAndEditPermissions {
|
|
|
|
items = append(items,
|
|
|
|
&models.DashboardAcl{
|
2020-11-17 10:09:14 -06:00
|
|
|
OrgID: orgID,
|
|
|
|
DashboardID: dashboardID,
|
2019-03-11 09:34:32 -05:00
|
|
|
Role: &rtEditor,
|
|
|
|
Permission: models.PERMISSION_EDIT,
|
|
|
|
Created: time.Now(),
|
|
|
|
Updated: time.Now(),
|
|
|
|
},
|
|
|
|
&models.DashboardAcl{
|
2020-11-17 10:09:14 -06:00
|
|
|
OrgID: orgID,
|
|
|
|
DashboardID: dashboardID,
|
2019-03-11 09:34:32 -05:00
|
|
|
Role: &rtViewer,
|
|
|
|
Permission: models.PERMISSION_VIEW,
|
|
|
|
Created: time.Now(),
|
|
|
|
Updated: time.Now(),
|
|
|
|
},
|
|
|
|
)
|
2019-03-05 09:44:41 -06:00
|
|
|
}
|
|
|
|
|
2021-09-23 10:43:32 -05:00
|
|
|
if err := dr.dashboardStore.UpdateDashboardACLCtx(ctx, dashboardID, items); err != nil {
|
2019-03-05 09:44:41 -06:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|