@oneuptime/common 8.0.5300 → 8.0.5310
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import CreateBy from "../Types/Database/CreateBy";
|
|
1
2
|
import DeleteBy from "../Types/Database/DeleteBy";
|
|
2
|
-
import { OnDelete, OnUpdate } from "../Types/Database/Hooks";
|
|
3
|
+
import { OnCreate, OnDelete, OnUpdate } from "../Types/Database/Hooks";
|
|
3
4
|
import UpdateBy from "../Types/Database/UpdateBy";
|
|
4
5
|
import DatabaseService from "./DatabaseService";
|
|
5
6
|
import LIMIT_MAX from "../../Types/Database/LimitMax";
|
|
@@ -7,8 +8,10 @@ import BadDataException from "../../Types/Exception/BadDataException";
|
|
|
7
8
|
import Model from "../../Models/DatabaseModels/Team";
|
|
8
9
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
9
10
|
import ObjectID from "../../Types/ObjectID";
|
|
11
|
+
import PositiveNumber from "../../Types/PositiveNumber";
|
|
10
12
|
import TeamMember from "../../Models/DatabaseModels/TeamMember";
|
|
11
13
|
import TeamMemberService from "./TeamMemberService";
|
|
14
|
+
import ProjectSCIMService from "./ProjectSCIMService";
|
|
12
15
|
|
|
13
16
|
export class Service extends DatabaseService<Model> {
|
|
14
17
|
public constructor() {
|
|
@@ -48,6 +51,70 @@ export class Service extends DatabaseService<Model> {
|
|
|
48
51
|
return teams;
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
private async assertScimAllowsTeamMutation(data: {
|
|
55
|
+
projectIds: Array<ObjectID>;
|
|
56
|
+
action: "create" | "delete";
|
|
57
|
+
}): Promise<void> {
|
|
58
|
+
if (!data.projectIds || data.projectIds.length === 0) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const uniqueProjectIds: Map<string, ObjectID> = new Map();
|
|
63
|
+
|
|
64
|
+
for (const projectId of data.projectIds) {
|
|
65
|
+
if (projectId) {
|
|
66
|
+
uniqueProjectIds.set(projectId.toString(), new ObjectID(projectId));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (const projectId of uniqueProjectIds.values()) {
|
|
71
|
+
const scimCount: PositiveNumber = await ProjectSCIMService.countBy({
|
|
72
|
+
query: {
|
|
73
|
+
projectId: projectId,
|
|
74
|
+
},
|
|
75
|
+
skip: new PositiveNumber(0),
|
|
76
|
+
limit: new PositiveNumber(1),
|
|
77
|
+
props: {
|
|
78
|
+
isRoot: true,
|
|
79
|
+
tenantId: projectId,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (scimCount.toNumber() > 0) {
|
|
84
|
+
throw new BadDataException(
|
|
85
|
+
`Cannot ${data.action} teams when SCIM is enabled for this project.`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@CaptureSpan()
|
|
92
|
+
protected override async onBeforeCreate(
|
|
93
|
+
createBy: CreateBy<Model>,
|
|
94
|
+
): Promise<OnCreate<Model>> {
|
|
95
|
+
let projectId: ObjectID | undefined = createBy.data.projectId;
|
|
96
|
+
|
|
97
|
+
if (!projectId && createBy.props.tenantId) {
|
|
98
|
+
projectId = new ObjectID(createBy.props.tenantId);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!projectId) {
|
|
102
|
+
throw new BadDataException("Project ID cannot be null");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
projectId = new ObjectID(projectId);
|
|
106
|
+
createBy.data.projectId = projectId;
|
|
107
|
+
|
|
108
|
+
if (!createBy.props.isRoot) {
|
|
109
|
+
await this.assertScimAllowsTeamMutation({
|
|
110
|
+
projectIds: [projectId],
|
|
111
|
+
action: "create",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { createBy, carryForward: null };
|
|
116
|
+
}
|
|
117
|
+
|
|
51
118
|
@CaptureSpan()
|
|
52
119
|
protected override async onBeforeUpdate(
|
|
53
120
|
updateBy: UpdateBy<Model>,
|
|
@@ -90,11 +157,27 @@ export class Service extends DatabaseService<Model> {
|
|
|
90
157
|
select: {
|
|
91
158
|
name: true,
|
|
92
159
|
isTeamDeleteable: true,
|
|
160
|
+
projectId: true,
|
|
93
161
|
},
|
|
94
162
|
|
|
95
163
|
props: deleteBy.props,
|
|
96
164
|
});
|
|
97
165
|
|
|
166
|
+
const projectIds: Array<ObjectID> = teams
|
|
167
|
+
.map((team: Model) => {
|
|
168
|
+
return team.projectId;
|
|
169
|
+
})
|
|
170
|
+
.filter((projectId: ObjectID | undefined): projectId is ObjectID => {
|
|
171
|
+
return Boolean(projectId);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
if (deleteBy.props.isRoot !== true) {
|
|
175
|
+
await this.assertScimAllowsTeamMutation({
|
|
176
|
+
projectIds: projectIds,
|
|
177
|
+
action: "delete",
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
98
181
|
for (const team of teams) {
|
|
99
182
|
if (!team.isTeamDeleteable) {
|
|
100
183
|
throw new BadDataException(
|
|
@@ -12,7 +12,10 @@ import LIMIT_MAX from "../../Types/Database/LimitMax";
|
|
|
12
12
|
import BadDataException from "../../Types/Exception/BadDataException";
|
|
13
13
|
import Model from "../../Models/DatabaseModels/Team";
|
|
14
14
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
15
|
+
import ObjectID from "../../Types/ObjectID";
|
|
16
|
+
import PositiveNumber from "../../Types/PositiveNumber";
|
|
15
17
|
import TeamMemberService from "./TeamMemberService";
|
|
18
|
+
import ProjectSCIMService from "./ProjectSCIMService";
|
|
16
19
|
export class Service extends DatabaseService {
|
|
17
20
|
constructor() {
|
|
18
21
|
super(Model);
|
|
@@ -43,6 +46,51 @@ export class Service extends DatabaseService {
|
|
|
43
46
|
}
|
|
44
47
|
return teams;
|
|
45
48
|
}
|
|
49
|
+
async assertScimAllowsTeamMutation(data) {
|
|
50
|
+
if (!data.projectIds || data.projectIds.length === 0) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const uniqueProjectIds = new Map();
|
|
54
|
+
for (const projectId of data.projectIds) {
|
|
55
|
+
if (projectId) {
|
|
56
|
+
uniqueProjectIds.set(projectId.toString(), new ObjectID(projectId));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const projectId of uniqueProjectIds.values()) {
|
|
60
|
+
const scimCount = await ProjectSCIMService.countBy({
|
|
61
|
+
query: {
|
|
62
|
+
projectId: projectId,
|
|
63
|
+
},
|
|
64
|
+
skip: new PositiveNumber(0),
|
|
65
|
+
limit: new PositiveNumber(1),
|
|
66
|
+
props: {
|
|
67
|
+
isRoot: true,
|
|
68
|
+
tenantId: projectId,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
if (scimCount.toNumber() > 0) {
|
|
72
|
+
throw new BadDataException(`Cannot ${data.action} teams when SCIM is enabled for this project.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async onBeforeCreate(createBy) {
|
|
77
|
+
let projectId = createBy.data.projectId;
|
|
78
|
+
if (!projectId && createBy.props.tenantId) {
|
|
79
|
+
projectId = new ObjectID(createBy.props.tenantId);
|
|
80
|
+
}
|
|
81
|
+
if (!projectId) {
|
|
82
|
+
throw new BadDataException("Project ID cannot be null");
|
|
83
|
+
}
|
|
84
|
+
projectId = new ObjectID(projectId);
|
|
85
|
+
createBy.data.projectId = projectId;
|
|
86
|
+
if (!createBy.props.isRoot) {
|
|
87
|
+
await this.assertScimAllowsTeamMutation({
|
|
88
|
+
projectIds: [projectId],
|
|
89
|
+
action: "create",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return { createBy, carryForward: null };
|
|
93
|
+
}
|
|
46
94
|
async onBeforeUpdate(updateBy) {
|
|
47
95
|
// get teams by query.
|
|
48
96
|
const teams = await this.findBy({
|
|
@@ -70,9 +118,23 @@ export class Service extends DatabaseService {
|
|
|
70
118
|
select: {
|
|
71
119
|
name: true,
|
|
72
120
|
isTeamDeleteable: true,
|
|
121
|
+
projectId: true,
|
|
73
122
|
},
|
|
74
123
|
props: deleteBy.props,
|
|
75
124
|
});
|
|
125
|
+
const projectIds = teams
|
|
126
|
+
.map((team) => {
|
|
127
|
+
return team.projectId;
|
|
128
|
+
})
|
|
129
|
+
.filter((projectId) => {
|
|
130
|
+
return Boolean(projectId);
|
|
131
|
+
});
|
|
132
|
+
if (deleteBy.props.isRoot !== true) {
|
|
133
|
+
await this.assertScimAllowsTeamMutation({
|
|
134
|
+
projectIds: projectIds,
|
|
135
|
+
action: "delete",
|
|
136
|
+
});
|
|
137
|
+
}
|
|
76
138
|
for (const team of teams) {
|
|
77
139
|
if (!team.isTeamDeleteable) {
|
|
78
140
|
throw new BadDataException(`${team.name || "This"} team cannot be deleted its a critical team for this project.`);
|
|
@@ -81,6 +143,12 @@ export class Service extends DatabaseService {
|
|
|
81
143
|
return { deleteBy, carryForward: null };
|
|
82
144
|
}
|
|
83
145
|
}
|
|
146
|
+
__decorate([
|
|
147
|
+
CaptureSpan(),
|
|
148
|
+
__metadata("design:type", Function),
|
|
149
|
+
__metadata("design:paramtypes", [Object]),
|
|
150
|
+
__metadata("design:returntype", Promise)
|
|
151
|
+
], Service.prototype, "onBeforeCreate", null);
|
|
84
152
|
__decorate([
|
|
85
153
|
CaptureSpan(),
|
|
86
154
|
__metadata("design:type", Function),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TeamService.js","sourceRoot":"","sources":["../../../../Server/Services/TeamService.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"TeamService.js","sourceRoot":"","sources":["../../../../Server/Services/TeamService.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,SAAS,MAAM,+BAA+B,CAAC;AACtD,O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,MAAM,UAAU,GAAoB,KAAK;aACtC,GAAG,CAAC,CAAC,IAAW,EAAE,EAAE;YACnB,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,SAA+B,EAAyB,EAAE;YACjE,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEL,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACnC,MAAM,IAAI,CAAC,4BAA4B,CAAC;gBACtC,UAAU,EAAE,UAAU;gBACtB,MAAM,EAAE,QAAQ;aACjB,CAAC,CAAC;QACL,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAC3B,MAAM,IAAI,gBAAgB,CACxB,GACE,IAAI,CAAC,IAAI,IAAI,MACf,+DAA+D,CAChE,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF;AArG0B;IADxB,WAAW,EAAE;;;;6CAyBb;AAGwB;IADxB,WAAW,EAAE;;;;6CA6Bb;AAGwB;IADxB,WAAW,EAAE;;;;6CA2Cb;AAEH,eAAe,IAAI,OAAO,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneuptime/common",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.5310",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@opentelemetry/sdk-trace-web": "^1.25.1",
|
|
69
69
|
"@opentelemetry/semantic-conventions": "^1.26.0",
|
|
70
70
|
"@remixicon/react": "^4.2.0",
|
|
71
|
-
"@simplewebauthn/server": "^13.2.
|
|
71
|
+
"@simplewebauthn/server": "^13.2.2",
|
|
72
72
|
"@tippyjs/react": "^4.2.6",
|
|
73
73
|
"@types/archiver": "^6.0.3",
|
|
74
74
|
"@types/crypto-js": "^4.2.2",
|