@@ -17,6 +17,31 @@ async function baseFilter(session: Session) {
17
17
if ( ! session ?. userId ) return false ;
18
18
if ( session . permissions . viewAllPublicCloudProducts ) return true ;
19
19
20
+ const filter : Prisma . PublicCloudRequestWhereInput = {
21
+ OR : [
22
+ {
23
+ type : RequestType . CREATE ,
24
+ createdById : session . user . id ,
25
+ } ,
26
+ {
27
+ type : RequestType . CREATE ,
28
+ decisionData : { projectOwnerId : session . user . id } ,
29
+ } ,
30
+ {
31
+ type : RequestType . CREATE ,
32
+ decisionData : { primaryTechnicalLeadId : session . user . id } ,
33
+ } ,
34
+ {
35
+ type : RequestType . CREATE ,
36
+ decisionData : { secondaryTechnicalLeadId : session . user . id } ,
37
+ } ,
38
+ {
39
+ type : RequestType . CREATE ,
40
+ decisionData : { expenseAuthorityId : session . user . id } ,
41
+ } ,
42
+ ] ,
43
+ } ;
44
+
20
45
const { data : products } = await publicCloudProductModel . list ( { select : { licencePlate : true } } , session ) ;
21
46
const licencePlates = products . map ( ( { licencePlate } ) => licencePlate ) ;
22
47
@@ -51,36 +76,20 @@ async function baseFilter(session: Session) {
51
76
52
77
const licencePlatesAsEa = billingRecords . map ( ( b ) => b . licencePlate ) ;
53
78
54
- const filter : Prisma . PublicCloudRequestWhereInput = {
55
- OR : [
56
- {
57
- licencePlate : {
58
- in : getUniqueNonFalsyItems ( [ ...licencePlates , ...licencePlatesFromTasks , ...licencePlatesAsEa ] ) ,
59
- } ,
60
- } ,
61
- { id : { in : getUniqueNonFalsyItems ( [ ...requestIdsFromTasks ] ) } } ,
62
- {
63
- type : RequestType . CREATE ,
64
- createdById : { equals : session . user . id , mode : 'insensitive' } ,
65
- } ,
66
- {
67
- type : RequestType . CREATE ,
68
- decisionData : { projectOwnerId : session . user . id } ,
69
- } ,
70
- {
71
- type : RequestType . CREATE ,
72
- decisionData : { primaryTechnicalLeadId : session . user . id } ,
73
- } ,
74
- {
75
- type : RequestType . CREATE ,
76
- decisionData : { secondaryTechnicalLeadId : session . user . id } ,
77
- } ,
78
- {
79
- type : RequestType . CREATE ,
80
- decisionData : { expenseAuthorityId : session . user . id } ,
81
- } ,
82
- ] ,
83
- } ;
79
+ const allowedLicencePlates = getUniqueNonFalsyItems ( [
80
+ ...licencePlates ,
81
+ ...licencePlatesFromTasks ,
82
+ ...licencePlatesAsEa ,
83
+ ] ) ;
84
+
85
+ if ( allowedLicencePlates . length > 0 ) {
86
+ filter . OR ?. push ( { licencePlate : { in : allowedLicencePlates } } ) ;
87
+ }
88
+
89
+ const allowedIds = getUniqueNonFalsyItems ( [ ...requestIdsFromTasks ] ) ;
90
+ if ( allowedIds . length > 0 ) {
91
+ filter . OR ?. push ( { id : { in : allowedIds } } ) ;
92
+ }
84
93
85
94
return filter ;
86
95
}
0 commit comments