Skip to content

Commit

Permalink
Merge pull request #2430 from opencb/TASK-6032
Browse files Browse the repository at this point in the history
TASK-6032 - User info does not return projects
  • Loading branch information
pfurio authored Apr 23, 2024
2 parents 2048bc0 + ebb082c commit 3ca20ce
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,21 +353,16 @@ private void extractSharedProjects(DataResult<User> userDataResult, QueryOptions
studyMap.put(study.getFqn(), study);
studyProjectMap.put(study.getFqn(), project.getFqn());

String owner = study.getFqn().split("@")[0];

if (study.getGroups() != null) {
for (Group group : study.getGroups()) {
if (StudyManager.MEMBERS.equals(group.getId())) {
// Add all the users that should be able to see the study to the map
for (String userId : group.getUserIds()) {
// Exclude owner of the project
if (!owner.equals(userId)) {
if (users.contains(userId)) {
if (!userStudyMap.containsKey(userId)) {
userStudyMap.put(userId, new ArrayList<>());
}
userStudyMap.get(userId).add(study.getFqn());
if (users.contains(userId)) {
if (!userStudyMap.containsKey(userId)) {
userStudyMap.put(userId, new ArrayList<>());
}
userStudyMap.get(userId).add(study.getFqn());
}
}
break;
Expand All @@ -378,7 +373,7 @@ private void extractSharedProjects(DataResult<User> userDataResult, QueryOptions
}
}

// Add sharedProject information
// Add project information
for (User user : userDataResult.getResults()) {
if (userStudyMap.containsKey(user.getId())) {
Map<String, List<Study>> projectStudyMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public OpenCGAResult<User> get(String organizationId, String userId, QueryOption
* @return The requested users
* @throws CatalogException CatalogException
*/
public OpenCGAResult<User> get(String organizationId, List<String> userIdList, QueryOptions options, String token)
public OpenCGAResult<User> get(@Nullable String organizationId, List<String> userIdList, QueryOptions options, String token)
throws CatalogException {
ParamUtils.checkNotEmptyArray(userIdList, "userId");
ParamUtils.checkParameter(token, "token");
Expand All @@ -532,7 +532,7 @@ public OpenCGAResult<User> get(String organizationId, List<String> userIdList, Q
.append("token", token);
JwtPayload jwtPayload = validateToken(token);

if (userIdList.size() == 1 && jwtPayload.getUserId().equals(userIdList.get(0)) && StringUtils.isEmpty(organizationId)) {
if (StringUtils.isEmpty(organizationId)) {
organizationId = jwtPayload.getOrganization();
}
String userId = jwtPayload.getUserId(organizationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.opencb.opencga.catalog.managers;

import com.mongodb.BasicDBObject;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Ignore;
Expand Down Expand Up @@ -256,6 +257,65 @@ public void testGetUserInfo() throws CatalogException {
studyAdminToken1);
}

@Test
public void testGetProjectsFromUserInfo() throws CatalogException {
String userId = organizationId;
catalogManager.getUserManager().create(userId, "test", "mail@mail.com", TestParamConstants.PASSWORD, organizationId, null,
opencgaToken);
catalogManager.getStudyManager().updateGroup(studyFqn, ParamConstants.MEMBERS_GROUP, ParamUtils.BasicUpdateAction.ADD,
new GroupUpdateParams(Collections.singletonList("test")), ownerToken);
String token = catalogManager.getUserManager().login(organizationId, userId, TestParamConstants.PASSWORD).getToken();

DataResult<User> user = catalogManager.getUserManager().get(organizationId, userId, new QueryOptions(), token);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(organizationId, normalUserId3, new QueryOptions(), normalToken3);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(organizationId, orgOwnerUserId, new QueryOptions(), ownerToken);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(organizationId, orgAdminUserId1, new QueryOptions(), orgAdminToken1);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(organizationId, studyAdminUserId1, new QueryOptions(), studyAdminToken1);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(organizationId, normalUserId1, new QueryOptions(), orgAdminToken1);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());


user = catalogManager.getUserManager().get(null, normalUserId1, new QueryOptions(), normalToken1);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(null, normalUserId3, new QueryOptions(), normalToken3);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(null, orgOwnerUserId, new QueryOptions(), ownerToken);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(null, orgAdminUserId1, new QueryOptions(), orgAdminToken1);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(null, studyAdminUserId1, new QueryOptions(), studyAdminToken1);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());

user = catalogManager.getUserManager().get(null, normalUserId1, new QueryOptions(), orgAdminToken1);
assertTrue(CollectionUtils.isNotEmpty(user.first().getProjects()));
System.out.println(user.first().getProjects().size());
}

@Test
public void testModifyUser() throws CatalogException, InterruptedException, IOException {
ObjectMap params = new ObjectMap();
Expand Down

0 comments on commit 3ca20ce

Please sign in to comment.