Skip to content

Commit 9c099a7

Browse files
authored
Merge branch 'SciCatProject:master' into master
2 parents 02301a9 + c40c823 commit 9c099a7

22 files changed

+2135
-233
lines changed

package-lock.json

Lines changed: 30 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datasets/datasets-access.service.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ProposalClass } from "src/proposals/schemas/proposal.schema";
1010
import { Instrument } from "src/instruments/schemas/instrument.schema";
1111
import { OrigDatablock } from "src/origdatablocks/schemas/origdatablock.schema";
1212
import { SampleClass } from "src/samples/schemas/sample.schema";
13-
import { Datablock } from "src/datablocks/schemas/datablock.schema";
1413
import { DatasetClass } from "./schemas/dataset.schema";
1514

1615
@Injectable({ scope: Scope.REQUEST })
@@ -66,19 +65,19 @@ export class DatasetsAccessService {
6665
const ability = this.caslAbilityFactory.datasetInstanceAccess(user);
6766
const canViewAny = ability.can(
6867
Action.DatasetDatablockReadAny,
69-
Datablock,
68+
DatasetClass,
7069
);
7170
const canViewAccess = ability.can(
7271
Action.DatasetDatablockReadAccess,
73-
Datablock,
72+
DatasetClass,
7473
);
7574
const canViewOwner = ability.can(
7675
Action.DatasetDatablockReadOwner,
77-
Datablock,
76+
DatasetClass,
7877
);
7978
const canViewPublic = ability.can(
8079
Action.DatasetDatablockReadPublic,
81-
Datablock,
80+
DatasetClass,
8281
);
8382

8483
return { canViewAny, canViewOwner, canViewAccess, canViewPublic };
@@ -147,10 +146,8 @@ export class DatasetsAccessService {
147146
fieldValue.$lookup.as as DatasetLookupKeysEnum,
148147
currentUser,
149148
);
150-
151149
if (access) {
152150
const { canViewAny, canViewAccess, canViewOwner } = access;
153-
154151
if (!canViewAny) {
155152
if (canViewAccess) {
156153
fieldValue.$lookup.pipeline = [
@@ -185,4 +182,42 @@ export class DatasetsAccessService {
185182
}
186183
}
187184
}
185+
186+
addDatasetAccess(fieldValue: PipelineStage.Lookup) {
187+
const currentUser = this.request.user as JWTUser;
188+
const ability = this.caslAbilityFactory.datasetInstanceAccess(currentUser);
189+
const canViewAny = ability.can(Action.DatasetReadAny, DatasetClass);
190+
const canViewAccess = ability.can(
191+
Action.DatasetReadManyAccess,
192+
DatasetClass,
193+
);
194+
const canViewOwner = ability.can(Action.DatasetReadManyOwner, DatasetClass);
195+
196+
if (!canViewAny) {
197+
if (canViewAccess) {
198+
fieldValue.$lookup.pipeline?.unshift({
199+
$match: {
200+
$or: [
201+
{ ownerGroup: { $in: currentUser.currentGroups } },
202+
{ accessGroups: { $in: currentUser.currentGroups } },
203+
{ sharedWith: { $in: [currentUser.email] } },
204+
{ isPublished: true },
205+
],
206+
},
207+
});
208+
} else if (canViewOwner) {
209+
fieldValue.$lookup.pipeline?.unshift({
210+
$match: {
211+
ownerGroup: { $in: currentUser.currentGroups },
212+
},
213+
});
214+
} else {
215+
fieldValue.$lookup.pipeline?.unshift({
216+
$match: {
217+
isPublished: true,
218+
},
219+
});
220+
}
221+
}
222+
}
188223
}

src/datasets/datasets.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import { CaslModule } from "src/casl/casl.module";
6767
]),
6868
HttpModule,
6969
],
70-
exports: [DatasetsService],
70+
exports: [DatasetsService, DatasetsAccessService],
7171
controllers: [
7272
DatasetsPublicV4Controller,
7373
DatasetsController,

src/datasets/types/dataset-lookup.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export enum DatasetLookupKeysEnum {
1111
all = "all",
1212
}
1313

14+
export enum DatasetArchiverLookupKeysEnum {
15+
origdatablocks = "origdatablocks",
16+
datablocks = "datablocks",
17+
attachments = "attachments",
18+
}
19+
1420
export const DATASET_LOOKUP_FIELDS: Record<
1521
DatasetLookupKeysEnum,
1622
PipelineStage.Lookup | undefined

src/jobs/dto/output-job-v3.dto.ts

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,52 @@
1-
import { ApiHideProperty, ApiProperty } from "@nestjs/swagger";
1+
import { ApiHideProperty } from "@nestjs/swagger";
22
import { DatasetListDto } from "./dataset-list.dto";
33

44
export class OutputJobV3Dto {
55
@ApiHideProperty()
66
_id: string;
77

8-
@ApiProperty({
9-
type: String,
10-
required: true,
11-
description: "Globally unique identifier of a job.",
12-
})
8+
/**
9+
* Globally unique identifier of a job.
10+
*/
1311
id: string;
1412

15-
@ApiProperty({
16-
type: String,
17-
required: false,
18-
description: "The email of the person initiating the job request.",
19-
})
13+
/**
14+
* The email of the person initiating the job request.
15+
*/
2016
emailJobInitiator?: string;
2117

22-
@ApiProperty({
23-
type: String,
24-
required: true,
25-
description: "Type of job, e.g. archive, retrieve etc.",
26-
})
18+
/**
19+
* Type of job, e.g. archive, retrieve etc.
20+
*/
2721
type: string;
2822

29-
@ApiProperty({
30-
type: Date,
31-
required: true,
32-
description:
33-
"Time when job is created. Format according to chapter 5.6 internet date/time format in RFC 3339. This is handled automatically by mongoose with timestamps flag.",
34-
})
23+
/**
24+
* Time when job is created. Format according to chapter 5.6 internet date/time format in RFC 3339. This is handled automatically by mongoose with timestamps flag.
25+
*/
3526
creationTime: Date;
3627

37-
@ApiProperty({
38-
type: Date,
39-
required: false,
40-
description:
41-
"Time when job should be executed. If not specified then the Job will be executed asap. Format according to chapter 5.6 internet date/time format in RFC 3339.",
42-
})
28+
/**
29+
* Time when job should be executed. If not specified then the Job will be executed asap. Format according to chapter 5.6 internet date/time format in RFC 3339.
30+
*/
4331
executionTime?: Date;
4432

45-
@ApiProperty({
46-
type: Object,
47-
required: true,
48-
default: {},
49-
description:
50-
"Object of key-value pairs defining job input parameters, e.g. 'destinationPath' for retrieve jobs or 'tapeCopies' for archive jobs.",
51-
})
33+
/**
34+
* Object of key-value pairs defining job input parameters, e.g. 'destinationPath' for retrieve jobs or 'tapeCopies' for archive jobs.
35+
*/
5236
jobParams: Record<string, unknown>;
5337

54-
@ApiProperty({
55-
type: String,
56-
required: false,
57-
description: "Defines current status of job lifecycle.",
58-
})
38+
/**
39+
* Defines current status of job lifecycle.
40+
*/
5941
jobStatusMessage?: string;
6042

61-
@ApiProperty({
62-
type: [DatasetListDto],
63-
required: false,
64-
description:
65-
"Array of objects with keys: pid, files. The value for the pid key defines the dataset ID, the value for the files key is an array of file names. This array is either an empty array, implying that all files within the dataset are selected, or an explicit list of dataset-relative file paths, which should be selected.",
66-
})
43+
/**
44+
* Array of objects with keys: pid, files. The value for the pid key defines the dataset ID, the value for the files key is an array of file names. This array is either an empty array, implying that all files within the dataset are selected, or an explicit list of dataset-relative file paths, which should be selected.
45+
*/
6746
datasetList: DatasetListDto[];
6847

69-
@ApiProperty({
70-
type: Object,
71-
required: true,
72-
default: {},
73-
description: "Detailed return value after job is finished.",
74-
})
48+
/**
49+
* Detailed return value after job is finished.
50+
*/
7551
jobResultObject: Record<string, unknown>;
7652
}

0 commit comments

Comments
 (0)