-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix v3 dataset controller access filters
- Loading branch information
1 parent
3b0ef0b
commit 8432254
Showing
1 changed file
with
25 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }; | ||
} | ||
|