@@ -9,16 +9,21 @@ import (
9
9
"strconv"
10
10
11
11
"github.com/gin-gonic/gin"
12
+ "github.com/uc-cdis/cohort-middleware/middlewares"
12
13
"github.com/uc-cdis/cohort-middleware/models"
13
14
"github.com/uc-cdis/cohort-middleware/utils"
14
15
)
15
16
16
17
type CohortDataController struct {
17
- cohortDataModel models.CohortDataI
18
+ cohortDataModel models.CohortDataI
19
+ teamProjectAuthz middlewares.TeamProjectAuthzI
18
20
}
19
21
20
- func NewCohortDataController (cohortDataModel models.CohortDataI ) CohortDataController {
21
- return CohortDataController {cohortDataModel : cohortDataModel }
22
+ func NewCohortDataController (cohortDataModel models.CohortDataI , teamProjectAuthz middlewares.TeamProjectAuthzI ) CohortDataController {
23
+ return CohortDataController {
24
+ cohortDataModel : cohortDataModel ,
25
+ teamProjectAuthz : teamProjectAuthz ,
26
+ }
22
27
}
23
28
24
29
func (u CohortDataController ) RetrieveHistogramForCohortIdAndConceptId (c * gin.Context ) {
@@ -44,6 +49,14 @@ func (u CohortDataController) RetrieveHistogramForCohortIdAndConceptId(c *gin.Co
44
49
cohortId , _ := strconv .Atoi (cohortIdStr )
45
50
histogramConceptId , _ := strconv .ParseInt (histogramIdStr , 10 , 64 )
46
51
52
+ validAccessRequest := u .teamProjectAuthz .TeamProjectValidation (c , []int {cohortId }, cohortPairs )
53
+ if ! validAccessRequest {
54
+ log .Printf ("Error: invalid request" )
55
+ c .JSON (http .StatusBadRequest , gin.H {"message" : "access denied" })
56
+ c .Abort ()
57
+ return
58
+ }
59
+
47
60
cohortData , err := u .cohortDataModel .RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs (sourceId , cohortId , histogramConceptId , filterConceptIds , cohortPairs )
48
61
if err != nil {
49
62
c .JSON (http .StatusInternalServerError , gin.H {"message" : "Error retrieving concept details" , "error" : err .Error ()})
@@ -85,6 +98,14 @@ func (u CohortDataController) RetrieveDataBySourceIdAndCohortIdAndVariables(c *g
85
98
sourceId , _ := strconv .Atoi (sourceIdStr )
86
99
cohortId , _ := strconv .Atoi (cohortIdStr )
87
100
101
+ validAccessRequest := u .teamProjectAuthz .TeamProjectValidation (c , []int {cohortId }, cohortPairs )
102
+ if ! validAccessRequest {
103
+ log .Printf ("Error: invalid request" )
104
+ c .JSON (http .StatusBadRequest , gin.H {"message" : "access denied" })
105
+ c .Abort ()
106
+ return
107
+ }
108
+
88
109
// call model method:
89
110
cohortData , err := u .cohortDataModel .RetrieveDataBySourceIdAndCohortIdAndConceptIdsOrderedByPersonId (sourceId , cohortId , conceptIds )
90
111
if err != nil {
@@ -111,7 +132,7 @@ func generateCohortPairsHeaders(cohortPairs []utils.CustomDichotomousVariableDef
111
132
cohortPairsHeaders := []string {}
112
133
113
134
for _ , cohortPair := range cohortPairs {
114
- cohortPairsHeaders = append (cohortPairsHeaders , utils .GetCohortPairKey (cohortPair .CohortId1 , cohortPair .CohortId2 ))
135
+ cohortPairsHeaders = append (cohortPairsHeaders , utils .GetCohortPairKey (cohortPair .CohortDefinitionId1 , cohortPair .CohortDefinitionId2 ))
115
136
}
116
137
117
138
return cohortPairsHeaders
@@ -230,6 +251,14 @@ func (u CohortDataController) RetrieveCohortOverlapStatsWithoutFilteringOnConcep
230
251
controlCohortId , errors [2 ] = utils .ParseNumericArg (c , "controlcohortid" )
231
252
conceptIds , cohortPairs , errors [3 ] = utils .ParseConceptIdsAndDichotomousDefs (c )
232
253
254
+ validAccessRequest := u .teamProjectAuthz .TeamProjectValidation (c , []int {caseCohortId , controlCohortId }, cohortPairs )
255
+ if ! validAccessRequest {
256
+ log .Printf ("Error: invalid request" )
257
+ c .JSON (http .StatusBadRequest , gin.H {"message" : "access denied" })
258
+ c .Abort ()
259
+ return
260
+ }
261
+
233
262
if utils .ContainsNonNil (errors ) {
234
263
c .JSON (http .StatusBadRequest , gin.H {"message" : "bad request" })
235
264
c .Abort ()
@@ -298,8 +327,8 @@ func (u CohortDataController) RetrievePeopleIdAndCohort(sourceId int, cohortId i
298
327
*/
299
328
personIdToCSVValues := make (map [int64 ]map [string ]string )
300
329
for _ , cohortPair := range cohortPairs {
301
- firstCohortDefinitionId := cohortPair .CohortId1
302
- secondCohortDefinitionId := cohortPair .CohortId2
330
+ firstCohortDefinitionId := cohortPair .CohortDefinitionId1
331
+ secondCohortDefinitionId := cohortPair .CohortDefinitionId2
303
332
cohortPairKey := utils .GetCohortPairKey (firstCohortDefinitionId , secondCohortDefinitionId )
304
333
305
334
firstCohortPeopleData , err1 := u .cohortDataModel .RetrieveDataByOriginalCohortAndNewCohort (sourceId , cohortId , firstCohortDefinitionId )
0 commit comments