23
23
import java .util .List ;
24
24
import java .util .UUID ;
25
25
26
- import static org .gridsuite .directory .server .DirectoryException .Type .NOT_ALLOWED ;
27
-
28
26
/**
29
27
* @author Nicolas Noir <nicolas.noir at rte-france.com>
30
28
* @author Slimane Amar <slimane.amar at rte-france.com>
@@ -91,14 +89,8 @@ public ResponseEntity<Void> createElementInDirectoryPath(@RequestParam("director
91
89
@ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "List info of an element and its parents in order to get its path" ),
92
90
@ ApiResponse (responseCode = "403" , description = "Access forbidden for the element" ),
93
91
@ ApiResponse (responseCode = "404" , description = "The searched element was not found" )})
94
- public ResponseEntity <List <ElementAttributes >> getPath (@ PathVariable ("elementUuid" ) UUID elementUuid ,
95
- @ RequestHeader ("userId" ) String userId ) {
96
-
97
- List <ElementAttributes > path = service .getPath (elementUuid );
98
- if (!service .isPathAccessible (userId , path )) {
99
- throw new DirectoryException (NOT_ALLOWED );
100
- }
101
- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (path );
92
+ public ResponseEntity <List <ElementAttributes >> getPath (@ PathVariable ("elementUuid" ) UUID elementUuid ) {
93
+ return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (service .getPath (elementUuid ));
102
94
}
103
95
104
96
@ DeleteMapping (value = "/elements/{elementUuid}" )
@@ -178,12 +170,13 @@ public ResponseEntity<List<ElementAttributes>> getElements(@RequestParam("ids")
178
170
@ ApiResponses (value = {
179
171
@ ApiResponse (responseCode = "200" , description = "All elements are accessible" ),
180
172
@ ApiResponse (responseCode = "404" , description = "At least one element was not found" ),
181
- @ ApiResponse (responseCode = "403 " , description = "Access forbidden for at least one element" )
173
+ @ ApiResponse (responseCode = "204 " , description = "Access forbidden for at least one element" )
182
174
})
183
175
public ResponseEntity <Void > areElementsAccessible (@ RequestParam ("ids" ) List <UUID > elementUuids ,
184
- @ RequestHeader ("userId" ) String userId ) {
185
- service .areElementsAccessible (userId , elementUuids );
186
- return ResponseEntity .ok ().build ();
176
+ @ RequestParam (value = "forDeletion" , required = false , defaultValue = "false" ) Boolean forDeletion ,
177
+ @ RequestHeader ("userId" ) String userId ) {
178
+ boolean result = Boolean .TRUE .equals (forDeletion ) ? service .areDirectoryElementsDeletable (elementUuids , userId ) : service .areDirectoryElementsAccessible (elementUuids , userId );
179
+ return result ? ResponseEntity .ok ().build () : ResponseEntity .noContent ().build ();
187
180
}
188
181
189
182
@ PutMapping (value = "/elements/{elementUuid}" , consumes = MediaType .APPLICATION_JSON_VALUE )
@@ -207,11 +200,11 @@ public ResponseEntity<Void> updateElement(@PathVariable("elementUuid") UUID elem
207
200
@ ApiResponse (responseCode = "404" , description = "The elements or the targeted directory was not found" ),
208
201
@ ApiResponse (responseCode = "403" , description = "Not authorized execute this update" )
209
202
})
210
- public ResponseEntity <Void > updateElementsDirectory (
203
+ public ResponseEntity <Void > moveElementsDirectory (
211
204
@ RequestParam UUID targetDirectoryUuid ,
212
205
@ RequestBody List <UUID > elementsUuids ,
213
206
@ RequestHeader ("userId" ) String userId ) {
214
- service .updateElementsDirectory (elementsUuids , targetDirectoryUuid , userId );
207
+ service .moveElementsDirectory (elementsUuids , targetDirectoryUuid , userId );
215
208
return ResponseEntity .ok ().build ();
216
209
}
217
210
@@ -262,9 +255,8 @@ public ResponseEntity<Void> reindexAllElements() {
262
255
@ Operation (summary = "Search elements in elasticsearch" )
263
256
@ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "List of elements found" )})
264
257
public ResponseEntity <List <DirectoryElementInfos >> searchElements (
265
- @ Parameter (description = "User input" ) @ RequestParam (value = "userInput" ) String userInput ,
266
- @ RequestHeader ("userId" ) String userId ) {
258
+ @ Parameter (description = "User input" ) @ RequestParam (value = "userInput" ) String userInput ) {
267
259
return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON )
268
- .body (service .searchElements (userInput , userId ));
260
+ .body (service .searchElements (userInput ));
269
261
}
270
262
}
0 commit comments