Skip to content
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

TASK-7192 - Enable Federation Support in XetaBase #2541

Merged
merged 25 commits into from
Feb 18, 2025
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b7c7042
models: prepare for federations, #TASK-7192
pfurio Jan 10, 2025
d087744
catalog: store federation info in token, #TASK-7192
pfurio Jan 14, 2025
9b0464a
Merge branch 'develop' into TASK-7192
pfurio Jan 14, 2025
fbd759b
catalog: methods to update federation server/client params, #TASK-7192
pfurio Jan 16, 2025
6ddaa78
wip
pfurio Jan 17, 2025
e1d5835
app: add federation migration, #TASK-7192
pfurio Jan 20, 2025
a2dc078
catalog: check federated users can't access fed studies, #TASK-7192
pfurio Jan 20, 2025
727b48e
core: make MailUtils class more generic, #TASK-7192
pfurio Jan 21, 2025
0f799ec
catalog: fix AuthenticationManager implementation, #TASK-7192
pfurio Jan 21, 2025
81dda66
catalog: validate token using security key, #TASK-7192
pfurio Jan 21, 2025
a7b3ebf
catalog: return corresponding orgId when there's federation, #TASK-7192
pfurio Jan 24, 2025
0aa8043
catalog: extract new user validator, #TASK-7192
pfurio Feb 5, 2025
9d54b2b
catalog: fix study delete operation, #TASK-7192
pfurio Feb 5, 2025
0a7ee97
catalog: fix project delete implementation, #TASK-7192
pfurio Feb 5, 2025
a79a62c
catalog: control some actions on federated studies, #TASK-7192
pfurio Feb 5, 2025
e6d6544
catalog: fix queries for federated data, #TASK-7192
pfurio Feb 6, 2025
9975dba
Merge branch 'develop' into TASK-7192
pfurio Feb 7, 2025
f7fa198
app: fix user migration, #TASK-6013
pfurio Feb 7, 2025
2b9bbd6
catalog: add method to remove user from all groups in one go, #TASK-7192
pfurio Feb 10, 2025
8a07415
catalog: block user accounts even if token is valid, #TASK-7192
pfurio Feb 10, 2025
0301a92
Merge branch 'develop' into TASK-7192
pfurio Feb 11, 2025
4b3a4d3
server: improve response builder, #TASK-7192
pfurio Feb 11, 2025
4906e24
core: add fields to client mixin, #TASK-7192
pfurio Feb 12, 2025
13192c2
Merge branch 'develop' into TASK-7192
pfurio Feb 17, 2025
454977b
Merge branch 'develop' into TASK-7192
pfurio Feb 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
catalog: add method to remove user from all groups in one go, #TASK-7192
  • Loading branch information
pfurio committed Feb 10, 2025

Verified

This commit was signed with the committer’s verified signature.
pfurio Pedro Furió
commit 2b9bbd63405a5977786308608595cefa3abc92fc
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ protected void run() throws Exception {
);
});

// Patch 2. Organization 'configuration.defaultUserExpirationDate' field was not set for existing organizations
MongoCollection<Document> orgCollection = getMongoCollection(OrganizationMongoDBAdaptorFactory.ORGANIZATION_COLLECTION);
orgCollection.updateMany(Filters.exists("configuration.defaultUserExpirationDate", false),
Updates.set("configuration.defaultUserExpirationDate", Constants.DEFAULT_USER_EXPIRATION_DATE));
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.opencb.opencga.app.migrations.v3.v3_2_1;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.UpdateOneModel;
import com.mongodb.client.model.Updates;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.opencb.opencga.catalog.db.mongodb.MongoDBAdaptor;
import org.opencb.opencga.catalog.db.mongodb.OrganizationMongoDBAdaptorFactory;
import org.opencb.opencga.catalog.migration.Migration;
import org.opencb.opencga.catalog.migration.MigrationTool;
import org.opencb.opencga.catalog.utils.Constants;

import java.util.Arrays;

@@ -46,5 +49,14 @@ protected void run() throws Exception {

bulk.add(new UpdateOneModel<>(Filters.eq("_id", document.get("_id")), updateDocument.toFinalUpdateDocument()));
});

