Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IA2
GMS
Commits
5c13e18b
Commit
5c13e18b
authored
Mar 17, 2021
by
Sonia Zorba
Browse files
Added optional recursive parameter to list groups endpoint
parent
d8a9c640
Changes
4
Hide whitespace changes
Inline
Side-by-side
gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/GmsClient.java
View file @
5c13e18b
...
...
@@ -98,8 +98,8 @@ public class GmsClient extends BaseClient {
}).
orElse
(
super
.
getInvalidStatusCodeExceptionMessage
(
request
,
response
));
}
public
List
<
String
>
listGroups
(
String
prefix
)
{
return
new
ListGroupsCall
(
this
).
listGroups
(
prefix
);
public
List
<
String
>
listGroups
(
String
prefix
,
boolean
recursive
)
{
return
new
ListGroupsCall
(
this
).
listGroups
(
prefix
,
recursive
);
}
public
List
<
String
>
getUserGroups
(
String
userId
)
{
...
...
gms-client/gms-client/src/main/java/it/inaf/ia2/gms/client/call/ListGroupsCall.java
View file @
5c13e18b
...
...
@@ -19,14 +19,15 @@ public class ListGroupsCall extends BaseCall<GmsClient> {
* the privileges to see that information). The prefix is removed by the
* service.
*/
public
List
<
String
>
listGroups
(
String
prefix
)
{
public
List
<
String
>
listGroups
(
String
prefix
,
boolean
recursive
)
{
List
<
String
>
groups
=
new
ArrayList
<>();
String
uri
=
"
ws/jwt/
list"
;
String
uri
=
"list"
;
if
(
prefix
!=
null
&&
!
prefix
.
isBlank
())
{
uri
+=
"/"
+
prefix
;
}
uri
+=
"?recursive="
+
recursive
;
HttpRequest
groupsRequest
=
client
.
newRequest
(
uri
)
.
header
(
"Accept"
,
"text/plain"
)
...
...
gms-client/gms-client/src/test/java/it/inaf/ia2/gms/client/call/GetUserGroupsTest.java
View file @
5c13e18b
...
...
@@ -50,9 +50,9 @@ public class GetUserGroupsTest extends BaseGmsClientTest {
CompletableFuture
response
=
CompletableFuture
.
completedFuture
(
getMockedStreamResponse
(
200
,
body
));
when
(
httpClient
.
sendAsync
(
any
(),
any
())).
thenReturn
(
response
);
List
<
String
>
groups
=
gmsClient
.
listGroups
(
"LBT."
);
List
<
String
>
groups
=
gmsClient
.
listGroups
(
"LBT."
,
false
);
verify
(
httpClient
,
times
(
1
)).
sendAsync
(
endpointEq
(
"GET"
,
"
ws/jwt/
list/LBT."
),
any
());
verify
(
httpClient
,
times
(
1
)).
sendAsync
(
endpointEq
(
"GET"
,
"list/LBT.
?recursive=false
"
),
any
());
assertEquals
(
2
,
groups
.
size
());
assertEquals
(
"INAF"
,
groups
.
get
(
0
));
...
...
gms/src/main/java/it/inaf/ia2/gms/controller/JWTWebServiceController.java
View file @
5c13e18b
...
...
@@ -136,14 +136,21 @@ public class JWTWebServiceController {
// else: empty response (as defined by GMS standard)
}
@GetMapping
(
value
=
{
"/ws/jwt/list/{group:.+}"
,
"/ws/jwt/list"
},
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
public
void
listGroups
(
@PathVariable
(
"group"
)
Optional
<
String
>
groupNames
,
Principal
principal
,
HttpServletResponse
response
)
throws
IOException
{
@GetMapping
(
value
=
{
"/ws/jwt/list/{group:.+}"
,
"/ws/jwt/list"
,
"/list"
},
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
public
void
listGroups
(
@PathVariable
(
"group"
)
Optional
<
String
>
groupNames
,
@RequestParam
(
value
=
"recursive"
,
defaultValue
=
"false"
)
boolean
recursive
,
Principal
principal
,
HttpServletResponse
response
)
throws
IOException
{
String
userId
=
principal
.
getName
();
GroupEntity
parentGroup
=
groupNameService
.
getGroupFromNames
(
groupNames
);
List
<
GroupEntity
>
allSubGroups
=
groupsDAO
.
getDirectSubGroups
(
parentGroup
.
getPath
());
List
<
GroupEntity
>
allSubGroups
;
if
(
recursive
)
{
allSubGroups
=
groupsDAO
.
getAllChildren
(
parentGroup
.
getPath
());
}
else
{
allSubGroups
=
groupsDAO
.
getDirectSubGroups
(
parentGroup
.
getPath
());
}
// Select only the groups visible to the user
List
<
PermissionEntity
>
permissions
=
permissionsDAO
.
findUserPermissions
(
userId
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment