@@ -80,9 +80,50 @@ func RunsForProject(c *gin.Context) {
80
80
}
81
81
82
82
func RunDetails (c * gin.Context ) {
83
- // currentOrg, exists := c.Get(middleware.ORGANISATION_ID_KEY)
84
- //projectIdStr := c.Param("project_id ")
83
+ currentOrg , exists := c .Get (middleware .ORGANISATION_ID_KEY )
84
+ runIdStr := c .Param ("run_id " )
85
85
86
- response := make (map [string ]interface {})
86
+ if runIdStr == "" {
87
+ c .String (http .StatusBadRequest , "RunID not specified" )
88
+ return
89
+ }
90
+
91
+ runId , err := strconv .Atoi (runIdStr )
92
+ if err != nil {
93
+ c .String (http .StatusBadRequest , "Invalid RunId" )
94
+ return
95
+ }
96
+
97
+ if ! exists {
98
+ c .String (http .StatusForbidden , "Not allowed to access this resource" )
99
+ return
100
+ }
101
+
102
+ var org models.Organisation
103
+ err = models .DB .GormDB .Where ("id = ?" , currentOrg ).First (& org ).Error
104
+ if err != nil {
105
+ if errors .Is (err , gorm .ErrRecordNotFound ) {
106
+ c .String (http .StatusNotFound , fmt .Sprintf ("Could not find organisation: %v" , currentOrg ))
107
+ } else {
108
+ c .String (http .StatusInternalServerError , "Unknown error occurred while fetching database" )
109
+ }
110
+ return
111
+ }
112
+
113
+ run , err := models .DB .GetDiggerRun (uint (runId ))
114
+ if err != nil {
115
+ log .Printf ("Could not fetch run: %v" , err )
116
+ c .String (http .StatusBadRequest , "Could not fetch run, please check that it exists" )
117
+ }
118
+ if run .Repo .OrganisationID != org .ID {
119
+ c .String (http .StatusForbidden , "Not allowed to access this resource" )
120
+ return
121
+ }
122
+
123
+ response , err := run .MapToJsonStruct ()
124
+ if err != nil {
125
+ c .String (http .StatusInternalServerError , "Could not unmarshall data" )
126
+ return
127
+ }
87
128
c .JSON (http .StatusOK , response )
88
129
}
0 commit comments