Skip to content

Commit

Permalink
fix v3 dataset controller access filters
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-trajanovski committed Dec 13, 2024
1 parent 3b0ef0b commit 8432254
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,32 @@ export class DatasetsController {

if (!canViewAny) {
if (canViewAccess) {
// FIXME: This here doesn't work if we want to pass $or in the original query itself. This is overwriting it! Double-check it!
// Here is an example: { "where": { "$or": [{"datasetName": "test"}, {"description": "Dataset"}] }} gets overwritten with: {"where":{"$or":[{"ownerGroup":{"$in":["group1","ess","swap"]}},{"accessGroups":{"$in":["group1","ess","swap"]}},{"sharedWith":{"$in":"[email protected]"}},{"isPublished":true}]}}
mergedFilters.where["$or"] = [
{ ownerGroup: { $in: user.currentGroups } },
{ accessGroups: { $in: user.currentGroups } },
{ sharedWith: { $in: user.email } },
{ isPublished: true },
];
if (mergedFilters.where["$and"]) {
mergedFilters.where["$and"].push({
$or: [
{ ownerGroup: { $in: user.currentGroups } },
{ accessGroups: { $in: user.currentGroups } },
{ sharedWith: { $in: [user.email] } },
{ isPublished: true },
],
});
} else {
mergedFilters.where["$and"] = [
{
$or: [
{ ownerGroup: { $in: user.currentGroups } },
{ accessGroups: { $in: user.currentGroups } },
{ sharedWith: { $in: [user.email] } },
{ isPublished: true },
],
},
];
}
} else if (canViewOwner) {
mergedFilters.where = [{ ownerGroup: { $in: user.currentGroups } }];
mergedFilters.where = {
...mergedFilters.where,
ownerGroup: { $in: user.currentGroups },
};
} else if (canViewPublic) {
mergedFilters.where = { isPublished: true };
}
Expand Down

0 comments on commit 8432254

Please sign in to comment.