@@ -24,6 +24,8 @@ class SelectionRepositoryService {
24
24
25
25
static transactional = true
26
26
27
+ def currentTenant
28
+
27
29
/**
28
30
* List selections stored in the repository.
29
31
*
@@ -38,15 +40,16 @@ class SelectionRepositoryService {
38
40
* @return a list of selections matching the parameters. Each list entry is a Map with selection properties
39
41
*/
40
42
List<Map<String , Object > > list (String location , String username = null , Long tenant = null ) {
43
+ Long tenantId = currentTenant?. get() ?: tenant
41
44
SelectionRepository . createCriteria(). list([sort : ' name' , order : ' asc' ]) {
42
45
eq(' location' , location)
43
46
if (username) {
44
47
eq(' username' , username)
45
48
} else {
46
49
isNull(' username' )
47
50
}
48
- if (tenant != null ) {
49
- eq(' tenantId' , tenant )
51
+ if (tenantId != null ) {
52
+ eq(' tenantId' , tenantId )
50
53
}
51
54
}. collect {[id : it. id, name : it. name, description : it. description, uri :it. uri]}
52
55
}
@@ -62,6 +65,10 @@ class SelectionRepositoryService {
62
65
if (! s) {
63
66
throw new IllegalArgumentException (" No selection found with id [$id ]" )
64
67
}
68
+ def tenant = currentTenant?. get()
69
+ if (tenant != null && tenant != s. tenantId) {
70
+ throw new IllegalArgumentException (" No selection found with id [$id ]" )
71
+ }
65
72
s. uri
66
73
}
67
74
@@ -77,6 +84,7 @@ class SelectionRepositoryService {
77
84
* @return a selection URI suitable for retrieving/invoking the persisted selection
78
85
*/
79
86
URI put (URI selection , String location , String username , String name , String description = null , Long tenant = null ) {
87
+ Long tenantId = currentTenant?. get() ?: tenant
80
88
// Try to find persistent selection.
81
89
def s = SelectionRepository . createCriteria(). get() {
82
90
eq(' location' , location)
@@ -86,14 +94,14 @@ class SelectionRepositoryService {
86
94
} else {
87
95
isNull(' username' )
88
96
}
89
- if (tenant != null ) {
90
- eq(' tenantId' , tenant )
97
+ if (tenantId != null ) {
98
+ eq(' tenantId' , tenantId )
91
99
}
92
100
}
93
101
94
102
if (! s) {
95
103
// Create new persistent selection
96
- s = new SelectionRepository (tenantId : tenant , location : location, username : username, name : name)
104
+ s = new SelectionRepository (tenantId : tenantId , location : location, username : username, name : name)
97
105
}
98
106
99
107
// Update URI and description.
@@ -114,6 +122,10 @@ class SelectionRepositoryService {
114
122
if (! s) {
115
123
throw new IllegalArgumentException (" No selection found with id [$id ]" )
116
124
}
125
+ def tenant = currentTenant?. get()
126
+ if (tenant != null && tenant != s. tenantId) {
127
+ throw new IllegalArgumentException (" No selection found with id [$id ]" )
128
+ }
117
129
s. delete()
118
130
}
119
131
}
0 commit comments