// Due to patch 2 from TASK-6013, default user expirationDate for some users was not set.
MongoCollection<Document> userCollection = getMongoCollection(OrganizationMongoDBAdaptorFactory.USER_COLLECTION);
userCollection.updateMany(
Filters.or(
Filters.eq("internal.account.expirationDate", null),
Filters.eq("internal.account.expirationDate", "")
),
Updates.set("internal.account.expirationDate", Constants.DEFAULT_USER_EXPIRATION_DATE));
}
}
Original file line number Diff line number Diff line change
@@ -252,6 +252,8 @@ OpenCGAResult<Group> setUsersToGroup(long studyId, String groupId, List<String>

OpenCGAResult<Group> removeUsersFromAllGroups(long studyId, List<String> users) throws CatalogException;

OpenCGAResult<Group> removeUsersFromAllGroups(List<String> users) throws CatalogException;

/**
* Delete a group.
*
Original file line number Diff line number Diff line change
@@ -418,13 +418,13 @@ private void fixFederationClientForRemoval(ObjectMap parameters) {
}
List<Document> federationParamList = new LinkedList<>();
for (Object federationClient : parameters.getAsList(QueryParams.FEDERATION_CLIENTS.key())) {
if (federationClient instanceof FederationServerParams) {
federationParamList.add(new Document("id", ((FederationServerParams) federationClient).getId()));
if (federationClient instanceof FederationClientParams) {
federationParamList.add(new Document("id", ((FederationClientParams) federationClient).getId()));
} else {
federationParamList.add(new Document("id", ((Map) federationClient).get("id")));
}
}
parameters.putNested(QueryParams.FEDERATION_CLIENTS.key(), federationParamList, false);
parameters.put(QueryParams.FEDERATION_CLIENTS.key(), federationParamList, false);
}

private void fixFederationServerForRemoval(ObjectMap parameters) {
@@ -433,13 +433,13 @@ private void fixFederationServerForRemoval(ObjectMap parameters) {
}
List<Document> federationParamList = new LinkedList<>();
for (Object federationServer : parameters.getAsList(QueryParams.FEDERATION_SERVERS.key())) {
if (federationServer instanceof FederationClientParams) {
federationParamList.add(new Document("id", ((FederationClientParams) federationServer).getId()));
if (federationServer instanceof FederationServerParams) {
federationParamList.add(new Document("id", ((FederationServerParams) federationServer).getId()));
} else {
federationParamList.add(new Document("id", ((Map) federationServer).get("id")));
}
}
parameters.putNested(QueryParams.FEDERATION_SERVERS.key(), federationParamList, false);
parameters.put(QueryParams.FEDERATION_SERVERS.key(), federationParamList, false);
}

private void fixAuthOriginsForRemoval(ObjectMap parameters) {
Original file line number Diff line number Diff line change
@@ -492,7 +492,7 @@ OpenCGAResult<Group> removeUsersFromAdminsGroup(ClientSession clientSession, Lis

@Override
public OpenCGAResult<Group> removeUsersFromAllGroups(long studyId, List<String> users) throws CatalogException {
if (users == null || users.size() == 0) {
if (CollectionUtils.isEmpty(users)) {
throw new CatalogDBException("Unable to remove users from groups. List of users is empty");
}

@@ -507,7 +507,7 @@ public OpenCGAResult<Group> removeUsersFromAllGroups(long studyId, List<String>
Bson pull = Updates.pullAll("groups.$.userIds", users);

// Pull those users while they are still there
DataResult update;
DataResult<?> update;
do {
update = studyCollection.update(clientSession, query, pull, null);
} while (update.getNumUpdated() > 0);
@@ -520,6 +520,36 @@ public OpenCGAResult<Group> removeUsersFromAllGroups(long studyId, List<String>
}
}

@Override
public OpenCGAResult<Group> removeUsersFromAllGroups(List<String> users) throws CatalogException {
if (CollectionUtils.isEmpty(users)) {
throw new CatalogDBException("Unable to remove users from groups. List of users is empty");
}

try {
return runTransaction(clientSession -> {
long tmpStartTime = startQuery();
logger.debug("Removing list of users '{}' from all groups from all studies", users);

Document query = new Document()
.append(QueryParams.GROUP_USER_IDS.key(), new Document("$in", users));
Bson pull = Updates.pullAll("groups.$.userIds", users);

QueryOptions multi = new QueryOptions(MongoDBCollection.MULTI, true);
// Pull those users while they are still there
DataResult<?> update;
do {
update = studyCollection.update(clientSession, query, pull, multi);
} while (update.getNumUpdated() > 0);

return endWrite(tmpStartTime, -1, -1, null);
});
} catch (Exception e) {
logger.error("Could not remove users from all groups from all studies. {}", e.getMessage());
throw e;
}
}

@Override
public OpenCGAResult<Group> deleteGroup(long studyId, String groupId) throws CatalogDBException {
Bson queryBson = new Document()