-
-
Notifications
You must be signed in to change notification settings - Fork 512
Allow Editor and Reviewer profiles to transfer record ownership #9284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1256,6 +1256,38 @@ private void updateOwnership(Integer groupIdentifier, | |
| serviceContext, String.valueOf(metadata.getId()))) { | ||
| report.addNotEditableMetadataId(metadata.getId()); | ||
| } else { | ||
| UserSession callerSession = ApiUtils.getUserSession(session); | ||
| Profile callerProfile = callerSession.getProfile(); | ||
|
|
||
| if (callerProfile == Profile.Editor || callerProfile == Profile.Reviewer) { | ||
| int callerUserId = callerSession.getUserIdAsInt(); | ||
| Integer sourceUsr = metadata.getSourceInfo().getOwner(); | ||
| Integer sourceGrp = metadata.getSourceInfo().getGroupOwner(); | ||
|
|
||
| if (callerProfile == Profile.Editor) { | ||
| if (!Objects.equals(sourceUsr, callerUserId)) { | ||
| report.addNotEditableMetadataId(metadata.getId()); | ||
| return; | ||
| } | ||
| } else { | ||
| Set<Integer> reviewerGroups = accessMan.getReviewerGroups(callerSession); | ||
| if (sourceGrp == null || !reviewerGroups.contains(sourceGrp)) { | ||
| report.addNotEditableMetadataId(metadata.getId()); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (!ReservedGroup.isReserved(groupIdentifier)) { | ||
| List<Integer> myGroups = userGroupRepository.findGroupIds( | ||
| UserGroupSpecs.hasUserId(callerUserId)); | ||
| if (!myGroups.contains(groupIdentifier)) { | ||
| report.addMetadataInfos(metadata, | ||
| "Transfer to group " + groupIdentifier + " is not allowed for your profile."); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @juanluisrp I would refactor a bit the code of the changes: private boolean isEditableMetadata(AbstractMetadata metadata, AccessManager accessMan, UserSession callerSession) throws Exception {
Profile callerProfile = callerSession.getProfile();
if (callerProfile == Profile.Editor || callerProfile == Profile.Reviewer) {
int callerUserId = callerSession.getUserIdAsInt();
Integer sourceUsr = metadata.getSourceInfo().getOwner();
Integer sourceGrp = metadata.getSourceInfo().getGroupOwner();
if (callerProfile == Profile.Editor) {
if (!Objects.equals(sourceUsr, callerUserId)) {
return false;
}
} else {
Set<Integer> reviewerGroups = accessMan.getReviewerGroups(callerSession);
if (sourceGrp == null || !reviewerGroups.contains(sourceGrp)) {
return false;
}
}
} else if (callerProfile == Profile.Administrator) {
return true;
}
return false;
}
private boolean isDestinationTransferGroupAllowed(Integer groupIdentifier, UserSession callerSession) {
Profile callerProfile = callerSession.getProfile();
if (callerProfile == Profile.Editor || callerProfile == Profile.Reviewer) {
int callerUserId = callerSession.getUserIdAsInt();
if (!ReservedGroup.isReserved(groupIdentifier)) {
List<Integer> myGroups = userGroupRepository.findGroupIds(
UserGroupSpecs.hasUserId(callerUserId));
if (!myGroups.contains(groupIdentifier)) {
return false;
}
}
return true;
} else if (callerProfile == Profile.Administrator) {
return true;
}
return false;
}...
UserSession callerSession = ApiUtils.getUserSession(session);
if (!isEditableMetadata(metadata, accessMan, callerSession)) {
report.addNotEditableMetadataId(metadata.getId());
return;
}
if (!isDestinationTransferGroupAllowed(groupIdentifier, callerSession)) {
report.addMetadataInfos(metadata,
"Transfer to group " + groupIdentifier + " is not allowed for your profile.");
return;
}
// Retrieve the identifiers associated with the metadata uuid.
// When the workflow is enabled, the metadata can have an approved and a working copy version.
...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @juanluisrp I would refactor a bit the code of the changes: private boolean isEditableMetadata(AbstractMetadata metadata, AccessManager accessMan, UserSession callerSession) throws Exception {
Profile callerProfile = callerSession.getProfile();
if (callerProfile == Profile.Editor || callerProfile == Profile.Reviewer) {
int callerUserId = callerSession.getUserIdAsInt();
Integer sourceUsr = metadata.getSourceInfo().getOwner();
Integer sourceGrp = metadata.getSourceInfo().getGroupOwner();
if (callerProfile == Profile.Editor) {
if (!Objects.equals(sourceUsr, callerUserId)) {
return false;
}
} else {
Set<Integer> reviewerGroups = accessMan.getReviewerGroups(callerSession);
if (sourceGrp == null || !reviewerGroups.contains(sourceGrp)) {
return false;
}
}
} else if (callerProfile == Profile.Administrator) {
return true;
}
return false;
}
private boolean isDestinationTransferGroupAllowed(Integer groupIdentifier, UserSession callerSession) {
Profile callerProfile = callerSession.getProfile();
if (callerProfile == Profile.Editor || callerProfile == Profile.Reviewer) {
int callerUserId = callerSession.getUserIdAsInt();
if (!ReservedGroup.isReserved(groupIdentifier)) {
List<Integer> myGroups = userGroupRepository.findGroupIds(
UserGroupSpecs.hasUserId(callerUserId));
if (!myGroups.contains(groupIdentifier)) {
return false;
}
}
return true;
} else if (callerProfile == Profile.Administrator) {
return true;
} else {
return false;
}
}...
UserSession callerSession = ApiUtils.getUserSession(session);
if (!isEditableMetadata(metadata, accessMan, callerSession)) {
report.addNotEditableMetadataId(metadata.getId());
return;
}
if (!isDestinationTransferGroupAllowed(groupIdentifier, callerSession)) {
report.addMetadataInfos(metadata,
"Transfer to group " + groupIdentifier + " is not allowed for your profile.");
return;
}
// Retrieve the identifiers associated with the metadata uuid.
// When the workflow is enabled, the metadata can have an approved and a working copy version.
... |
||
|
|
||
| // Retrieve the identifiers associated with the metadata uuid. | ||
| // When the workflow is enabled, the metadata can have an approved and a working copy version. | ||
| List<Integer> idList = metadataUtils.findAllIdsBy(MetadataSpecs.hasMetadataUuid(uuid)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,6 +186,20 @@ public List<UserGroupsResponse> retrieveAllUserGroups( | |
| ); | ||
| } | ||
| return list; | ||
| } else if (myProfile == Profile.Reviewer || myProfile == Profile.Editor) { | ||
| List<Integer> myGroups = userGroupRepository.findAll(UserGroupSpecs.hasUserId(session.getUserIdAsInt())) | ||
| .stream().map(ug -> ug.getGroup().getId()).collect(Collectors.toList()); | ||
| List<UserGroup> userGroups = userGroupRepository.findAll(UserGroupSpecs.hasGroupIds(myGroups)); | ||
|
|
||
| if (groupTypes != null) { | ||
| userGroups = userGroups.stream() | ||
| .filter(ug -> groupTypes.contains(ug.getGroup().getType())) | ||
| .collect(Collectors.toList()); | ||
| } | ||
| for (UserGroup ug : userGroups) { | ||
| list.add(new UserGroupsResponse(ug.getUser(), ug.getGroup(), ug.getProfile().name())); | ||
| } | ||
| return list; | ||
|
Comment on lines
+189
to
+202
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would refactor, with previous lines also: private List<UserGroupsResponse> getUserGroupsResponse(List<UserGroup> userGroups, List<GroupType> groupTypes) {
List<UserGroupsResponse> list = new ArrayList<>();
if (groupTypes != null) {
userGroups = userGroups.stream()
.filter(ug -> groupTypes.contains(ug.getGroup().getType()))
.collect(Collectors.toList());
}
for (UserGroup ug : userGroups) {
list.add(new UserGroupsResponse(ug.getUser(), ug.getGroup(), ug.getProfile().name()));
}
return list;
}...
list.addAll(getUserGroupsResponse(userGroups, groupTypes));
return list;
} else if (myProfile == Profile.Reviewer || myProfile == Profile.Editor) {
List<Integer> myGroups = userGroupRepository.findAll(UserGroupSpecs.hasUserId(session.getUserIdAsInt()))
.stream().map(ug -> ug.getGroup().getId()).collect(Collectors.toList());
List<UserGroup> userGroups = userGroupRepository.findAll(UserGroupSpecs.hasGroupIds(myGroups));
return getUserGroupsResponse(userGroups, groupTypes);
} else {
throw new SecurityException("You don't have rights to do get the groups for this user");
}
... |
||
| } else { | ||
| throw new SecurityException("You don't have rights to do get the groups for this user"); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juanluisrp I would refactor a bit the code of the changes:
... UserSession callerSession = ApiUtils.getUserSession(session); if (!isEditableMetadata(metadata, accessMan, callerSession)) { report.addNotEditableMetadataId(metadata.getId()); return; } if (!isDestinationTransferGroupAllowed(groupIdentifier, callerSession)) { report.addMetadataInfos(metadata, "Transfer to group " + groupIdentifier + " is not allowed for your profile."); return; } // Retrieve the identifiers associated with the metadata uuid. // When the workflow is enabled, the metadata can have an approved and a working copy version. ...