mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
Require guardian.New to take context.Context as first argument. Migrates the GetDashboardAclInfoListQuery to be dispatched using context. Ref #36734 Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> Co-authored-by: sam boyer <sam.boyer@grafana.com>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package dashboards
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
func (dr *dashboardServiceImpl) MakeUserAdmin(ctx context.Context, orgID int64, userID int64, dashboardID int64, setViewAndEditPermissions bool) error {
|
|
rtEditor := models.ROLE_EDITOR
|
|
rtViewer := models.ROLE_VIEWER
|
|
|
|
items := []*models.DashboardAcl{
|
|
{
|
|
OrgID: orgID,
|
|
DashboardID: dashboardID,
|
|
UserID: userID,
|
|
Permission: models.PERMISSION_ADMIN,
|
|
Created: time.Now(),
|
|
Updated: time.Now(),
|
|
},
|
|
}
|
|
|
|
if setViewAndEditPermissions {
|
|
items = append(items,
|
|
&models.DashboardAcl{
|
|
OrgID: orgID,
|
|
DashboardID: dashboardID,
|
|
Role: &rtEditor,
|
|
Permission: models.PERMISSION_EDIT,
|
|
Created: time.Now(),
|
|
Updated: time.Now(),
|
|
},
|
|
&models.DashboardAcl{
|
|
OrgID: orgID,
|
|
DashboardID: dashboardID,
|
|
Role: &rtViewer,
|
|
Permission: models.PERMISSION_VIEW,
|
|
Created: time.Now(),
|
|
Updated: time.Now(),
|
|
},
|
|
)
|
|
}
|
|
|
|
if err := dr.dashboardStore.UpdateDashboardACLCtx(ctx, dashboardID, items); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|