@@ -13,6 +13,7 @@ import (
13
13
"gorm.io/gorm"
14
14
"log"
15
15
"net/http"
16
+ "strconv"
16
17
"strings"
17
18
"time"
18
19
)
@@ -117,6 +118,54 @@ func FindProjectsForOrg(c *gin.Context) {
117
118
c .JSON (http .StatusOK , response )
118
119
}
119
120
121
+ func ProjectDetails (c * gin.Context ) {
122
+
123
+ currentOrg , exists := c .Get (middleware .ORGANISATION_ID_KEY )
124
+ projectIdStr := c .Param ("project_id" )
125
+
126
+ if projectIdStr == "" {
127
+ c .String (http .StatusBadRequest , "ProjectId not specified" )
128
+ return
129
+ }
130
+
131
+ projectId , err := strconv .Atoi (projectIdStr )
132
+ if err != nil {
133
+ c .String (http .StatusBadRequest , "Invalid ProjectId" )
134
+ return
135
+ }
136
+
137
+ if ! exists {
138
+ c .String (http .StatusForbidden , "Not allowed to access this resource" )
139
+ return
140
+ }
141
+
142
+ var org models.Organisation
143
+ err = models .DB .GormDB .Where ("id = ?" , currentOrg ).First (& org ).Error
144
+ if err != nil {
145
+ if errors .Is (err , gorm .ErrRecordNotFound ) {
146
+ c .String (http .StatusNotFound , fmt .Sprintf ("Could not find organisation: %v" , currentOrg ))
147
+ } else {
148
+ c .String (http .StatusInternalServerError , "Unknown error occurred while fetching database" )
149
+ }
150
+ return
151
+ }
152
+
153
+ project , err := models .DB .GetProject (uint (projectId ))
154
+ if err != nil {
155
+ log .Printf ("could not fetch project: %v" , err )
156
+ c .String (http .StatusInternalServerError , "Could not fetch project" )
157
+ return
158
+ }
159
+
160
+ if project .OrganisationID != org .ID {
161
+ log .Printf ("Forbidden access: not allowed to access projectID: %v logged in org: %v" , project .OrganisationID , org .ID )
162
+ c .String (http .StatusForbidden , "No access to this project" )
163
+ return
164
+ }
165
+
166
+ c .JSON (http .StatusOK , project .MapToJsonStruct ())
167
+ }
168
+
120
169
type CreateProjectRequest struct {
121
170
Name string `json:"name"`
122
171
ConfigurationYaml string `json:"configurationYaml"`
0 commit comments