@webda/core 2.0.0-beta.2 → 2.0.1
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.
- package/lib/application.d.ts +5 -21
- package/lib/application.js +71 -84
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +121 -140
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +44 -45
- package/lib/core.js +239 -320
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +326 -391
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -45
- package/lib/index.js +54 -67
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +2 -2
- package/lib/models/aclmodel.js +63 -90
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +128 -151
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +39 -17
- package/lib/models/coremodel.js +160 -117
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +143 -107
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +3 -3
- package/lib/models/ident.js +4 -9
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js +9 -11
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/ownermodel.d.ts +2 -2
- package/lib/models/ownermodel.js +39 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +126 -166
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +2 -2
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -61
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +9 -9
- package/lib/models/user.js +3 -8
- package/lib/models/user.js.map +1 -1
- package/lib/models/user.spec.js +14 -16
- package/lib/models/user.spec.js.map +1 -1
- package/lib/queues/filequeue.d.ts +2 -2
- package/lib/queues/filequeue.js +72 -93
- package/lib/queues/filequeue.js.map +1 -1
- package/lib/queues/filequeue.spec.js +53 -70
- package/lib/queues/filequeue.spec.js.map +1 -1
- package/lib/queues/memoryqueue.d.ts +2 -2
- package/lib/queues/memoryqueue.js +37 -61
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/memoryqueue.spec.js +142 -165
- package/lib/queues/memoryqueue.spec.js.map +1 -1
- package/lib/queues/pubsubservice.d.ts +2 -2
- package/lib/queues/pubsubservice.js +3 -7
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queue.spec.d.ts +1 -1
- package/lib/queues/queue.spec.js +42 -56
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.d.ts +4 -4
- package/lib/queues/queueservice.js +52 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +3 -3
- package/lib/router.js +46 -47
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +64 -61
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +2 -2
- package/lib/services/asyncevents.js +44 -64
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/asyncevents.spec.js +81 -98
- package/lib/services/asyncevents.spec.js.map +1 -1
- package/lib/services/authentication.d.ts +28 -19
- package/lib/services/authentication.js +542 -574
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +411 -447
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +9 -7
- package/lib/services/binary.js +213 -245
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +3 -3
- package/lib/services/binary.spec.js +390 -443
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +3 -3
- package/lib/services/cloudbinary.js +45 -70
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/cloudbinary.spec.d.ts +3 -3
- package/lib/services/cloudbinary.spec.js +133 -162
- package/lib/services/cloudbinary.spec.js.map +1 -1
- package/lib/services/configuration.d.ts +6 -3
- package/lib/services/configuration.js +78 -103
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +63 -83
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +3 -2
- package/lib/services/cron.js +9 -13
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.js +18 -21
- package/lib/services/cron.spec.js.map +1 -1
- package/lib/services/cryptoservice.d.ts +258 -0
- package/lib/services/cryptoservice.js +312 -0
- package/lib/services/cryptoservice.js.map +1 -0
- package/lib/services/cryptoservice.spec.d.ts +1 -0
- package/lib/services/cryptoservice.spec.js +137 -0
- package/lib/services/cryptoservice.spec.js.map +1 -0
- package/lib/services/debugmailer.d.ts +1 -1
- package/lib/services/debugmailer.js +13 -34
- package/lib/services/debugmailer.js.map +1 -1
- package/lib/services/debugmailer.spec.js +16 -29
- package/lib/services/debugmailer.spec.js.map +1 -1
- package/lib/services/echo.d.ts +2 -2
- package/lib/services/echo.js +15 -31
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.js +27 -40
- package/lib/services/echo.spec.js.map +1 -1
- package/lib/services/filebinary.d.ts +10 -5
- package/lib/services/filebinary.js +171 -205
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -117
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +2 -2
- package/lib/services/fileconfiguration.js +25 -43
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/fileconfiguration.spec.js +79 -109
- package/lib/services/fileconfiguration.spec.js.map +1 -1
- package/lib/services/invitationservice.d.ts +10 -10
- package/lib/services/invitationservice.js +275 -313
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +443 -449
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +2 -2
- package/lib/services/kubernetesconfiguration.js +41 -59
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +80 -98
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +4 -4
- package/lib/services/mailer.js +62 -86
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/mailer.spec.js +86 -127
- package/lib/services/mailer.spec.js.map +1 -1
- package/lib/services/notificationservice.d.ts +4 -4
- package/lib/services/notificationservice.js +23 -42
- package/lib/services/notificationservice.js.map +1 -1
- package/lib/services/notificationservice.spec.js +47 -73
- package/lib/services/notificationservice.spec.js.map +1 -1
- package/lib/services/oauth.d.ts +32 -6
- package/lib/services/oauth.js +73 -78
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +128 -148
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +74 -0
- package/lib/services/proxy.js +126 -0
- package/lib/services/proxy.js.map +1 -0
- package/lib/services/proxy.spec.d.ts +1 -0
- package/lib/services/proxy.spec.js +59 -0
- package/lib/services/proxy.spec.js.map +1 -0
- package/lib/services/resource.d.ts +2 -2
- package/lib/services/resource.js +12 -18
- package/lib/services/resource.js.map +1 -1
- package/lib/services/resource.spec.js +67 -99
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +29 -6
- package/lib/services/service.js +69 -39
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.js +62 -67
- package/lib/services/service.spec.js.map +1 -1
- package/lib/services/version.d.ts +1 -1
- package/lib/services/version.js +3 -8
- package/lib/services/version.js.map +1 -1
- package/lib/services/version.spec.js +11 -24
- package/lib/services/version.spec.js.map +1 -1
- package/lib/stores/aggregator.d.ts +3 -3
- package/lib/stores/aggregator.js +37 -57
- package/lib/stores/aggregator.js.map +1 -1
- package/lib/stores/file.d.ts +3 -3
- package/lib/stores/file.js +93 -131
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.d.ts +2 -2
- package/lib/stores/file.spec.js +262 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +4 -4
- package/lib/stores/mapper.js +111 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +133 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +67 -6
- package/lib/stores/memory.js +155 -117
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +3 -2
- package/lib/stores/memory.spec.js +127 -105
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +40 -16
- package/lib/stores/store.js +847 -830
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +6 -4
- package/lib/stores/store.spec.js +628 -647
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
- package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
- package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
- package/lib/stores/webdaql/query.d.ts +4 -5
- package/lib/stores/webdaql/query.js +16 -19
- package/lib/stores/webdaql/query.js.map +1 -1
- package/lib/stores/webdaql/query.spec.js +30 -32
- package/lib/stores/webdaql/query.spec.js.map +1 -1
- package/lib/test.d.ts +3 -3
- package/lib/test.js +74 -94
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +44 -38
- package/lib/unpackedapplication.js.map +1 -1
- package/lib/utils/abstractdeployer.js +1 -5
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/lib/utils/abstractdeployer.spec.js +6 -8
- package/lib/utils/abstractdeployer.spec.js.map +1 -1
- package/lib/utils/context.d.ts +61 -29
- package/lib/utils/context.js +133 -127
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +144 -153
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +66 -45
- package/lib/utils/cookie.js +69 -158
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +220 -238
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/esm.d.ts +4 -0
- package/lib/utils/esm.js +10 -0
- package/lib/utils/esm.js.map +1 -0
- package/lib/utils/httpcontext.d.ts +3 -0
- package/lib/utils/httpcontext.js +48 -65
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -56
- package/lib/utils/httpcontext.spec.js.map +1 -1
- package/lib/utils/logger.d.ts +2 -2
- package/lib/utils/logger.js +15 -28
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js +9 -11
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +17 -20
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +43 -44
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/session.d.ts +120 -0
- package/lib/utils/session.js +155 -0
- package/lib/utils/session.js.map +1 -0
- package/lib/utils/session.spec.d.ts +1 -0
- package/lib/utils/session.spec.js +66 -0
- package/lib/utils/session.spec.js.map +1 -0
- package/lib/utils/waiter.d.ts +1 -1
- package/lib/utils/waiter.js +32 -52
- package/lib/utils/waiter.js.map +1 -1
- package/lib/utils/waiter.spec.js +75 -92
- package/lib/utils/waiter.spec.js.map +1 -1
- package/package.json +22 -14
- package/test/config-invitation.json +1 -3
- package/test/config.json +3 -3
- package/test/config.old.json +1 -2
- package/test/moddas/annotatedservice.js +5 -5
- package/test/moddas/debugmailer.js +2 -3
- package/test/moddas/fakeservice.js +2 -3
- package/test/moddas/voidstore.js +6 -4
- package/test/models/ident.js +2 -6
- package/test/models/task.js +3 -7
- package/test/package.json +2 -1
- package/webda.module.json +895 -189
|
@@ -1,69 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const sinon = require("sinon");
|
|
21
|
-
const aclmodel_1 = require("../models/aclmodel");
|
|
22
|
-
const test_1 = require("../test");
|
|
23
|
-
const invitationservice_1 = require("./invitationservice");
|
|
24
|
-
class MyCompany extends aclmodel_1.AclModel {
|
|
25
|
-
canAct(ctx, action) {
|
|
26
|
-
const _super = Object.create(null, {
|
|
27
|
-
canAct: { get: () => super.canAct }
|
|
28
|
-
});
|
|
29
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
if (action === "create") {
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
return _super.canAct.call(this, ctx, action);
|
|
34
|
-
});
|
|
7
|
+
import { suite, test } from "@testdeck/mocha";
|
|
8
|
+
import * as assert from "assert";
|
|
9
|
+
import * as sinon from "sinon";
|
|
10
|
+
import { AclModel } from "../models/aclmodel.js";
|
|
11
|
+
import { WebdaTest } from "../test.js";
|
|
12
|
+
import InvitationService, { InvitationParameters } from "./invitationservice.js";
|
|
13
|
+
class MyCompany extends AclModel {
|
|
14
|
+
async canAct(ctx, action) {
|
|
15
|
+
if (action === "create") {
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
return super.canAct(ctx, action);
|
|
35
19
|
}
|
|
36
20
|
}
|
|
37
|
-
let InvitationTest = class InvitationTest extends
|
|
21
|
+
let InvitationTest = class InvitationTest extends WebdaTest {
|
|
38
22
|
getTestConfiguration() {
|
|
39
23
|
return process.cwd() + "/test/config-invitation.json";
|
|
40
24
|
}
|
|
41
|
-
before() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
mapAttribute: "_companies",
|
|
52
|
-
pendingAttribute: "__invitations",
|
|
53
|
-
notificationService: "DebugMailer",
|
|
54
|
-
mapFields: ["name"]
|
|
55
|
-
});
|
|
56
|
-
this.webda.getServices()["invit"] = this.service;
|
|
57
|
-
this.store = this.webda.getService("Companies");
|
|
58
|
-
this.store._model = MyCompany;
|
|
59
|
-
this.invitations = this.webda.getService("Invitations");
|
|
60
|
-
this.authentication = this.webda.getService("Authentication");
|
|
61
|
-
this.mailer = this.webda.getService("DebugMailer");
|
|
62
|
-
this.service.resolve();
|
|
25
|
+
async before() {
|
|
26
|
+
await super.before();
|
|
27
|
+
this.service = new InvitationService(this.webda, "invit", {
|
|
28
|
+
modelStore: "Companies",
|
|
29
|
+
invitationStore: "Invitations",
|
|
30
|
+
attribute: "__acl",
|
|
31
|
+
mapAttribute: "_companies",
|
|
32
|
+
pendingAttribute: "__invitations",
|
|
33
|
+
notificationService: "DebugMailer",
|
|
34
|
+
mapFields: ["name"]
|
|
63
35
|
});
|
|
36
|
+
this.webda.getServices()["invit"] = this.service;
|
|
37
|
+
this.store = this.webda.getService("Companies");
|
|
38
|
+
this.store._model = MyCompany;
|
|
39
|
+
this.invitations = this.webda.getService("Invitations");
|
|
40
|
+
this.authentication = this.webda.getService("Authentication");
|
|
41
|
+
this.mailer = this.webda.getService("DebugMailer");
|
|
42
|
+
await this.service.resolve().init();
|
|
64
43
|
}
|
|
65
44
|
params() {
|
|
66
|
-
let p = new
|
|
45
|
+
let p = new InvitationParameters({
|
|
67
46
|
mapFields: "test,test2",
|
|
68
47
|
attribute: "_attr"
|
|
69
48
|
});
|
|
@@ -71,447 +50,462 @@ let InvitationTest = class InvitationTest extends test_1.WebdaTest {
|
|
|
71
50
|
assert.strictEqual(p.pendingAttribute, "_attrPending");
|
|
72
51
|
assert.strictEqual(p.multiple, true);
|
|
73
52
|
assert.strictEqual(p.authenticationService, "Authentication");
|
|
74
|
-
assert.throws(() => new
|
|
53
|
+
assert.throws(() => new InvitationParameters({
|
|
75
54
|
attribute: "plop"
|
|
76
55
|
}), /needs to start with a _/);
|
|
77
|
-
assert.throws(() => new
|
|
56
|
+
assert.throws(() => new InvitationParameters({
|
|
78
57
|
attribute: "_plop",
|
|
79
58
|
pendingAttribute: "bouzouf"
|
|
80
59
|
}), /needs to start with a _/);
|
|
81
|
-
assert.throws(() => new
|
|
60
|
+
assert.throws(() => new InvitationParameters({
|
|
82
61
|
autoAccept: true,
|
|
83
62
|
multiple: false,
|
|
84
63
|
fields: "test,test2",
|
|
85
64
|
attribute: "_attr"
|
|
86
65
|
}), /You cannot have multiple=false with autoAccept=true/);
|
|
87
66
|
}
|
|
88
|
-
initNoTemplate() {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
});
|
|
67
|
+
async initNoTemplate() {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
let stub = sinon.stub(this.mailer, "hasNotification").callsFake(async () => false);
|
|
70
|
+
try {
|
|
71
|
+
this.service.getParameters().notification = "plop";
|
|
72
|
+
await assert.rejects(() => this.service.init(), /Email template should exist/);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
stub.restore();
|
|
76
|
+
}
|
|
100
77
|
}
|
|
101
|
-
inviteOnMissing() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
yield assert.rejects(() => this.execute(ctx, "test.webda.io", "POST", `/companies/unknown/invitations`, {}), /404/);
|
|
105
|
-
});
|
|
78
|
+
async inviteOnMissing() {
|
|
79
|
+
let ctx = await this.newContext();
|
|
80
|
+
await assert.rejects(() => this.execute(ctx, "test.webda.io", "POST", `/companies/unknown/invitations`, {}), /404/);
|
|
106
81
|
}
|
|
107
|
-
inviteOnAclWithAutoAccept() {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
{
|
|
154
|
-
uuid: "test4@webda.io_email_invit",
|
|
155
|
-
metadata: "read",
|
|
156
|
-
inviter: {
|
|
157
|
-
uuid: user.getUuid(),
|
|
158
|
-
displayName: "Webda.io Test"
|
|
159
|
-
}
|
|
82
|
+
async inviteOnAclWithAutoAccept() {
|
|
83
|
+
this.service.getParameters().autoAccept = true;
|
|
84
|
+
this.service.getParameters().notification = "COMPANY_INVITE";
|
|
85
|
+
sinon.stub(this.service.notificationService, "sendNotification").callsFake(async () => { });
|
|
86
|
+
// New model as owner
|
|
87
|
+
let ctx = await this.newContext();
|
|
88
|
+
let user = await this.authentication.getUserStore().save({ displayName: "Webda.io Test" });
|
|
89
|
+
ctx.getSession().userId = user.getUuid();
|
|
90
|
+
let res = await this.execute(ctx, "test.webda.io", "POST", "/companies", { name: "MyTestCompany" });
|
|
91
|
+
const company = await this.store.get(res.uuid);
|
|
92
|
+
// Auto register 2 users
|
|
93
|
+
await this.authentication.createUserWithIdent("email", "test1@webda.io");
|
|
94
|
+
await this.authentication.createUserWithIdent("email", "test2@webda.io");
|
|
95
|
+
const ident1 = await this.authentication.getIdentStore().get(`test1@webda.io_email`);
|
|
96
|
+
const ident2 = await this.authentication.getIdentStore().get(`test2@webda.io_email`);
|
|
97
|
+
// Add four users to the ACL
|
|
98
|
+
// 2 unregistered , 2 registered
|
|
99
|
+
await this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
|
|
100
|
+
idents: ["test1@webda.io_email", "test3@webda.io_email", "test4@webda.io_email"],
|
|
101
|
+
users: [ident2.getUser(), "unknown"],
|
|
102
|
+
metadata: "read"
|
|
103
|
+
});
|
|
104
|
+
await company.refresh();
|
|
105
|
+
assert.deepStrictEqual(company.__acl, {
|
|
106
|
+
[ident1.getUser()]: "read",
|
|
107
|
+
[ident2.getUser()]: "read",
|
|
108
|
+
[user.getUuid()]: "all"
|
|
109
|
+
});
|
|
110
|
+
let getter = await this.execute(ctx, "test.webda.io", "GET", `/companies/${company.getUuid()}/invitations`);
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
assert.deepStrictEqual(company.__invitations, {
|
|
113
|
+
"ident_test3@webda.io_email": "read",
|
|
114
|
+
"ident_test4@webda.io_email": "read"
|
|
115
|
+
});
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
assert.deepStrictEqual(company.__invitations, getter);
|
|
118
|
+
assert.deepStrictEqual((await this.invitations.getAll()).map(i => ({
|
|
119
|
+
uuid: i.getUuid(),
|
|
120
|
+
...i[this.service.getInvitationAttribute(company.getUuid())]
|
|
121
|
+
})), [
|
|
122
|
+
{
|
|
123
|
+
uuid: "test3@webda.io_email_invit",
|
|
124
|
+
metadata: "read",
|
|
125
|
+
inviter: {
|
|
126
|
+
uuid: user.getUuid(),
|
|
127
|
+
displayName: "Webda.io Test"
|
|
160
128
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
yield company.refresh();
|
|
169
|
-
assert.deepStrictEqual(company.__acl, {
|
|
170
|
-
[ident1.getUser()]: "read,write",
|
|
171
|
-
[ident2.getUser()]: "read,write",
|
|
172
|
-
[user.getUuid()]: "all"
|
|
173
|
-
});
|
|
174
|
-
let userCheck = yield this.authentication.getUserStore().get(ident1.getUser());
|
|
175
|
-
assert.deepStrictEqual(userCheck["_companies"], [
|
|
176
|
-
{
|
|
177
|
-
inviter: {
|
|
178
|
-
displayName: "Webda.io Test",
|
|
179
|
-
uuid: user.getUuid()
|
|
180
|
-
},
|
|
181
|
-
metadata: {
|
|
182
|
-
name: "MyTestCompany"
|
|
183
|
-
},
|
|
184
|
-
model: company.getUuid(),
|
|
185
|
-
pending: false
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
uuid: "test4@webda.io_email_invit",
|
|
132
|
+
metadata: "read",
|
|
133
|
+
inviter: {
|
|
134
|
+
uuid: user.getUuid(),
|
|
135
|
+
displayName: "Webda.io Test"
|
|
186
136
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
137
|
+
}
|
|
138
|
+
]);
|
|
139
|
+
// Reinviting should be handled and metadata overwritten
|
|
140
|
+
await this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
|
|
141
|
+
idents: ["test2@webda.io_email", "test3@webda.io_email", "test4@webda.io_email"],
|
|
142
|
+
users: [ident1.getUser()],
|
|
143
|
+
metadata: "read,write"
|
|
144
|
+
});
|
|
145
|
+
await company.refresh();
|
|
146
|
+
assert.deepStrictEqual(company.__acl, {
|
|
147
|
+
[ident1.getUser()]: "read,write",
|
|
148
|
+
[ident2.getUser()]: "read,write",
|
|
149
|
+
[user.getUuid()]: "all"
|
|
150
|
+
});
|
|
151
|
+
let userCheck = await this.authentication.getUserStore().get(ident1.getUser());
|
|
152
|
+
assert.deepStrictEqual(userCheck["_companies"], [
|
|
153
|
+
{
|
|
154
|
+
inviter: {
|
|
155
|
+
displayName: "Webda.io Test",
|
|
156
|
+
uuid: user.getUuid()
|
|
157
|
+
},
|
|
158
|
+
metadata: {
|
|
159
|
+
name: "MyTestCompany"
|
|
201
160
|
},
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
161
|
+
model: company.getUuid(),
|
|
162
|
+
pending: false
|
|
163
|
+
}
|
|
164
|
+
]);
|
|
165
|
+
// @ts-ignore
|
|
166
|
+
assert.deepStrictEqual(company.__invitations, {
|
|
167
|
+
"ident_test3@webda.io_email": "read,write",
|
|
168
|
+
"ident_test4@webda.io_email": "read,write"
|
|
169
|
+
});
|
|
170
|
+
assert.deepStrictEqual((await this.invitations.getAll()).map(i => ({
|
|
171
|
+
uuid: i.getUuid(),
|
|
172
|
+
...i[this.service.getInvitationAttribute(company.getUuid())]
|
|
173
|
+
})), [
|
|
174
|
+
{
|
|
175
|
+
uuid: "test3@webda.io_email_invit",
|
|
176
|
+
metadata: "read,write",
|
|
177
|
+
inviter: {
|
|
178
|
+
uuid: user.getUuid(),
|
|
179
|
+
displayName: "Webda.io Test"
|
|
209
180
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
[ident2.getUser()]: "read,write",
|
|
218
|
-
[user.getUuid()]: "all"
|
|
219
|
-
});
|
|
220
|
-
// @ts-ignore
|
|
221
|
-
assert.deepStrictEqual(company.__invitations, {
|
|
222
|
-
"ident_test4@webda.io_email": "read,write"
|
|
223
|
-
});
|
|
224
|
-
assert.deepStrictEqual((yield this.invitations.getAll()).map(i => (Object.assign({ uuid: i.getUuid() }, i[this.service.getInvitationAttribute(company.getUuid())]))), [
|
|
225
|
-
{ uuid: "test3@webda.io_email_invit" },
|
|
226
|
-
{
|
|
227
|
-
uuid: "test4@webda.io_email_invit",
|
|
228
|
-
metadata: "read,write",
|
|
229
|
-
inviter: {
|
|
230
|
-
uuid: user.getUuid(),
|
|
231
|
-
displayName: "Webda.io Test"
|
|
232
|
-
}
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
uuid: "test4@webda.io_email_invit",
|
|
184
|
+
metadata: "read,write",
|
|
185
|
+
inviter: {
|
|
186
|
+
uuid: user.getUuid(),
|
|
187
|
+
displayName: "Webda.io Test"
|
|
233
188
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
displayName: "Webda.io Test",
|
|
261
|
-
uuid: user.getUuid()
|
|
262
|
-
},
|
|
263
|
-
metadata: {
|
|
264
|
-
name: "MyTestCompany"
|
|
265
|
-
},
|
|
266
|
-
model: company.getUuid(),
|
|
267
|
-
pending: false
|
|
189
|
+
}
|
|
190
|
+
]);
|
|
191
|
+
// Remove 1 unregistered and one registered from the ACL
|
|
192
|
+
await this.execute(ctx, "test.webda.io", "DELETE", `/companies/${company.getUuid()}/invitations`, {
|
|
193
|
+
idents: ["test1@webda.io_email", "test3@webda.io_email"]
|
|
194
|
+
});
|
|
195
|
+
await company.refresh();
|
|
196
|
+
assert.deepStrictEqual(company.__acl, {
|
|
197
|
+
[ident2.getUser()]: "read,write",
|
|
198
|
+
[user.getUuid()]: "all"
|
|
199
|
+
});
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
assert.deepStrictEqual(company.__invitations, {
|
|
202
|
+
"ident_test4@webda.io_email": "read,write"
|
|
203
|
+
});
|
|
204
|
+
assert.deepStrictEqual((await this.invitations.getAll()).map(i => ({
|
|
205
|
+
uuid: i.getUuid(),
|
|
206
|
+
...i[this.service.getInvitationAttribute(company.getUuid())]
|
|
207
|
+
})), [
|
|
208
|
+
{ uuid: "test3@webda.io_email_invit" },
|
|
209
|
+
{
|
|
210
|
+
uuid: "test4@webda.io_email_invit",
|
|
211
|
+
metadata: "read,write",
|
|
212
|
+
inviter: {
|
|
213
|
+
uuid: user.getUuid(),
|
|
214
|
+
displayName: "Webda.io Test"
|
|
268
215
|
}
|
|
269
|
-
|
|
216
|
+
}
|
|
217
|
+
]);
|
|
218
|
+
// Missing model
|
|
219
|
+
await this.invitations.setAttribute("test4@webda.io_email_invit", "invit_test", "all");
|
|
220
|
+
// Register user 3 and 4
|
|
221
|
+
await this.authentication.createUserWithIdent("email", "test3@webda.io");
|
|
222
|
+
await this.authentication.createUserWithIdent("email", "test4@webda.io");
|
|
223
|
+
const ident3 = await this.authentication.getIdentStore().get(`test3@webda.io_email`);
|
|
224
|
+
const ident4 = await this.authentication.getIdentStore().get(`test4@webda.io_email`);
|
|
225
|
+
await company.refresh();
|
|
226
|
+
assert.deepStrictEqual(company.__acl, {
|
|
227
|
+
[ident2.getUser()]: "read,write",
|
|
228
|
+
[ident4.getUser()]: "read,write",
|
|
229
|
+
[user.getUuid()]: "all"
|
|
270
230
|
});
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
// Add four users to the ACL
|
|
289
|
-
// 2 unregistered , 2 registered
|
|
290
|
-
yield this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
|
|
291
|
-
idents: ["test1@webda.io_email", "test3@webda.io_email", "test4@webda.io_email"],
|
|
292
|
-
users: [ident2.getUser()],
|
|
293
|
-
metadata: "read"
|
|
294
|
-
});
|
|
295
|
-
yield company.refresh();
|
|
296
|
-
assert.deepStrictEqual(company.__acl, {
|
|
297
|
-
[user.getUuid()]: "all"
|
|
298
|
-
});
|
|
299
|
-
// @ts-ignore
|
|
300
|
-
assert.deepStrictEqual(company.__invitations, {
|
|
301
|
-
[`user_${ident1.getUser()}`]: "read",
|
|
302
|
-
[`user_${ident2.getUser()}`]: "read",
|
|
303
|
-
"ident_test3@webda.io_email": "read",
|
|
304
|
-
"ident_test4@webda.io_email": "read"
|
|
305
|
-
});
|
|
306
|
-
assert.deepStrictEqual((yield this.invitations.getAll()).map(i => (Object.assign({ uuid: i.getUuid() }, i[this.service.getInvitationAttribute(company.getUuid())]))), [
|
|
307
|
-
{
|
|
308
|
-
uuid: "test3@webda.io_email_invit",
|
|
309
|
-
metadata: "read",
|
|
310
|
-
inviter: {
|
|
311
|
-
uuid: user.getUuid(),
|
|
312
|
-
displayName: "Webda.io Test"
|
|
313
|
-
}
|
|
231
|
+
// @ts-ignore
|
|
232
|
+
assert.deepStrictEqual(company.__invitations, {});
|
|
233
|
+
assert.deepStrictEqual((await this.invitations.getAll()).map(i => ({
|
|
234
|
+
uuid: i.getUuid(),
|
|
235
|
+
metadata: i[this.service.getInvitationAttribute(company.getUuid())]
|
|
236
|
+
})), []);
|
|
237
|
+
userCheck = await this.authentication.getUserStore().get(ident3.getUser());
|
|
238
|
+
assert.deepStrictEqual(userCheck["_companies"] || [], []);
|
|
239
|
+
userCheck = await this.authentication.getUserStore().get(ident4.getUser());
|
|
240
|
+
assert.deepStrictEqual(userCheck["_companies"], [
|
|
241
|
+
{
|
|
242
|
+
inviter: {
|
|
243
|
+
displayName: "Webda.io Test",
|
|
244
|
+
uuid: user.getUuid()
|
|
245
|
+
},
|
|
246
|
+
metadata: {
|
|
247
|
+
name: "MyTestCompany"
|
|
314
248
|
},
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
249
|
+
model: company.getUuid(),
|
|
250
|
+
pending: false
|
|
251
|
+
}
|
|
252
|
+
]);
|
|
253
|
+
}
|
|
254
|
+
async inviteOnAclWithoutAutoAccept() {
|
|
255
|
+
this.service.getParameters().autoAccept = false;
|
|
256
|
+
// New model as owner
|
|
257
|
+
let ctx = await this.newContext();
|
|
258
|
+
let user = await this.authentication.getUserStore().save({
|
|
259
|
+
displayName: "Webda.io Test"
|
|
260
|
+
});
|
|
261
|
+
ctx.getSession().userId = user.getUuid();
|
|
262
|
+
let res = await this.execute(ctx, "test.webda.io", "POST", "/companies", { name: "MyTestCompany" });
|
|
263
|
+
const company = await this.store.get(res.uuid);
|
|
264
|
+
// Auto register 2 users
|
|
265
|
+
await this.authentication.createUserWithIdent("email", "test1@webda.io");
|
|
266
|
+
await this.authentication.createUserWithIdent("email", "test2@webda.io");
|
|
267
|
+
const ident1 = await this.authentication.getIdentStore().get(`test1@webda.io_email`);
|
|
268
|
+
const ident2 = await this.authentication.getIdentStore().get(`test2@webda.io_email`);
|
|
269
|
+
// Add four users to the ACL
|
|
270
|
+
// 2 unregistered , 2 registered
|
|
271
|
+
await this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
|
|
272
|
+
idents: ["test1@webda.io_email", "test3@webda.io_email", "test4@webda.io_email"],
|
|
273
|
+
users: [ident2.getUser()],
|
|
274
|
+
metadata: "read"
|
|
275
|
+
});
|
|
276
|
+
await company.refresh();
|
|
277
|
+
assert.deepStrictEqual(company.__acl, {
|
|
278
|
+
[user.getUuid()]: "all"
|
|
279
|
+
});
|
|
280
|
+
// @ts-ignore
|
|
281
|
+
assert.deepStrictEqual(company.__invitations, {
|
|
282
|
+
[`user_${ident1.getUser()}`]: "read",
|
|
283
|
+
[`user_${ident2.getUser()}`]: "read",
|
|
284
|
+
"ident_test3@webda.io_email": "read",
|
|
285
|
+
"ident_test4@webda.io_email": "read"
|
|
286
|
+
});
|
|
287
|
+
assert.deepStrictEqual((await this.invitations.getAll()).map(i => ({
|
|
288
|
+
uuid: i.getUuid(),
|
|
289
|
+
...i[this.service.getInvitationAttribute(company.getUuid())]
|
|
290
|
+
})), [
|
|
291
|
+
{
|
|
292
|
+
uuid: "test3@webda.io_email_invit",
|
|
293
|
+
metadata: "read",
|
|
294
|
+
inviter: {
|
|
295
|
+
uuid: user.getUuid(),
|
|
296
|
+
displayName: "Webda.io Test"
|
|
322
297
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
},
|
|
331
|
-
metadata: {
|
|
332
|
-
name: "MyTestCompany"
|
|
333
|
-
},
|
|
334
|
-
model: company.getUuid(),
|
|
335
|
-
pending: true
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
uuid: "test4@webda.io_email_invit",
|
|
301
|
+
metadata: "read",
|
|
302
|
+
inviter: {
|
|
303
|
+
uuid: user.getUuid(),
|
|
304
|
+
displayName: "Webda.io Test"
|
|
336
305
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
});
|
|
346
|
-
// Accepting the invite for user1
|
|
347
|
-
let ctx2 = yield this.newContext();
|
|
348
|
-
ctx2.getSession().userId = ident1.getUser();
|
|
349
|
-
yield assert.rejects(() => this.execute(ctx2, "test.webda.io", "PUT", `/companies/${company.getUuid()}/invitations`, {}), /400/);
|
|
350
|
-
yield this.execute(ctx2, "test.webda.io", "PUT", `/companies/${company.getUuid()}/invitations`, {
|
|
351
|
-
accept: true
|
|
352
|
-
});
|
|
353
|
-
yield company.refresh();
|
|
354
|
-
assert.deepStrictEqual(company.__acl, {
|
|
355
|
-
[ident1.getUser()]: "read",
|
|
356
|
-
[user.getUuid()]: "all"
|
|
357
|
-
});
|
|
358
|
-
// Reinviting should be handled and metadata overwritten
|
|
359
|
-
yield this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
|
|
360
|
-
idents: ["test1@webda.io_email", "test2@webda.io_email", "test3@webda.io_email", "test4@webda.io_email"],
|
|
361
|
-
metadata: "read,write"
|
|
362
|
-
});
|
|
363
|
-
yield company.refresh();
|
|
364
|
-
assert.deepStrictEqual(company.__acl, {
|
|
365
|
-
[ident1.getUser()]: "read",
|
|
366
|
-
[user.getUuid()]: "all"
|
|
367
|
-
});
|
|
368
|
-
// @ts-ignore
|
|
369
|
-
assert.deepStrictEqual(company.__invitations, {
|
|
370
|
-
[`user_${ident2.getUser()}`]: "read,write",
|
|
371
|
-
"ident_test3@webda.io_email": "read,write",
|
|
372
|
-
"ident_test4@webda.io_email": "read,write"
|
|
373
|
-
});
|
|
374
|
-
assert.deepStrictEqual((yield this.invitations.getAll()).map(i => (Object.assign({ uuid: i.getUuid() }, i[this.service.getInvitationAttribute(company.getUuid())]))), [
|
|
375
|
-
{
|
|
376
|
-
uuid: "test3@webda.io_email_invit",
|
|
377
|
-
metadata: "read,write",
|
|
378
|
-
inviter: {
|
|
379
|
-
uuid: user.getUuid(),
|
|
380
|
-
displayName: "Webda.io Test"
|
|
381
|
-
}
|
|
306
|
+
}
|
|
307
|
+
]);
|
|
308
|
+
let userCheck = await this.authentication.getUserStore().get(ident1.getUser());
|
|
309
|
+
assert.deepStrictEqual(userCheck["_companies"], [
|
|
310
|
+
{
|
|
311
|
+
inviter: {
|
|
312
|
+
displayName: "Webda.io Test",
|
|
313
|
+
uuid: user.getUuid()
|
|
382
314
|
},
|
|
383
|
-
{
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
315
|
+
metadata: {
|
|
316
|
+
name: "MyTestCompany"
|
|
317
|
+
},
|
|
318
|
+
model: company.getUuid(),
|
|
319
|
+
pending: true
|
|
320
|
+
}
|
|
321
|
+
]);
|
|
322
|
+
userCheck["_companies"] = [
|
|
323
|
+
{
|
|
324
|
+
model: "Test"
|
|
325
|
+
},
|
|
326
|
+
...userCheck["_companies"]
|
|
327
|
+
];
|
|
328
|
+
// @ts-ignore
|
|
329
|
+
await userCheck.save("_companies");
|
|
330
|
+
// Accepting the invite for user1
|
|
331
|
+
let ctx2 = await this.newContext();
|
|
332
|
+
ctx2.getSession().userId = ident1.getUser();
|
|
333
|
+
await assert.rejects(() => this.execute(ctx2, "test.webda.io", "PUT", `/companies/${company.getUuid()}/invitations`, {}), /400/);
|
|
334
|
+
await this.execute(ctx2, "test.webda.io", "PUT", `/companies/${company.getUuid()}/invitations`, {
|
|
335
|
+
accept: true
|
|
336
|
+
});
|
|
337
|
+
await company.refresh();
|
|
338
|
+
assert.deepStrictEqual(company.__acl, {
|
|
339
|
+
[ident1.getUser()]: "read",
|
|
340
|
+
[user.getUuid()]: "all"
|
|
341
|
+
});
|
|
342
|
+
// Reinviting should be handled and metadata overwritten
|
|
343
|
+
await this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
|
|
344
|
+
idents: ["test1@webda.io_email", "test2@webda.io_email", "test3@webda.io_email", "test4@webda.io_email"],
|
|
345
|
+
metadata: "read,write"
|
|
346
|
+
});
|
|
347
|
+
await company.refresh();
|
|
348
|
+
assert.deepStrictEqual(company.__acl, {
|
|
349
|
+
[ident1.getUser()]: "read",
|
|
350
|
+
[user.getUuid()]: "all"
|
|
351
|
+
});
|
|
352
|
+
// @ts-ignore
|
|
353
|
+
assert.deepStrictEqual(company.__invitations, {
|
|
354
|
+
[`user_${ident2.getUser()}`]: "read,write",
|
|
355
|
+
"ident_test3@webda.io_email": "read,write",
|
|
356
|
+
"ident_test4@webda.io_email": "read,write"
|
|
357
|
+
});
|
|
358
|
+
assert.deepStrictEqual((await this.invitations.getAll()).map(i => ({
|
|
359
|
+
uuid: i.getUuid(),
|
|
360
|
+
...i[this.service.getInvitationAttribute(company.getUuid())]
|
|
361
|
+
})), [
|
|
362
|
+
{
|
|
363
|
+
uuid: "test3@webda.io_email_invit",
|
|
364
|
+
metadata: "read,write",
|
|
365
|
+
inviter: {
|
|
366
|
+
uuid: user.getUuid(),
|
|
367
|
+
displayName: "Webda.io Test"
|
|
390
368
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
assert.deepStrictEqual(company.__acl, {
|
|
399
|
-
[user.getUuid()]: "all"
|
|
400
|
-
});
|
|
401
|
-
// @ts-ignore
|
|
402
|
-
assert.deepStrictEqual(company.__invitations, {
|
|
403
|
-
"ident_test4@webda.io_email": "read,write"
|
|
404
|
-
});
|
|
405
|
-
assert.deepStrictEqual((yield this.invitations.getAll()).map(i => (Object.assign({ uuid: i.getUuid() }, i[this.service.getInvitationAttribute(company.getUuid())]))), [
|
|
406
|
-
{ uuid: "test3@webda.io_email_invit" },
|
|
407
|
-
{
|
|
408
|
-
uuid: "test4@webda.io_email_invit",
|
|
409
|
-
metadata: "read,write",
|
|
410
|
-
inviter: {
|
|
411
|
-
uuid: user.getUuid(),
|
|
412
|
-
displayName: "Webda.io Test"
|
|
413
|
-
}
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
uuid: "test4@webda.io_email_invit",
|
|
372
|
+
metadata: "read,write",
|
|
373
|
+
inviter: {
|
|
374
|
+
uuid: user.getUuid(),
|
|
375
|
+
displayName: "Webda.io Test"
|
|
414
376
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
377
|
+
}
|
|
378
|
+
]);
|
|
379
|
+
// Remove 1 unregistered and one registered from the ACL
|
|
380
|
+
await this.execute(ctx, "test.webda.io", "DELETE", `/companies/${company.getUuid()}/invitations`, {
|
|
381
|
+
idents: ["test3@webda.io_email"],
|
|
382
|
+
users: [ident1.getUser(), ident2.getUser()]
|
|
383
|
+
});
|
|
384
|
+
// Ensure double delete will not be an issue
|
|
385
|
+
await this.execute(ctx, "test.webda.io", "DELETE", `/companies/${company.getUuid()}/invitations`, {
|
|
386
|
+
users: [ident1.getUser(), ident2.getUser()]
|
|
387
|
+
});
|
|
388
|
+
await company.refresh();
|
|
389
|
+
assert.deepStrictEqual(company.__acl, {
|
|
390
|
+
[user.getUuid()]: "all"
|
|
391
|
+
});
|
|
392
|
+
// @ts-ignore
|
|
393
|
+
assert.deepStrictEqual(company.__invitations, {
|
|
394
|
+
"ident_test4@webda.io_email": "read,write"
|
|
395
|
+
});
|
|
396
|
+
assert.deepStrictEqual((await this.invitations.getAll()).map(i => ({
|
|
397
|
+
uuid: i.getUuid(),
|
|
398
|
+
...i[this.service.getInvitationAttribute(company.getUuid())]
|
|
399
|
+
})), [
|
|
400
|
+
{ uuid: "test3@webda.io_email_invit" },
|
|
401
|
+
{
|
|
402
|
+
uuid: "test4@webda.io_email_invit",
|
|
403
|
+
metadata: "read,write",
|
|
404
|
+
inviter: {
|
|
405
|
+
uuid: user.getUuid(),
|
|
406
|
+
displayName: "Webda.io Test"
|
|
420
407
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
});
|
|
446
|
-
yield company.refresh();
|
|
447
|
-
assert.deepStrictEqual(company.__acl, {
|
|
448
|
-
[user.getUuid()]: "all",
|
|
449
|
-
[ident4.getUser()]: "read,write"
|
|
450
|
-
});
|
|
451
|
-
// @ts-ignore
|
|
452
|
-
assert.deepStrictEqual(company.__invitations, {});
|
|
408
|
+
}
|
|
409
|
+
]);
|
|
410
|
+
userCheck = await this.authentication.getUserStore().get(ident1.getUser());
|
|
411
|
+
assert.deepStrictEqual(userCheck["_companies"], [
|
|
412
|
+
{
|
|
413
|
+
model: "Test"
|
|
414
|
+
}
|
|
415
|
+
]);
|
|
416
|
+
userCheck = await this.authentication.getUserStore().get(ident2.getUser());
|
|
417
|
+
assert.deepStrictEqual(userCheck["_companies"], []);
|
|
418
|
+
// Missing model
|
|
419
|
+
await this.invitations.setAttribute("test4@webda.io_email_invit", "invit_test", "all");
|
|
420
|
+
// Register user 3 and 4
|
|
421
|
+
await this.authentication.createUserWithIdent("email", "test3@webda.io");
|
|
422
|
+
await this.authentication.createUserWithIdent("email", "test4@webda.io");
|
|
423
|
+
await this.authentication.getIdentStore().get(`test3@webda.io_email`);
|
|
424
|
+
const ident4 = await this.authentication.getIdentStore().get(`test4@webda.io_email`);
|
|
425
|
+
await company.refresh();
|
|
426
|
+
assert.deepStrictEqual(company.__acl, {
|
|
427
|
+
[user.getUuid()]: "all"
|
|
428
|
+
});
|
|
429
|
+
// @ts-ignore
|
|
430
|
+
assert.deepStrictEqual(company.__invitations, {
|
|
431
|
+
"ident_test4@webda.io_email": "read,write"
|
|
453
432
|
});
|
|
433
|
+
assert.deepStrictEqual((await this.invitations.getAll()).map(i => ({
|
|
434
|
+
uuid: i.getUuid(),
|
|
435
|
+
...i[this.service.getInvitationAttribute(company.getUuid())]
|
|
436
|
+
})), []);
|
|
437
|
+
ctx2.getSession().userId = ident4.getUser();
|
|
438
|
+
// Force refresh of user as we changed user manually
|
|
439
|
+
await ctx2.getCurrentUser(true);
|
|
440
|
+
await this.execute(ctx2, "test.webda.io", "PUT", `/companies/${company.getUuid()}/invitations`, {
|
|
441
|
+
accept: true
|
|
442
|
+
});
|
|
443
|
+
await company.refresh();
|
|
444
|
+
assert.deepStrictEqual(company.__acl, {
|
|
445
|
+
[user.getUuid()]: "all",
|
|
446
|
+
[ident4.getUser()]: "read,write"
|
|
447
|
+
});
|
|
448
|
+
// @ts-ignore
|
|
449
|
+
assert.deepStrictEqual(company.__invitations, {});
|
|
454
450
|
}
|
|
455
|
-
invitationDeletedModel() {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
metadata: "read"
|
|
475
|
-
});
|
|
476
|
-
yield company.delete();
|
|
477
|
-
let checkUser = yield this.authentication.getUserStore().get(ident1.getUser());
|
|
478
|
-
assert.strictEqual(checkUser["_companies"].length, 1);
|
|
479
|
-
// Accepting the invite for user1
|
|
480
|
-
let ctx2 = yield this.newContext();
|
|
481
|
-
ctx2.getSession().userId = ident1.getUser();
|
|
482
|
-
// It should be removed and get a 410 error code
|
|
483
|
-
yield assert.rejects(() => this.execute(ctx2, "test.webda.io", "PUT", `/companies/${company.getUuid()}/invitations`, {
|
|
484
|
-
accept: true
|
|
485
|
-
}), /410/);
|
|
486
|
-
yield checkUser.refresh();
|
|
487
|
-
assert.strictEqual(checkUser["_companies"].length, 0);
|
|
488
|
-
// Register pending one
|
|
489
|
-
yield this.authentication.createUserWithIdent("email", "test2@webda.io");
|
|
490
|
-
const ident2 = yield this.authentication.getIdentStore().get(`test2@webda.io_email`);
|
|
491
|
-
checkUser = yield this.authentication.getUserStore().get(ident2.getUser());
|
|
492
|
-
assert.strictEqual(checkUser["_companies"].length, 0);
|
|
451
|
+
async invitationDeletedModel() {
|
|
452
|
+
this.service.getParameters().autoAccept = false;
|
|
453
|
+
// New model as owner
|
|
454
|
+
let ctx = await this.newContext();
|
|
455
|
+
let user = await this.authentication.getUserStore().save({
|
|
456
|
+
displayName: "Webda.io Test"
|
|
457
|
+
});
|
|
458
|
+
ctx.getSession().userId = user.getUuid();
|
|
459
|
+
let res = await this.execute(ctx, "test.webda.io", "POST", "/companies", { name: "MyTestCompany" });
|
|
460
|
+
const company = await this.store.get(res.uuid);
|
|
461
|
+
// Auto register 2 users
|
|
462
|
+
await this.authentication.createUserWithIdent("email", "test1@webda.io");
|
|
463
|
+
const ident1 = await this.authentication.getIdentStore().get(`test1@webda.io_email`);
|
|
464
|
+
// Add two users to the ACL
|
|
465
|
+
// 1 unregistered , 1 registered
|
|
466
|
+
await this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
|
|
467
|
+
idents: ["test2@webda.io_email"],
|
|
468
|
+
users: [ident1.getUser()],
|
|
469
|
+
metadata: "read"
|
|
493
470
|
});
|
|
471
|
+
await company.delete();
|
|
472
|
+
let checkUser = await this.authentication.getUserStore().get(ident1.getUser());
|
|
473
|
+
assert.strictEqual(checkUser["_companies"].length, 1);
|
|
474
|
+
// Accepting the invite for user1
|
|
475
|
+
let ctx2 = await this.newContext();
|
|
476
|
+
ctx2.getSession().userId = ident1.getUser();
|
|
477
|
+
// It should be removed and get a 410 error code
|
|
478
|
+
await assert.rejects(() => this.execute(ctx2, "test.webda.io", "PUT", `/companies/${company.getUuid()}/invitations`, {
|
|
479
|
+
accept: true
|
|
480
|
+
}), /410/);
|
|
481
|
+
await checkUser.refresh();
|
|
482
|
+
assert.strictEqual(checkUser["_companies"].length, 0);
|
|
483
|
+
// Register pending one
|
|
484
|
+
await this.authentication.createUserWithIdent("email", "test2@webda.io");
|
|
485
|
+
const ident2 = await this.authentication.getIdentStore().get(`test2@webda.io_email`);
|
|
486
|
+
checkUser = await this.authentication.getUserStore().get(ident2.getUser());
|
|
487
|
+
assert.strictEqual(checkUser["_companies"].length, 0);
|
|
494
488
|
}
|
|
495
489
|
};
|
|
496
490
|
__decorate([
|
|
497
|
-
|
|
491
|
+
test
|
|
498
492
|
], InvitationTest.prototype, "params", null);
|
|
499
493
|
__decorate([
|
|
500
|
-
|
|
494
|
+
test
|
|
501
495
|
], InvitationTest.prototype, "initNoTemplate", null);
|
|
502
496
|
__decorate([
|
|
503
|
-
|
|
497
|
+
test
|
|
504
498
|
], InvitationTest.prototype, "inviteOnMissing", null);
|
|
505
499
|
__decorate([
|
|
506
|
-
|
|
500
|
+
test
|
|
507
501
|
], InvitationTest.prototype, "inviteOnAclWithAutoAccept", null);
|
|
508
502
|
__decorate([
|
|
509
|
-
|
|
503
|
+
test
|
|
510
504
|
], InvitationTest.prototype, "inviteOnAclWithoutAutoAccept", null);
|
|
511
505
|
__decorate([
|
|
512
|
-
|
|
506
|
+
test
|
|
513
507
|
], InvitationTest.prototype, "invitationDeletedModel", null);
|
|
514
508
|
InvitationTest = __decorate([
|
|
515
|
-
|
|
509
|
+
suite
|
|
516
510
|
], InvitationTest);
|
|
517
511
|
//# sourceMappingURL=invitationservice.spec.js.map
|