@@ -703,10 +703,10 @@ func (hs *HTTPServer) GetDashboardVersions(c *models.ReqContext) response.Respon
703
703
// 500: internalServerError
704
704
func (hs * HTTPServer ) GetDashboardVersion (c * models.ReqContext ) response.Response {
705
705
var dashID int64
706
-
707
706
var err error
708
- dashUID := web . Params ( c . Req )[ ":uid" ]
707
+ var dash * models. Dashboard
709
708
709
+ dashUID := web .Params (c .Req )[":uid" ]
710
710
if dashUID == "" {
711
711
dashID , err = strconv .ParseInt (web .Params (c .Req )[":dashboardId" ], 10 , 64 )
712
712
if err != nil {
@@ -721,12 +721,20 @@ func (hs *HTTPServer) GetDashboardVersion(c *models.ReqContext) response.Respons
721
721
return response .Error (http .StatusBadRequest , "failed to get dashboard by UID" , err )
722
722
}
723
723
dashID = q .Result .Id
724
+ dash = q .Result
724
725
}
725
726
726
727
guardian := guardian .New (c .Req .Context (), dashID , c .OrgID , c .SignedInUser )
727
- if canSave , err := guardian .CanSave (); err != nil || ! canSave {
728
+ canSave := true
729
+ if canSave , err = guardian .CanSave (); err != nil || ! canSave {
728
730
return dashboardGuardianResponse (err )
729
731
}
732
+ if canView , err := guardian .CanView (); err != nil || ! canView {
733
+ return dashboardGuardianResponse (err )
734
+ }
735
+ canEdit , _ := guardian .CanEdit ()
736
+ canAdmin , _ := guardian .CanAdmin ()
737
+ canDelete , _ := guardian .CanDelete ()
730
738
731
739
version , _ := strconv .ParseInt (web .Params (c .Req )[":id" ], 10 , 32 )
732
740
query := dashver.GetDashboardVersionQuery {
@@ -745,10 +753,61 @@ func (hs *HTTPServer) GetDashboardVersion(c *models.ReqContext) response.Respons
745
753
creator = hs .getUserLogin (c .Req .Context (), res .CreatedBy )
746
754
}
747
755
756
+ annotationPermissions := & dtos.AnnotationPermission {}
757
+ if ! hs .AccessControl .IsDisabled () {
758
+ hs .getAnnotationPermissionsByScope (c , & annotationPermissions .Dashboard , accesscontrol .ScopeAnnotationsTypeDashboard )
759
+ hs .getAnnotationPermissionsByScope (c , & annotationPermissions .Organization , accesscontrol .ScopeAnnotationsTypeOrganization )
760
+ }
761
+
762
+ hasPublicDashboard := false
763
+ publicDashboardEnabled := false
764
+ // If public dashboards is enabled and we have a public dashboard, update meta values
765
+ if hs .Features .IsEnabled (featuremgmt .FlagPublicDashboards ) {
766
+ publicDashboard , err := hs .PublicDashboardsApi .PublicDashboardService .FindByDashboardUid (c .Req .Context (), c .OrgID , dash .Uid )
767
+ if err != nil && ! errors .Is (err , publicdashboardModels .ErrPublicDashboardNotFound ) {
768
+ return response .Error (500 , "Error while retrieving public dashboards" , err )
769
+ }
770
+ if publicDashboard != nil {
771
+ hasPublicDashboard = true
772
+ publicDashboardEnabled = publicDashboard .IsEnabled
773
+ }
774
+ }
775
+
748
776
meta := dtos.DashboardMeta {
749
- Type : models .DashTypeDB ,
750
- CreatedBy : creator ,
751
- Version : res .Version ,
777
+ Slug : dash .Slug ,
778
+ Type : models .DashTypeDB ,
779
+ CanStar : c .IsSignedIn ,
780
+ CanSave : canSave ,
781
+ CanEdit : canEdit ,
782
+ CanAdmin : canAdmin ,
783
+ CanDelete : canDelete ,
784
+ Created : dash .Created ,
785
+ Updated : dash .Updated ,
786
+ UpdatedBy : "Someone" ,
787
+ CreatedBy : creator ,
788
+ Version : dash .Version ,
789
+ HasACL : dash .HasACL ,
790
+ IsFolder : dash .IsFolder ,
791
+ FolderId : dash .FolderId ,
792
+ Url : dash .GetUrl (),
793
+ FolderTitle : "General" ,
794
+ AnnotationsPermissions : annotationPermissions ,
795
+ PublicDashboardEnabled : publicDashboardEnabled ,
796
+ HasPublicDashboard : hasPublicDashboard ,
797
+ }
798
+
799
+ // lookup folder title
800
+ if dash .FolderId > 0 {
801
+ query := models.GetDashboardQuery {Id : dash .FolderId , OrgId : c .OrgID }
802
+ if err := hs .DashboardService .GetDashboard (c .Req .Context (), & query ); err != nil {
803
+ if errors .Is (err , dashboards .ErrFolderNotFound ) {
804
+ return response .Error (404 , "Folder not found" , err )
805
+ }
806
+ return response .Error (500 , "Dashboard folder could not be read" , err )
807
+ }
808
+ meta .FolderUid = query .Result .Uid
809
+ meta .FolderTitle = query .Result .Title
810
+ meta .FolderUrl = query .Result .GetUrl ()
752
811
}
753
812
754
813
dto := dtos.DashboardFullWithMeta {
0 commit comments