Skip to content
GitLab
Explore
Sign in
IA2
GMS
Compare revisions
846f98737fd31938ef020c9c360486cc38bb9de6 to cdc85827792efeb827b0677229dc5603a5734040
Hide whitespace changes
Inline
Side-by-side
gms/src/main/java/it/inaf/ia2/gms/persistence/model/ClientEntity.java
deleted
100644 → 0
View file @
846f9873
package
it.inaf.ia2.gms.persistence.model
;
import
java.util.List
;
public
class
ClientEntity
{
private
String
id
;
private
String
secret
;
private
List
<
String
>
allowedActions
;
private
String
ipFilter
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getSecret
()
{
return
secret
;
}
public
void
setSecret
(
String
secret
)
{
this
.
secret
=
secret
;
}
public
List
<
String
>
getAllowedActions
()
{
return
allowedActions
;
}
public
void
setAllowedActions
(
List
<
String
>
allowedActions
)
{
this
.
allowedActions
=
allowedActions
;
}
public
String
getIpFilter
()
{
return
ipFilter
;
}
public
void
setIpFilter
(
String
ipFilter
)
{
this
.
ipFilter
=
ipFilter
;
}
}
gms/src/main/java/it/inaf/ia2/gms/persistence/model/GroupEntity.java
View file @
cdc85827
package
it.inaf.ia2.gms.persistence.model
;
import
java.util.Date
;
import
java.util.Objects
;
public
class
GroupEntity
{
...
...
@@ -9,6 +10,8 @@ public class GroupEntity {
private
String
path
;
private
boolean
leaf
;
private
boolean
locked
;
private
Date
creationTime
;
private
String
createdBy
;
public
String
getId
()
{
return
id
;
...
...
@@ -50,6 +53,22 @@ public class GroupEntity {
this
.
locked
=
locked
;
}
public
Date
getCreationTime
()
{
return
creationTime
;
}
public
void
setCreationTime
(
Date
creationTime
)
{
this
.
creationTime
=
creationTime
;
}
public
String
getCreatedBy
()
{
return
createdBy
;
}
public
void
setCreatedBy
(
String
createdBy
)
{
this
.
createdBy
=
createdBy
;
}
public
String
getParentPath
()
{
if
(
path
.
isEmpty
())
{
return
null
;
...
...
gms/src/main/java/it/inaf/ia2/gms/persistence/model/MembershipEntity.java
View file @
cdc85827
package
it.inaf.ia2.gms.persistence.model
;
import
java.util.Date
;
import
java.util.Objects
;
import
javax.validation.constraints.NotEmpty
;
...
...
@@ -9,6 +10,8 @@ public class MembershipEntity {
private
String
groupId
;
@NotEmpty
private
String
userId
;
private
Date
creationTime
;
private
String
createdBy
;
public
String
getGroupId
()
{
return
groupId
;
...
...
@@ -26,6 +29,22 @@ public class MembershipEntity {
this
.
userId
=
userId
;
}
public
Date
getCreationTime
()
{
return
creationTime
;
}
public
void
setCreationTime
(
Date
creationTime
)
{
this
.
creationTime
=
creationTime
;
}
public
String
getCreatedBy
()
{
return
createdBy
;
}
public
void
setCreatedBy
(
String
createdBy
)
{
this
.
createdBy
=
createdBy
;
}
@Override
public
int
hashCode
()
{
int
hash
=
5
;
...
...
gms/src/main/java/it/inaf/ia2/gms/persistence/model/PermissionEntity.java
View file @
cdc85827
package
it.inaf.ia2.gms.persistence.model
;
import
it.inaf.ia2.gms.model.Permission
;
import
java.util.Date
;
import
java.util.Objects
;
import
javax.validation.constraints.NotEmpty
;
import
javax.validation.constraints.NotNull
;
...
...
@@ -13,6 +14,8 @@ public class PermissionEntity {
private
String
groupId
;
@NotNull
private
Permission
permission
;
private
Date
updateTime
;
private
String
setBy
;
// The group path is copied here for performance reasons
private
String
groupPath
;
...
...
@@ -49,6 +52,22 @@ public class PermissionEntity {
this
.
groupPath
=
groupPath
;
}
public
Date
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
Date
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
public
String
getSetBy
()
{
return
setBy
;
}
public
void
setSetBy
(
String
setBy
)
{
this
.
setBy
=
setBy
;
}
@Override
public
int
hashCode
()
{
int
hash
=
5
;
...
...
gms/src/main/java/it/inaf/ia2/gms/service/GroupNameService.java
View file @
cdc85827
...
...
@@ -85,8 +85,13 @@ public class GroupNameService {
}
public
String
getShortGroupName
(
String
completeGroupName
,
Optional
<
String
>
groupPrefix
)
{
if
(
groupPrefix
.
isPresent
())
{
return
completeGroupName
.
substring
(
groupPrefix
.
get
().
length
()
+
1
);
if
(
groupPrefix
.
isPresent
()
&&
!
groupPrefix
.
get
().
isBlank
())
{
if
(
groupPrefix
.
get
().
endsWith
(
"."
))
{
// this branch is kept for retro-compatibility with old API, it will be removed in the future
return
completeGroupName
.
substring
(
groupPrefix
.
get
().
length
());
}
else
{
return
completeGroupName
.
substring
(
groupPrefix
.
get
().
length
()
+
1
);
}
}
return
completeGroupName
;
}
...
...
@@ -144,7 +149,7 @@ public class GroupNameService {
currentName
+=
c
;
}
}
names
.
add
(
currentName
);
names
.
add
(
currentName
.
replace
(
"\\."
,
"."
)
);
return
names
;
}
...
...
gms/src/main/java/it/inaf/ia2/gms/service/GroupsService.java
View file @
cdc85827
...
...
@@ -10,7 +10,9 @@ import it.inaf.ia2.gms.persistence.InvitedRegistrationDAO;
import
it.inaf.ia2.gms.persistence.LoggingDAO
;
import
it.inaf.ia2.gms.persistence.MembershipsDAO
;
import
it.inaf.ia2.gms.persistence.PermissionsDAO
;
import
static
it
.
inaf
.
ia2
.
gms
.
persistence
.
model
.
ActionType
.*;
import
it.inaf.ia2.gms.persistence.model.GroupEntity
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.UUID
;
...
...
@@ -49,7 +51,7 @@ public class GroupsService {
}
}
public
GroupEntity
addGroup
(
GroupEntity
parent
,
String
groupName
,
boolean
leaf
)
{
public
GroupEntity
addGroup
(
GroupEntity
parent
,
String
groupName
,
boolean
leaf
,
String
createdBy
)
{
if
(
groupsDAO
.
getDirectSubGroups
(
parent
.
getPath
()).
stream
()
.
anyMatch
(
g
->
g
.
getName
().
equals
(
groupName
)))
{
...
...
@@ -69,9 +71,11 @@ public class GroupsService {
group
.
setName
(
groupName
);
group
.
setPath
(
path
);
group
.
setLeaf
(
leaf
);
group
.
setCreatedBy
(
createdBy
);
group
.
setCreationTime
(
new
Date
());
groupsDAO
.
createGroup
(
group
);
loggingDAO
.
logAction
(
"Added group: parent_path="
+
parent
.
getPath
()
+
", group_name="
+
groupName
);
loggingDAO
.
logAction
(
GROUP_CREATED
,
"Added group: parent_path="
+
parent
.
getPath
()
+
", group_name="
+
groupName
);
return
group
;
}
...
...
@@ -87,7 +91,7 @@ public class GroupsService {
group
.
setLeaf
(
leaf
);
GroupEntity
entity
=
groupsDAO
.
updateGroup
(
group
);
loggingDAO
.
logAction
(
"Group updated, group_id="
+
group
.
getId
()
loggingDAO
.
logAction
(
GROUP_UPDATED
,
"Group updated, group_id="
+
group
.
getId
()
+
", new name: "
+
newGroupName
+
", leaf: "
+
leaf
);
return
entity
;
...
...
@@ -121,7 +125,7 @@ public class GroupsService {
groupsDAO
.
deleteGroup
(
g
);
}
loggingDAO
.
logAction
(
"Group deleted [group_id="
+
group
.
getId
()
+
", group_name="
+
group
.
getName
()
+
"]"
);
loggingDAO
.
logAction
(
GROUP_DELETED
,
"Group deleted [group_id="
+
group
.
getId
()
+
", group_name="
+
group
.
getName
()
+
"]"
);
return
parent
;
}
...
...
@@ -181,4 +185,12 @@ public class GroupsService {
public
List
<
GroupEntity
>
searchGroups
(
String
searchText
)
{
return
groupsDAO
.
searchGroups
(
searchText
);
}
public
List
<
GroupEntity
>
getChildGroups
(
GroupEntity
parentGroup
,
boolean
recursive
)
{
if
(
recursive
)
{
return
groupsDAO
.
getAllChildren
(
parentGroup
.
getPath
());
}
else
{
return
groupsDAO
.
getDirectSubGroups
(
parentGroup
.
getPath
());
}
}
}
gms/src/main/java/it/inaf/ia2/gms/service/GroupsTreeBuilder.java
View file @
cdc85827
...
...
@@ -62,6 +62,8 @@ public class GroupsTreeBuilder {
node
.
setLeaf
(
group
.
isLeaf
());
node
.
setLocked
(
group
.
isLocked
());
node
.
setPermission
(
permission
);
node
.
setCreatedBy
(
group
.
getCreatedBy
());
node
.
setCreationTime
(
group
.
getCreationTime
());
nodes
.
add
(
node
);
});
}
...
...
gms/src/main/java/it/inaf/ia2/gms/service/JoinService.java
View file @
cdc85827
...
...
@@ -2,10 +2,15 @@ package it.inaf.ia2.gms.service;
import
it.inaf.ia2.gms.model.Permission
;
import
it.inaf.ia2.gms.persistence.JoinDAO
;
import
it.inaf.ia2.gms.persistence.LoggingDAO
;
import
it.inaf.ia2.gms.persistence.MembershipsDAO
;
import
it.inaf.ia2.gms.persistence.PermissionsDAO
;
import
it.inaf.ia2.gms.persistence.model.ActionType
;
import
it.inaf.ia2.gms.persistence.model.GroupEntity
;
import
it.inaf.ia2.gms.persistence.model.MembershipEntity
;
import
it.inaf.ia2.gms.persistence.model.PermissionEntity
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -23,33 +28,59 @@ public class JoinService {
@Autowired
private
JoinDAO
joinDAO
;
public
void
join
(
String
userId1
,
String
userId2
)
{
@Autowired
private
LoggingDAO
loggingDAO
;
Set
<
MembershipEntity
>
existingMemberships
=
membershipsDAO
.
getUserMemberships
(
userId1
).
stream
()
.
map
(
g
->
getMembershipEntity
(
g
.
getId
(),
userId1
))
.
collect
(
Collectors
.
toSet
());
public
String
join
(
String
userId1
,
String
userId2
)
{
Set
<
MembershipEntity
>
membershipsToAdd
=
membershipsDAO
.
getUserMemberships
(
userId2
).
stream
()
.
map
(
g
->
getMembershipEntity
(
g
.
getId
(),
userId1
))
.
filter
(
m
->
!
existingMemberships
.
contains
(
m
))
.
collect
(
Collectors
.
toSet
());
List
<
GroupEntity
>
user1Groups
=
membershipsDAO
.
getUserMemberships
(
userId1
);
List
<
GroupEntity
>
user2Groups
=
membershipsDAO
.
getUserMemberships
(
userId2
);
// The user having less groups will be deleted
String
remainingUserId
=
user1Groups
.
size
()
>=
user2Groups
.
size
()
?
userId1
:
userId2
;
String
deletingUserId
=
remainingUserId
.
equals
(
userId1
)
?
userId2
:
userId1
;
List
<
GroupEntity
>
remainingUserGroups
=
remainingUserId
.
equals
(
userId1
)
?
user1Groups
:
user2Groups
;
List
<
GroupEntity
>
deletingUserGroups
=
deletingUserId
.
equals
(
userId1
)
?
user1Groups
:
user2Groups
;
Set
<
MembershipEntity
>
existingMemberships
=
remainingUserGroups
.
stream
()
.
map
(
g
->
getMembershipEntity
(
g
.
getId
(),
remainingUserId
))
.
collect
(
Collectors
.
toSet
());
Set
<
MembershipEntity
>
membershipsToAdd
=
deletingUserGroups
.
stream
()
.
map
(
g
->
getMembershipEntity
(
g
.
getId
(),
remainingUserId
))
.
filter
(
m
->
!
existingMemberships
.
contains
(
m
))
.
collect
(
Collectors
.
toSet
());
Set
<
PermissionEntity
>
existingPermissions
=
permissionsDAO
.
findUserPermissions
(
u
serId
1
).
stream
()
=
permissionsDAO
.
findUserPermissions
(
remainingU
serId
).
stream
()
.
collect
(
Collectors
.
toSet
());
Set
<
PermissionEntity
>
permissionsToAdd
=
permissionsDAO
.
findUserPermissions
(
u
serId
2
).
stream
()
=
permissionsDAO
.
findUserPermissions
(
deletingU
serId
).
stream
()
.
map
(
p
->
{
p
.
setUserId
(
u
serId
1
);
p
.
setUserId
(
remainingU
serId
);
return
p
;
})
.
filter
(
p
->
isPermissionToAdd
(
existingPermissions
,
p
))
.
collect
(
Collectors
.
toSet
());
joinDAO
.
join
(
membershipsToAdd
,
permissionsToAdd
,
userId2
);
joinDAO
.
join
(
membershipsToAdd
,
permissionsToAdd
,
deletingUserId
);
loggingDAO
.
logAction
(
ActionType
.
JOIN
,
"removed_user="
+
deletingUserId
+
" added_memberships: "
+
String
.
join
(
", "
,
getAddedGroups
(
membershipsToAdd
))
+
" added_permissions: "
+
String
.
join
(
", "
,
getAddedPermissions
(
permissionsToAdd
))
);
return
remainingUserId
;
}
private
List
<
String
>
getAddedGroups
(
Set
<
MembershipEntity
>
membershipsToAdd
)
{
return
membershipsToAdd
.
stream
().
map
(
m
->
m
.
getGroupId
()).
collect
(
Collectors
.
toList
());
}
private
List
<
String
>
getAddedPermissions
(
Set
<
PermissionEntity
>
permissionsToAdd
)
{
return
permissionsToAdd
.
stream
().
map
(
m
->
"("
+
m
.
getGroupId
()
+
","
+
m
.
getPermission
()
+
")"
).
collect
(
Collectors
.
toList
());
}
private
MembershipEntity
getMembershipEntity
(
String
groupId
,
String
userId
)
{
...
...
gms/src/main/java/it/inaf/ia2/gms/service/PermissionsService.java
View file @
cdc85827
...
...
@@ -4,6 +4,7 @@ import it.inaf.ia2.gms.model.Permission;
import
it.inaf.ia2.gms.persistence.LoggingDAO
;
import
it.inaf.ia2.gms.persistence.model.PermissionEntity
;
import
it.inaf.ia2.gms.persistence.PermissionsDAO
;
import
static
it
.
inaf
.
ia2
.
gms
.
persistence
.
model
.
ActionType
.*;
import
it.inaf.ia2.gms.persistence.model.GroupEntity
;
import
java.util.List
;
import
java.util.Optional
;
...
...
@@ -26,16 +27,20 @@ public class PermissionsService {
return
permissionsDAO
.
getGroupsPermissions
(
group
.
getId
());
}
public
List
<
PermissionEntity
>
findUserPermissions
(
String
userId
)
{
return
permissionsDAO
.
findUserPermissions
(
userId
);
}
public
List
<
PermissionEntity
>
findUserPermissions
(
GroupEntity
group
,
String
userId
)
{
return
permissionsDAO
.
findUserPermissions
(
userId
,
group
.
getPath
());
}
public
void
removePermission
(
GroupEntity
group
,
String
userId
)
{
permissionsDAO
.
deletePermission
(
group
.
getId
(),
userId
);
loggingDAO
.
logAction
(
"Removed permission for "
+
userId
+
"in group "
+
group
.
getId
());
loggingDAO
.
logAction
(
PERMISSION_REMOVED
,
"Removed permission for "
+
userId
+
"
in group "
+
group
.
getId
());
}
public
PermissionEntity
addPermission
(
GroupEntity
group
,
String
userId
,
Permission
permission
)
{
public
PermissionEntity
addPermission
(
GroupEntity
group
,
String
userId
,
Permission
permission
,
String
setBy
)
{
Optional
<
PermissionEntity
>
existingPermissionEntity
=
permissionsDAO
.
findPermissionEntity
(
group
.
getId
(),
userId
);
...
...
@@ -54,30 +59,41 @@ public class PermissionsService {
permissionEntity
.
setUserId
(
userId
);
permissionEntity
.
setPermission
(
permission
);
permissionEntity
.
setGroupPath
(
group
.
getPath
());
permissionEntity
.
setSetBy
(
setBy
);
}
permissionEntity
=
permissionsDAO
.
createOrUpdatePermission
(
permissionEntity
);
loggingDAO
.
logAction
(
"Added "
+
permission
+
" permission for "
+
userId
+
"in group "
+
group
.
getId
());
loggingDAO
.
logAction
(
PERMISSION_ADDED
,
"Added "
+
permission
+
" permission for "
+
userId
+
"
in group "
+
group
.
getId
());
return
permissionEntity
;
}
public
PermissionEntity
createOrUpdatePermission
(
GroupEntity
group
,
String
userId
,
Permission
permission
)
{
public
PermissionEntity
createOrUpdatePermission
(
GroupEntity
group
,
String
userId
,
Permission
permission
,
String
setBy
)
{
PermissionEntity
permissionEntity
=
new
PermissionEntity
();
permissionEntity
.
setGroupId
(
group
.
getId
());
permissionEntity
.
setUserId
(
userId
);
permissionEntity
.
setPermission
(
permission
);
permissionEntity
.
setGroupPath
(
group
.
getPath
());
permissionEntity
.
setSetBy
(
setBy
);
return
permissionsDAO
.
createOrUpdatePermission
(
permissionEntity
);
permissionEntity
=
permissionsDAO
.
createOrUpdatePermission
(
permissionEntity
);
loggingDAO
.
logAction
(
PERMISSION_ADDED
,
"Added "
+
permission
+
" permission for "
+
userId
+
" in group "
+
group
.
getId
());
return
permissionEntity
;
}
public
PermissionEntity
updatePermission
(
GroupEntity
group
,
String
userId
,
Permission
permission
)
{
public
PermissionEntity
updatePermission
(
GroupEntity
group
,
String
userId
,
Permission
permission
,
String
setBy
)
{
PermissionEntity
permissionEntity
=
permissionsDAO
.
findPermissionEntity
(
group
.
getId
(),
userId
)
.
orElseThrow
(()
->
new
IllegalArgumentException
(
"Specified permission not found"
));
return
permissionsDAO
.
updatePermission
(
permissionEntity
,
permission
);
permissionEntity
.
setSetBy
(
setBy
);
permissionEntity
.
setPermission
(
permission
);
permissionEntity
=
permissionsDAO
.
updatePermission
(
permissionEntity
);
loggingDAO
.
logAction
(
PERMISSION_UPDATED
,
"Updated permission for "
+
userId
+
" in group "
+
group
.
getId
()
+
" to "
+
permission
);
return
permissionEntity
;
}
}
gms/src/main/java/it/inaf/ia2/gms/service/SearchService.java
View file @
cdc85827
...
...
@@ -14,6 +14,7 @@ import it.inaf.ia2.gms.persistence.PermissionsDAO;
import
it.inaf.ia2.gms.persistence.model.GroupEntity
;
import
it.inaf.ia2.gms.persistence.model.PermissionEntity
;
import
it.inaf.ia2.gms.authn.RapClient
;
import
it.inaf.ia2.gms.model.request.GenericSearchRequest
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -46,15 +47,21 @@ public class SearchService {
/**
* Generic search (both groups and users).
*/
public
PaginatedData
<
SearchResponseItem
>
search
(
String
query
,
String
userId
,
int
page
,
int
pageSize
)
{
public
PaginatedData
<
SearchResponseItem
>
search
(
GenericSearchRequest
searchRequest
,
String
userId
)
{
List
<
SearchResponseItem
>
items
=
searchUsers
(
query
);
items
.
addAll
(
searchGroups
(
query
,
userId
));
List
<
SearchResponseItem
>
items
=
new
ArrayList
<>();
if
(
searchRequest
.
isUsers
())
{
items
.
addAll
(
searchUsers
(
searchRequest
.
getQuery
()));
}
if
(
searchRequest
.
isGroups
())
{
items
.
addAll
(
searchGroups
(
searchRequest
.
getQuery
(),
userId
));
}
// sort by label
items
.
sort
((
i1
,
i2
)
->
i1
.
getLabel
().
compareTo
(
i2
.
getLabel
()));
return
new
PaginatedData
<>(
items
,
page
,
p
ageSize
);
return
new
PaginatedData
<>(
items
,
searchRequest
.
getPaginatorPage
(),
searchRequest
.
getPaginatorP
ageSize
()
);
}
private
List
<
SearchResponseItem
>
searchUsers
(
String
query
)
{
...
...
gms/src/main/resources/sql/init.sql
View file @
cdc85827
...
...
@@ -6,6 +6,8 @@ CREATE TABLE gms_group (
path
ltree
NOT
NULL
,
is_leaf
boolean
,
locked
boolean
,
creation_time
timestamp
DEFAULT
NOW
(),
created_by
varchar
,
primary
key
(
id
)
);
...
...
@@ -16,6 +18,8 @@ CREATE INDEX group_name_idx ON gms_group USING btree(name);
CREATE
TABLE
gms_membership
(
group_id
varchar
NOT
NULL
,
user_id
varchar
NOT
NULL
,
creation_time
timestamp
DEFAULT
NOW
(),
created_by
varchar
,
primary
key
(
group_id
,
user_id
),
foreign
key
(
group_id
)
references
gms_group
(
id
)
);
...
...
@@ -27,6 +31,8 @@ CREATE TABLE gms_permission (
user_id
varchar
NOT
NULL
,
permission
permission_type
NOT
NULL
,
group_path
ltree
NOT
NULL
,
-- group_path is copied here for performance reasons
update_time
timestamp
DEFAULT
NOW
(),
set_by
varchar
,
primary
key
(
group_id
,
user_id
),
-- we can have 1 permission for each group
foreign
key
(
group_id
)
references
gms_group
(
id
),
foreign
key
(
group_path
)
references
gms_group
(
path
)
...
...
@@ -42,7 +48,8 @@ CREATE TABLE audit_log (
"date"
timestamp
DEFAULT
NOW
(),
"user"
varchar
,
"ip_address"
varchar
,
"action"
TEXT
"action_type"
varchar
,
"description"
TEXT
);
CREATE
TABLE
invited_registration_request
(
...
...
gms/src/main/resources/sql/upgrade.sql
0 → 100644
View file @
cdc85827
-- 2021-03-12
ALTER
TABLE
gms_group
ADD
COLUMN
creation_time
timestamp
DEFAULT
NOW
();
ALTER
TABLE
gms_group
ADD
COLUMN
created_by
varchar
;
ALTER
TABLE
gms_membership
ADD
COLUMN
creation_time
timestamp
DEFAULT
NOW
();
ALTER
TABLE
gms_membership
ADD
COLUMN
created_by
varchar
;
ALTER
TABLE
gms_permission
ADD
COLUMN
update_time
timestamp
DEFAULT
NOW
();
ALTER
TABLE
gms_permission
ADD
COLUMN
set_by
varchar
;
--- 2021-03-19
ALTER
TABLE
audit_log
ADD
COLUMN
action_type
varchar
;
ALTER
TABLE
audit_log
RENAME
COLUMN
action
TO
description
;
gms/src/main/resources/static/help/help-admin.html
View file @
cdc85827
...
...
@@ -54,9 +54,9 @@
<img
src=
"img/gms-admin-add-group-modal.jpg"
alt=
""
class=
"mb-3"
/>
</p>
<p>
If you select the "
is leaf" checkbox, the group will be a leaf of the tree: this means that
it will not be possible to create sub-groups inside it. You can change this setting in any moment
clicking on the "Edit group" button (pencil icon
<img
src=
"img/pencil-icon.jpg"
alt=
""
/>
).
</p>
<p>
If you select the "
allow child groups" checkbox it will be possible to create sub-groups inside the group.
You can change this setting in any moment clicking on the "Edit group" button (pencil icon
<img
src=
"img/pencil-icon.jpg"
alt=
""
/>
).
</p>
<p>
You can delete groups using trash icons (
<img
src=
"img/trash-icon.jpg"
alt=
""
/>
).
A dialog will ask for confirming the operation before deleting the group.
</p>
...
...
gms/src/main/resources/static/help/help-pi.html
View file @
cdc85827
...
...
@@ -36,6 +36,10 @@
If multiple users need to manage memberships of the same group you can ask administrators to enable them.
</p>
<p><strong>
IMPORTANT
</strong>
: A user is searchable after he/she has performed the first login on one
of our services. Check
<a
href=
"https://sso.ia2.inaf.it/"
target=
"blank_"
>
SSO help page
</a>
for more information about IA2 authentication.
</p>
<p>
You can delete memberships using the trash icons (
<img
src=
"img/trash-icon.jpg"
alt=
""
/>
).
<h2
class=
"mt-4"
>
Seeing information about users
</h2>
...
...
gms/src/main/resources/static/help/img/gms-admin-add-group-modal.jpg
View replaced file @
846f9873
View file @
cdc85827
17.9 KiB
|
W:
|
H:
25.2 KiB
|
W:
|
H:
2-up
Swipe
Onion skin
gms/src/test/java/it/inaf/ia2/gms/controller/ControllersMockData.java
0 → 100644
View file @
cdc85827
package
it.inaf.ia2.gms.controller
;
import
it.inaf.ia2.gms.persistence.model.GroupEntity
;
import
it.inaf.ia2.gms.service.GroupsService
;
import
it.inaf.ia2.rap.data.RapUser
;
import
java.security.Principal
;
public
class
ControllersMockData
{
public
static
GroupEntity
getRoot
()
{
GroupEntity
root
=
new
GroupEntity
();
root
.
setId
(
GroupsService
.
ROOT
);
root
.
setName
(
GroupsService
.
ROOT
);
root
.
setPath
(
""
);
return
root
;
}
public
static
GroupEntity
getLbtGroup
()
{
GroupEntity
lbt
=
new
GroupEntity
();
lbt
.
setId
(
"lbt_id"
);
lbt
.
setName
(
"LBT"
);
lbt
.
setPath
(
"lbt_id"
);
return
lbt
;
}
public
static
GroupEntity
getInafGroup
()
{
GroupEntity
inaf
=
new
GroupEntity
();
inaf
.
setId
(
"inaf_id"
);
inaf
.
setName
(
"INAF"
);
inaf
.
setPath
(
"lbt_id.inaf_id"
);
return
inaf
;
}
public
static
GroupEntity
getInafProgramGroup
()
{
GroupEntity
inafProgram
=
new
GroupEntity
();
inafProgram
.
setId
(
"inaf_p1_id"
);
inafProgram
.
setName
(
"P1"
);
inafProgram
.
setPath
(
"lbt_id.inaf_id.inaf_p1_id"
);
return
inafProgram
;
}
public
static
GroupEntity
getPeopleGroup
()
{
GroupEntity
lbt
=
new
GroupEntity
();
lbt
.
setId
(
"people_id"
);
lbt
.
setName
(
"people"
);
lbt
.
setPath
(
"people_id"
);
return
lbt
;
}
public
static
GroupEntity
getNameSurnameGroup
()
{
GroupEntity
inaf
=
new
GroupEntity
();
inaf
.
setId
(
"user_group_id"
);
inaf
.
setName
(
"name.surname"
);
inaf
.
setPath
(
"people_id.user_group_id"
);
return
inaf
;
}
public
static
RapUser
getRapUser
()
{
RapUser
user
=
new
RapUser
();
user
.
setId
(
"rap_user"
);
return
user
;
}
public
static
Principal
getPrincipal
()
{
return
new
Principal
()
{
@Override
public
String
getName
()
{
return
"TEST_PRINCIPAL"
;
}
};
}
}
gms/src/test/java/it/inaf/ia2/gms/controller/GroupsControllerTest.java
View file @
cdc85827
...
...
@@ -2,6 +2,7 @@ package it.inaf.ia2.gms.controller;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
it.inaf.ia2.gms.GmsTestUtils
;
import
static
it
.
inaf
.
ia2
.
gms
.
controller
.
ControllersMockData
.*;
import
it.inaf.ia2.gms.manager.GroupsManager
;
import
it.inaf.ia2.gms.manager.PermissionsManager
;
import
it.inaf.ia2.gms.model.GroupNode
;
...
...
@@ -9,18 +10,28 @@ import it.inaf.ia2.gms.model.Permission;
import
it.inaf.ia2.gms.model.request.AddGroupRequest
;
import
it.inaf.ia2.gms.model.response.GroupsTabResponse
;
import
it.inaf.ia2.gms.model.response.PaginatedData
;
import
it.inaf.ia2.gms.persistence.GroupsDAO
;
import
it.inaf.ia2.gms.persistence.LoggingDAO
;
import
it.inaf.ia2.gms.persistence.model.GroupEntity
;
import
it.inaf.ia2.gms.service.GroupNameService
;
import
it.inaf.ia2.gms.service.GroupsService
;
import
it.inaf.ia2.gms.service.GroupsTreeBuilder
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Set
;
import
javax.servlet.http.HttpServletRequest
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
notNullValue
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyBoolean
;
import
static
org
.
mockito
.
ArgumentMatchers
.
argThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
...
...
@@ -59,6 +70,9 @@ public class GroupsControllerTest {
@Mock
private
GroupsTreeBuilder
groupsTreeBuilder
;
@Mock
private
GroupsDAO
groupsDAO
;
@Mock
private
LoggingDAO
loggingDAO
;
...
...
@@ -72,11 +86,12 @@ public class GroupsControllerTest {
@Before
public
void
init
()
{
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
controller
).
build
();
controller
.
groupNameService
=
new
GroupNameService
(
groupsDAO
);
GmsTestUtils
.
mockPrincipal
(
servletRequest
);
}
@Test
public
void
testGetGroups
()
throws
Exception
{
public
void
testGetGroups
Paginated
()
throws
Exception
{
GroupsTabResponse
response
=
new
GroupsTabResponse
();
response
.
setBreadcrumbs
(
new
ArrayList
<>());
...
...
@@ -85,7 +100,7 @@ public class GroupsControllerTest {
when
(
groupsTabResponseBuilder
.
getGroupsTab
(
any
())).
thenReturn
(
response
);
mockMvc
.
perform
(
get
(
"/groups?groupId=ROOT&paginatorPageSize=20&paginatorPage=1"
))
mockMvc
.
perform
(
get
(
"/
ui/
groups?groupId=ROOT&paginatorPageSize=20&paginatorPage=1"
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$.breadcrumbs"
,
notNullValue
()))
.
andExpect
(
jsonPath
(
"$.groupsPanel"
,
notNullValue
()))
...
...
@@ -93,7 +108,7 @@ public class GroupsControllerTest {
}
@Test
public
void
testAddGroup
s
()
throws
Exception
{
public
void
testAddGroup
Paginated
()
throws
Exception
{
AddGroupRequest
request
=
new
AddGroupRequest
();
request
.
setNewGroupName
(
"New Group"
);
...
...
@@ -106,19 +121,82 @@ public class GroupsControllerTest {
PaginatedData
<
GroupNode
>
paginatedData
=
new
PaginatedData
<>(
nodes
,
1
,
10
);
when
(
groupsTreeBuilder
.
listSubGroups
(
any
(),
any
(),
any
())).
thenReturn
(
paginatedData
);
mockMvc
.
perform
(
post
(
"/group"
)
mockMvc
.
perform
(
post
(
"/
ui/
group"
)
.
content
(
mapper
.
writeValueAsString
(
request
))
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
status
().
isCreated
());
}
@Test
public
void
testDeleteGroup
()
throws
Exception
{
public
void
testDeleteGroup
Paginated
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/group/id?paginatorPageSize=20&paginatorPage=1&searchFilter="
))
mockMvc
.
perform
(
delete
(
"/
ui/
group/id?paginatorPageSize=20&paginatorPage=1&searchFilter="
))
.
andDo
(
print
())
.
andExpect
(
status
().
isOk
());
verify
(
groupsManager
,
times
(
1
)).
deleteGroup
(
eq
(
"id"
));
}
@Test
public
void
testAddGroup
()
throws
Exception
{
GroupEntity
peopleGroup
=
getPeopleGroup
();
when
(
groupsManager
.
getRoot
()).
thenReturn
(
getRoot
());
when
(
groupsManager
.
createGroup
(
any
(
GroupEntity
.
class
),
eq
(
"people"
),
eq
(
false
))).
thenReturn
(
peopleGroup
);
when
(
groupsManager
.
createGroup
(
any
(
GroupEntity
.
class
),
eq
(
"name.surname"
),
eq
(
true
))).
thenReturn
(
getNameSurnameGroup
());
mockMvc
.
perform
(
post
(
"/group"
)
.
param
(
"name"
,
"people.name\\.surname"
)
.
param
(
"leaf"
,
"true"
)
.
accept
(
MediaType
.
TEXT_PLAIN
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
))
.
andExpect
(
status
().
isCreated
());
verify
(
groupsService
,
times
(
2
)).
findGroupByParentAndName
(
any
(
GroupEntity
.
class
),
any
());
verify
(
groupsManager
,
times
(
1
)).
createGroup
(
argGroupIdEq
(
GroupsService
.
ROOT
),
eq
(
"people"
),
eq
(
false
));
verify
(
groupsManager
,
times
(
1
)).
createGroup
(
argGroupIdEq
(
"people_id"
),
eq
(
"name.surname"
),
eq
(
true
));
}
@Test
public
void
testDeleteGroup
()
throws
Exception
{
GroupEntity
inafGroup
=
getInafGroup
();
when
(
groupsDAO
.
findGroupByParentAndName
(
""
,
"LBT"
)).
thenReturn
(
Optional
.
of
(
getLbtGroup
()));
when
(
groupsDAO
.
findGroupByParentAndName
(
"lbt_id"
,
"INAF"
)).
thenReturn
(
Optional
.
of
(
inafGroup
));
mockMvc
.
perform
(
delete
(
"/group?name=LBT.INAF"
))
.
andExpect
(
status
().
isNoContent
());
verify
(
groupsManager
,
times
(
1
)).
deleteGroup
(
eq
(
inafGroup
.
getId
()));
}
@Test
public
void
testListChildGroups
()
throws
Exception
{
GroupEntity
lbtGroup
=
getLbtGroup
();
GroupEntity
inafGroup
=
getInafGroup
();
GroupEntity
inafProgramGroup
=
getInafProgramGroup
();
when
(
groupsDAO
.
findGroupByParentAndName
(
""
,
"LBT"
)).
thenReturn
(
Optional
.
of
(
lbtGroup
));
when
(
groupsDAO
.
findGroupByParentAndName
(
lbtGroup
.
getPath
(),
"INAF"
)).
thenReturn
(
Optional
.
of
(
inafGroup
));
Map
<
String
,
String
>
namesMap
=
Map
.
of
(
inafProgramGroup
.
getId
(),
"LBT.INAF.P1"
);
when
(
groupsDAO
.
getGroupCompleteNamesFromId
(
Set
.
of
(
inafProgramGroup
.
getId
()))).
thenReturn
(
namesMap
);
when
(
groupsManager
.
getChildGroups
(
eq
(
inafGroup
),
anyBoolean
())).
thenReturn
(
Arrays
.
asList
(
inafProgramGroup
));
String
response
=
mockMvc
.
perform
(
get
(
"/groups?parent=LBT.INAF&recursive=false"
)
.
accept
(
MediaType
.
TEXT_PLAIN
))
.
andExpect
(
status
().
isOk
())
.
andReturn
().
getResponse
().
getContentAsString
();
assertEquals
(
"P1\n"
,
response
);
}
private
GroupEntity
argGroupIdEq
(
String
groupId
)
{
return
argThat
(
g
->
g
.
getId
().
equals
(
groupId
));
}
}
gms/src/test/java/it/inaf/ia2/gms/controller/HomePageControllerTest.java
View file @
cdc85827
...
...
@@ -43,7 +43,7 @@ public class HomePageControllerTest {
when
(
groupsTabResponseBuilder
.
getGroupsTab
(
any
())).
thenReturn
(
new
GroupsTabResponse
());
mockMvc
.
perform
(
get
(
"/home?groupId=ROOT&paginatorPageSize=20&paginatorPage=1"
))
mockMvc
.
perform
(
get
(
"/
ui/
home?groupId=ROOT&paginatorPageSize=20&paginatorPage=1"
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$.user"
,
notNullValue
()));
}
...
...
gms/src/test/java/it/inaf/ia2/gms/controller/InvitedRegistrationControllerTest.java
View file @
cdc85827
...
...
@@ -35,7 +35,7 @@ public class InvitedRegistrationControllerTest {
@Test
public
void
testDeleteInvitedRegistration
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/registration?request_id=req1&group_id=group1"
))
mockMvc
.
perform
(
delete
(
"/
ui/
registration?request_id=req1&group_id=group1"
))
.
andDo
(
print
())
.
andExpect
(
status
().
isNoContent
());
...
...
gms/src/test/java/it/inaf/ia2/gms/controller/JWTWebServiceControllerTest.java
View file @
cdc85827
...
...
@@ -16,7 +16,6 @@ import it.inaf.ia2.gms.service.JoinService;
import
it.inaf.ia2.rap.data.RapUser
;
import
java.security.Principal
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Optional
;
import
org.junit.Before
;
...
...
@@ -153,7 +152,7 @@ public class JWTWebServiceControllerTest {
mockMvc
.
perform
(
delete
(
"/ws/jwt/LBT.INAF"
))
.
andExpect
(
status
().
isNoContent
());
verify
(
groups
DAO
,
times
(
1
)).
deleteGroup
(
eq
(
inaf
));
verify
(
groups
Manager
,
times
(
1
)).
deleteGroup
(
eq
(
inaf
.
getId
()
));
}
@Test
...
...
@@ -238,9 +237,6 @@ public class JWTWebServiceControllerTest {
@Test
public
void
testRemovePermission
()
throws
Exception
{
List
<
String
>
names
=
Arrays
.
asList
(
"LBT"
,
"INAF"
);
//when(groupsService.findGroupByNames(names)).thenReturn(Optional.of(inaf));
when
(
groupsDAO
.
findGroupByParentAndName
(
""
,
"LBT"
)).
thenReturn
(
Optional
.
of
(
lbt
));
when
(
groupsDAO
.
findGroupByParentAndName
(
"lbt_id"
,
"INAF"
)).
thenReturn
(
Optional
.
of
(
inaf
));
...
...
Prev
1
2
3
4
5
Next