mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Guardian: Introduce additional constructors (#59577)
* Guardian: Use dashboard UID instead of ID * Apply suggestions from code review Introduce several guardian constructors and each time use the most appropriate one.
This commit is contained in:
committed by
GitHub
parent
6478d0a5ef
commit
11d8bcbea9
@@ -73,7 +73,10 @@ func (h *DashboardHandler) OnSubscribe(ctx context.Context, user *user.SignedInU
|
||||
}
|
||||
|
||||
dash := query.Result
|
||||
guard := guardian.New(ctx, dash.Id, user.OrgID, user)
|
||||
guard, err := guardian.NewByDashboard(ctx, dash, user.OrgID, user)
|
||||
if err != nil {
|
||||
return models.SubscribeReply{}, backend.SubscribeStreamStatusPermissionDenied, err
|
||||
}
|
||||
if canView, err := guard.CanView(); err != nil || !canView {
|
||||
return models.SubscribeReply{}, backend.SubscribeStreamStatusPermissionDenied, nil
|
||||
}
|
||||
@@ -119,7 +122,12 @@ func (h *DashboardHandler) OnPublish(ctx context.Context, user *user.SignedInUse
|
||||
return models.PublishReply{}, backend.PublishStreamStatusNotFound, nil
|
||||
}
|
||||
|
||||
guard := guardian.New(ctx, query.Result.Id, user.OrgID, user)
|
||||
guard, err := guardian.NewByDashboard(ctx, query.Result, user.OrgID, user)
|
||||
if err != nil {
|
||||
logger.Error("Failed to create guardian", "err", err)
|
||||
return models.PublishReply{}, backend.PublishStreamStatusNotFound, fmt.Errorf("internal error")
|
||||
}
|
||||
|
||||
canEdit, err := guard.CanEdit()
|
||||
if err != nil {
|
||||
return models.PublishReply{}, backend.PublishStreamStatusNotFound, fmt.Errorf("internal error")
|
||||
|
||||
Reference in New Issue
Block a user