/** * Retrieves the groupId where the members belongs to. * * @param studyId study id. * @param members List of user ids. * @return the group id of the user. Null if the user does not take part of any group. * @throws CatalogException when there is any database error. */ QueryResult<Group> getGroupBelonging(long studyId, List<String> members) throws CatalogException { return studyDBAdaptor.getGroup(studyId, null, members); }
/** * Checks if the member is valid. * * The "member" can be: * - '*' referring to all the users. * - '@{groupId}' referring to a {@link Group}. * - '{userId}' referring to a specific user. * @param studyId studyId * @param member member * @throws CatalogDBException CatalogDBException */ protected void checkMember(long studyId, String member) throws CatalogDBException { if (member.equals("*")) { return; } else if (member.startsWith("@")) { QueryResult<Group> queryResult = studyDBAdaptor.getGroup(studyId, member, Collections.emptyList()); if (queryResult.getNumResults() == 0) { throw CatalogDBException.idNotFound("Group", member); } } else { userDBAdaptor.checkId(member); } }
public QueryResult<Group> getGroup(String studyStr, String groupId, String sessionId) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = resolveId(studyStr, userId); authorizationManager.checkCanViewStudy(study.getUid(), userId); // Fix the groupId if (groupId != null && !groupId.startsWith("@")) { groupId = "@" + groupId; } return studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); }
public QueryResult<Group> deleteGroup(String studyStr, String groupId, String sessionId) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = resolveId(studyStr, userId); // Fix the groupId if (!groupId.startsWith("@")) { groupId = "@" + groupId; } authorizationManager.checkCreateDeleteGroupPermissions(study.getUid(), userId, groupId); QueryResult<Group> group = studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); group.setId("Delete group"); // Remove the permissions the group might have had Study.StudyAclParams aclParams = new Study.StudyAclParams(null, AclParams.Action.RESET, null); updateAcl(Collections.singletonList(studyStr), groupId, aclParams, sessionId); studyDBAdaptor.deleteGroup(study.getUid(), groupId); return group; }
@Test public void removeUsersFromAllGroups() throws CatalogDBException { catalogStudyDBAdaptor.createGroup(5L, new Group("name1", Arrays.asList("user1", "user2"))); catalogStudyDBAdaptor.createGroup(5L, new Group("name2", Arrays.asList("user1", "user2", "user3"))); catalogStudyDBAdaptor.createGroup(5L, new Group("name3", Arrays.asList("user1", "user3"))); QueryResult<Group> group = catalogStudyDBAdaptor.getGroup(5L, null, Arrays.asList("user1", "user3")); assertEquals(3, group.getNumResults()); catalogStudyDBAdaptor.removeUsersFromAllGroups(5L, Arrays.asList("user1", "user3")); group = catalogStudyDBAdaptor.getGroup(5L, null, Arrays.asList("user1", "user3")); assertEquals(0, group.getNumResults()); }
return studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList());
public QueryResult<Group> syncGroupWith(String studyStr, String groupId, Group.Sync syncedFrom, String sessionId) throws CatalogException { ParamUtils.checkObj(syncedFrom, "sync"); String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = resolveId(studyStr, userId); if (StringUtils.isEmpty(groupId)) { throw new CatalogException("Missing group name parameter"); } // Fix the groupId if (!groupId.startsWith("@")) { groupId = "@" + groupId; } authorizationManager.checkSyncGroupPermissions(study.getUid(), userId, groupId); QueryResult<Group> group = studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); if (group.first().getSyncedFrom() != null && StringUtils.isNotEmpty(group.first().getSyncedFrom().getAuthOrigin()) && StringUtils.isNotEmpty(group.first().getSyncedFrom().getRemoteGroup())) { throw new CatalogException("Cannot modify already existing sync information."); } // Check the group exists Query query = new Query() .append(StudyDBAdaptor.QueryParams.UID.key(), study.getUid()) .append(StudyDBAdaptor.QueryParams.GROUP_NAME.key(), groupId); if (studyDBAdaptor.count(query).first() == 0) { throw new CatalogException("The group " + groupId + " does not exist."); } studyDBAdaptor.syncGroup(study.getUid(), groupId, syncedFrom); return studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); }
QueryResult<Group> group = studyDBAdaptor.getGroup(study.getUid(), catalogGroup, Collections.emptyList()); if (group.getNumResults() == 1) { if (group.first().getSyncedFrom() != null && StringUtils.isNotEmpty(group.first().getSyncedFrom().getAuthOrigin()) return studyDBAdaptor.getGroup(study.getUid(), catalogGroup, Collections.emptyList());
QueryResult<Group> groupsStudy1 = catalogStudyDBAdaptor.getGroup(5L, null, Arrays.asList("user2")); QueryResult<Group> groupsStudy2 = catalogStudyDBAdaptor.getGroup(9L, null, Arrays.asList("user2")); assertEquals(groupsStudy1.getNumResults(), groupsStudy2.getNumResults()); assertEquals(2, groupsStudy1.getNumResults()); groupsStudy1 = catalogStudyDBAdaptor.getGroup(5L, null, Arrays.asList("user2")); groupsStudy2 = catalogStudyDBAdaptor.getGroup(9L, null, Arrays.asList("user2")); assertEquals(groupsStudy1.getNumResults(), groupsStudy2.getNumResults()); assertEquals(3, groupsStudy1.getNumResults()); groupsStudy1 = catalogStudyDBAdaptor.getGroup(5L, null, Arrays.asList("user5")); groupsStudy2 = catalogStudyDBAdaptor.getGroup(9L, null, Arrays.asList("user5")); assertEquals(groupsStudy1.getNumResults(), groupsStudy2.getNumResults()); assertEquals(2, groupsStudy1.getNumResults()); groupsStudy1 = catalogStudyDBAdaptor.getGroup(5L, null, Arrays.asList("user2")); groupsStudy2 = catalogStudyDBAdaptor.getGroup(9L, null, Arrays.asList("user2")); assertEquals(groupsStudy1.getNumResults(), groupsStudy2.getNumResults()); assertEquals(4, groupsStudy1.getNumResults());