Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:opencb/opencga into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfeSanahuja committed May 9, 2024
2 parents 15ae9a6 + bb2d686 commit 4138612
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 14 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/manual-deploy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ on:
type: string
required: true
hadoop:
type: string
type: choice
description: 'Hadoop flavour. Any of: [hdp3.1, hdi5.1, emr6.1, emr6.13]'
required: false
default: "hdp3.1"
default: hdp3.1
options:
- hdp3.1
- hdi5.1
- emr6.1
- emr6.13

jobs:
build:
Expand Down
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", "[email protected]", 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 4138612

Please sign in to comment.