@webda/core 2.0.0-beta.3 → 2.1.0

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.
Files changed (276) hide show
  1. package/lib/application.d.ts +5 -5
  2. package/lib/application.js +71 -84
  3. package/lib/application.js.map +1 -1
  4. package/lib/application.spec.js +121 -140
  5. package/lib/application.spec.js.map +1 -1
  6. package/lib/core.d.ts +21 -25
  7. package/lib/core.js +233 -320
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +334 -406
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/index.d.ts +49 -48
  12. package/lib/index.js +53 -70
  13. package/lib/index.js.map +1 -1
  14. package/lib/models/aclmodel.d.ts +2 -2
  15. package/lib/models/aclmodel.js +63 -90
  16. package/lib/models/aclmodel.js.map +1 -1
  17. package/lib/models/aclmodel.spec.js +128 -152
  18. package/lib/models/aclmodel.spec.js.map +1 -1
  19. package/lib/models/coremodel.d.ts +33 -14
  20. package/lib/models/coremodel.js +160 -117
  21. package/lib/models/coremodel.js.map +1 -1
  22. package/lib/models/coremodel.spec.js +143 -107
  23. package/lib/models/coremodel.spec.js.map +1 -1
  24. package/lib/models/deployment.js +1 -2
  25. package/lib/models/ident.d.ts +3 -3
  26. package/lib/models/ident.js +4 -9
  27. package/lib/models/ident.js.map +1 -1
  28. package/lib/models/ident.spec.js +9 -11
  29. package/lib/models/ident.spec.js.map +1 -1
  30. package/lib/models/ownermodel.d.ts +2 -2
  31. package/lib/models/ownermodel.js +39 -62
  32. package/lib/models/ownermodel.js.map +1 -1
  33. package/lib/models/ownermodel.spec.js +126 -168
  34. package/lib/models/ownermodel.spec.js.map +1 -1
  35. package/lib/models/rolemodel.d.ts +1 -1
  36. package/lib/models/rolemodel.js +24 -40
  37. package/lib/models/rolemodel.js.map +1 -1
  38. package/lib/models/rolemodel.spec.js +44 -63
  39. package/lib/models/rolemodel.spec.js.map +1 -1
  40. package/lib/models/user.d.ts +9 -9
  41. package/lib/models/user.js +3 -8
  42. package/lib/models/user.js.map +1 -1
  43. package/lib/models/user.spec.js +14 -16
  44. package/lib/models/user.spec.js.map +1 -1
  45. package/lib/queues/filequeue.d.ts +2 -2
  46. package/lib/queues/filequeue.js +72 -93
  47. package/lib/queues/filequeue.js.map +1 -1
  48. package/lib/queues/filequeue.spec.js +53 -70
  49. package/lib/queues/filequeue.spec.js.map +1 -1
  50. package/lib/queues/memoryqueue.d.ts +2 -2
  51. package/lib/queues/memoryqueue.js +37 -61
  52. package/lib/queues/memoryqueue.js.map +1 -1
  53. package/lib/queues/memoryqueue.spec.js +142 -165
  54. package/lib/queues/memoryqueue.spec.js.map +1 -1
  55. package/lib/queues/pubsubservice.d.ts +2 -2
  56. package/lib/queues/pubsubservice.js +3 -7
  57. package/lib/queues/pubsubservice.js.map +1 -1
  58. package/lib/queues/queue.spec.d.ts +1 -1
  59. package/lib/queues/queue.spec.js +42 -56
  60. package/lib/queues/queue.spec.js.map +1 -1
  61. package/lib/queues/queueservice.d.ts +3 -3
  62. package/lib/queues/queueservice.js +51 -67
  63. package/lib/queues/queueservice.js.map +1 -1
  64. package/lib/router.d.ts +3 -3
  65. package/lib/router.js +46 -47
  66. package/lib/router.js.map +1 -1
  67. package/lib/router.spec.js +64 -61
  68. package/lib/router.spec.js.map +1 -1
  69. package/lib/services/asyncevents.d.ts +2 -2
  70. package/lib/services/asyncevents.js +44 -64
  71. package/lib/services/asyncevents.js.map +1 -1
  72. package/lib/services/asyncevents.spec.js +81 -98
  73. package/lib/services/asyncevents.spec.js.map +1 -1
  74. package/lib/services/authentication.d.ts +23 -13
  75. package/lib/services/authentication.js +540 -566
  76. package/lib/services/authentication.js.map +1 -1
  77. package/lib/services/authentication.spec.js +411 -447
  78. package/lib/services/authentication.spec.js.map +1 -1
  79. package/lib/services/binary.d.ts +8 -6
  80. package/lib/services/binary.js +212 -245
  81. package/lib/services/binary.js.map +1 -1
  82. package/lib/services/binary.spec.d.ts +3 -3
  83. package/lib/services/binary.spec.js +390 -443
  84. package/lib/services/binary.spec.js.map +1 -1
  85. package/lib/services/cloudbinary.d.ts +3 -3
  86. package/lib/services/cloudbinary.js +45 -70
  87. package/lib/services/cloudbinary.js.map +1 -1
  88. package/lib/services/cloudbinary.spec.d.ts +3 -3
  89. package/lib/services/cloudbinary.spec.js +133 -162
  90. package/lib/services/cloudbinary.spec.js.map +1 -1
  91. package/lib/services/configuration.d.ts +1 -1
  92. package/lib/services/configuration.js +78 -105
  93. package/lib/services/configuration.js.map +1 -1
  94. package/lib/services/configuration.spec.js +63 -83
  95. package/lib/services/configuration.spec.js.map +1 -1
  96. package/lib/services/cron.d.ts +3 -2
  97. package/lib/services/cron.js +9 -13
  98. package/lib/services/cron.js.map +1 -1
  99. package/lib/services/cron.spec.js +18 -21
  100. package/lib/services/cron.spec.js.map +1 -1
  101. package/lib/services/cryptoservice.d.ts +9 -4
  102. package/lib/services/cryptoservice.js +187 -221
  103. package/lib/services/cryptoservice.js.map +1 -1
  104. package/lib/services/cryptoservice.spec.js +88 -115
  105. package/lib/services/cryptoservice.spec.js.map +1 -1
  106. package/lib/services/debugmailer.d.ts +1 -1
  107. package/lib/services/debugmailer.js +13 -34
  108. package/lib/services/debugmailer.js.map +1 -1
  109. package/lib/services/debugmailer.spec.js +16 -29
  110. package/lib/services/debugmailer.spec.js.map +1 -1
  111. package/lib/services/echo.d.ts +2 -2
  112. package/lib/services/echo.js +15 -31
  113. package/lib/services/echo.js.map +1 -1
  114. package/lib/services/echo.spec.js +27 -40
  115. package/lib/services/echo.spec.js.map +1 -1
  116. package/lib/services/filebinary.d.ts +5 -5
  117. package/lib/services/filebinary.js +165 -210
  118. package/lib/services/filebinary.js.map +1 -1
  119. package/lib/services/filebinary.spec.d.ts +2 -1
  120. package/lib/services/filebinary.spec.js +106 -116
  121. package/lib/services/filebinary.spec.js.map +1 -1
  122. package/lib/services/fileconfiguration.d.ts +1 -1
  123. package/lib/services/fileconfiguration.js +25 -44
  124. package/lib/services/fileconfiguration.js.map +1 -1
  125. package/lib/services/fileconfiguration.spec.js +79 -109
  126. package/lib/services/fileconfiguration.spec.js.map +1 -1
  127. package/lib/services/invitationservice.d.ts +8 -8
  128. package/lib/services/invitationservice.js +274 -314
  129. package/lib/services/invitationservice.js.map +1 -1
  130. package/lib/services/invitationservice.spec.js +443 -449
  131. package/lib/services/invitationservice.spec.js.map +1 -1
  132. package/lib/services/kubernetesconfiguration.d.ts +1 -1
  133. package/lib/services/kubernetesconfiguration.js +41 -60
  134. package/lib/services/kubernetesconfiguration.js.map +1 -1
  135. package/lib/services/kubernetesconfiguration.spec.js +80 -98
  136. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  137. package/lib/services/mailer.d.ts +4 -4
  138. package/lib/services/mailer.js +62 -86
  139. package/lib/services/mailer.js.map +1 -1
  140. package/lib/services/mailer.spec.js +86 -127
  141. package/lib/services/mailer.spec.js.map +1 -1
  142. package/lib/services/notificationservice.d.ts +3 -3
  143. package/lib/services/notificationservice.js +21 -42
  144. package/lib/services/notificationservice.js.map +1 -1
  145. package/lib/services/notificationservice.spec.js +47 -73
  146. package/lib/services/notificationservice.spec.js.map +1 -1
  147. package/lib/services/oauth.d.ts +4 -4
  148. package/lib/services/oauth.js +68 -83
  149. package/lib/services/oauth.js.map +1 -1
  150. package/lib/services/oauth.spec.js +130 -156
  151. package/lib/services/oauth.spec.js.map +1 -1
  152. package/lib/services/proxy.d.ts +2 -6
  153. package/lib/services/proxy.js +45 -58
  154. package/lib/services/proxy.js.map +1 -1
  155. package/lib/services/proxy.spec.js +34 -53
  156. package/lib/services/proxy.spec.js.map +1 -1
  157. package/lib/services/resource.d.ts +2 -2
  158. package/lib/services/resource.js +12 -18
  159. package/lib/services/resource.js.map +1 -1
  160. package/lib/services/resource.spec.js +67 -99
  161. package/lib/services/resource.spec.js.map +1 -1
  162. package/lib/services/service.d.ts +26 -3
  163. package/lib/services/service.js +68 -40
  164. package/lib/services/service.js.map +1 -1
  165. package/lib/services/service.spec.js +62 -67
  166. package/lib/services/service.spec.js.map +1 -1
  167. package/lib/services/version.d.ts +1 -1
  168. package/lib/services/version.js +3 -8
  169. package/lib/services/version.js.map +1 -1
  170. package/lib/services/version.spec.js +11 -24
  171. package/lib/services/version.spec.js.map +1 -1
  172. package/lib/stores/aggregator.d.ts +2 -2
  173. package/lib/stores/aggregator.js +37 -58
  174. package/lib/stores/aggregator.js.map +1 -1
  175. package/lib/stores/file.d.ts +3 -3
  176. package/lib/stores/file.js +93 -131
  177. package/lib/stores/file.js.map +1 -1
  178. package/lib/stores/file.spec.d.ts +2 -2
  179. package/lib/stores/file.spec.js +262 -289
  180. package/lib/stores/file.spec.js.map +1 -1
  181. package/lib/stores/mapper.d.ts +3 -3
  182. package/lib/stores/mapper.js +110 -137
  183. package/lib/stores/mapper.js.map +1 -1
  184. package/lib/stores/mapper.spec.js +133 -150
  185. package/lib/stores/mapper.spec.js.map +1 -1
  186. package/lib/stores/memory.d.ts +3 -3
  187. package/lib/stores/memory.js +98 -144
  188. package/lib/stores/memory.js.map +1 -1
  189. package/lib/stores/memory.spec.d.ts +2 -2
  190. package/lib/stores/memory.spec.js +124 -145
  191. package/lib/stores/memory.spec.js.map +1 -1
  192. package/lib/stores/store.d.ts +27 -17
  193. package/lib/stores/store.js +833 -849
  194. package/lib/stores/store.js.map +1 -1
  195. package/lib/stores/store.spec.d.ts +5 -4
  196. package/lib/stores/store.spec.js +625 -669
  197. package/lib/stores/store.spec.js.map +1 -1
  198. package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
  199. package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
  200. package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
  201. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
  202. package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
  203. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
  204. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
  205. package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
  206. package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
  207. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
  208. package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
  209. package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
  210. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
  211. package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
  212. package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
  213. package/lib/stores/webdaql/query.d.ts +4 -5
  214. package/lib/stores/webdaql/query.js +16 -19
  215. package/lib/stores/webdaql/query.js.map +1 -1
  216. package/lib/stores/webdaql/query.spec.js +30 -32
  217. package/lib/stores/webdaql/query.spec.js.map +1 -1
  218. package/lib/test.d.ts +3 -3
  219. package/lib/test.js +73 -100
  220. package/lib/test.js.map +1 -1
  221. package/lib/unpackedapplication.d.ts +1 -1
  222. package/lib/unpackedapplication.js +49 -39
  223. package/lib/unpackedapplication.js.map +1 -1
  224. package/lib/utils/abstractdeployer.js +1 -5
  225. package/lib/utils/abstractdeployer.js.map +1 -1
  226. package/lib/utils/abstractdeployer.spec.js +6 -8
  227. package/lib/utils/abstractdeployer.spec.js.map +1 -1
  228. package/lib/utils/context.d.ts +7 -5
  229. package/lib/utils/context.js +95 -103
  230. package/lib/utils/context.js.map +1 -1
  231. package/lib/utils/context.spec.js +139 -163
  232. package/lib/utils/context.spec.js.map +1 -1
  233. package/lib/utils/cookie.d.ts +3 -3
  234. package/lib/utils/cookie.js +42 -61
  235. package/lib/utils/cookie.js.map +1 -1
  236. package/lib/utils/cookie.spec.js +42 -64
  237. package/lib/utils/cookie.spec.js.map +1 -1
  238. package/lib/utils/esm.d.ts +4 -0
  239. package/lib/utils/esm.js +10 -0
  240. package/lib/utils/esm.js.map +1 -0
  241. package/lib/utils/httpcontext.d.ts +3 -0
  242. package/lib/utils/httpcontext.js +48 -65
  243. package/lib/utils/httpcontext.js.map +1 -1
  244. package/lib/utils/httpcontext.spec.js +37 -56
  245. package/lib/utils/httpcontext.spec.js.map +1 -1
  246. package/lib/utils/logger.d.ts +2 -2
  247. package/lib/utils/logger.js +15 -28
  248. package/lib/utils/logger.js.map +1 -1
  249. package/lib/utils/logger.spec.js +9 -11
  250. package/lib/utils/logger.spec.js.map +1 -1
  251. package/lib/utils/serializers.js +17 -20
  252. package/lib/utils/serializers.js.map +1 -1
  253. package/lib/utils/serializers.spec.js +43 -44
  254. package/lib/utils/serializers.spec.js.map +1 -1
  255. package/lib/utils/session.d.ts +6 -6
  256. package/lib/utils/session.js +37 -59
  257. package/lib/utils/session.js.map +1 -1
  258. package/lib/utils/session.spec.js +38 -51
  259. package/lib/utils/session.spec.js.map +1 -1
  260. package/lib/utils/waiter.d.ts +1 -1
  261. package/lib/utils/waiter.js +32 -52
  262. package/lib/utils/waiter.js.map +1 -1
  263. package/lib/utils/waiter.spec.js +75 -92
  264. package/lib/utils/waiter.spec.js.map +1 -1
  265. package/package.json +18 -13
  266. package/test/config-invitation.json +1 -3
  267. package/test/config.json +1 -2
  268. package/test/config.old.json +1 -2
  269. package/test/moddas/annotatedservice.js +5 -5
  270. package/test/moddas/debugmailer.js +2 -3
  271. package/test/moddas/fakeservice.js +2 -3
  272. package/test/moddas/voidstore.js +6 -4
  273. package/test/models/ident.js +2 -6
  274. package/test/models/task.js +3 -7
  275. package/test/package.json +2 -1
  276. package/webda.module.json +895 -190
@@ -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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const mocha_1 = require("@testdeck/mocha");
19
- const assert = require("assert");
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 test_1.WebdaTest {
21
+ let InvitationTest = class InvitationTest extends WebdaTest {
38
22
  getTestConfiguration() {
39
23
  return process.cwd() + "/test/config-invitation.json";
40
24
  }
41
- before() {
42
- const _super = Object.create(null, {
43
- before: { get: () => super.before }
44
- });
45
- return __awaiter(this, void 0, void 0, function* () {
46
- yield _super.before.call(this);
47
- this.service = new invitationservice_1.default(this.webda, "invit", {
48
- modelStore: "Companies",
49
- invitationStore: "Invitations",
50
- attribute: "__acl",
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
- yield this.service.resolve().init();
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 invitationservice_1.InvitationParameters({
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 invitationservice_1.InvitationParameters({
53
+ assert.throws(() => new InvitationParameters({
75
54
  attribute: "plop"
76
55
  }), /needs to start with a _/);
77
- assert.throws(() => new invitationservice_1.InvitationParameters({
56
+ assert.throws(() => new InvitationParameters({
78
57
  attribute: "_plop",
79
58
  pendingAttribute: "bouzouf"
80
59
  }), /needs to start with a _/);
81
- assert.throws(() => new invitationservice_1.InvitationParameters({
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
- return __awaiter(this, void 0, void 0, function* () {
90
- // @ts-ignore
91
- let stub = sinon.stub(this.mailer, "hasNotification").callsFake(() => __awaiter(this, void 0, void 0, function* () { return false; }));
92
- try {
93
- this.service.getParameters().notification = "plop";
94
- yield assert.rejects(() => this.service.init(), /Email template should exist/);
95
- }
96
- finally {
97
- stub.restore();
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
- return __awaiter(this, void 0, void 0, function* () {
103
- let ctx = yield this.newContext();
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
- return __awaiter(this, void 0, void 0, function* () {
109
- this.service.getParameters().autoAccept = true;
110
- this.service.getParameters().notification = "COMPANY_INVITE";
111
- sinon.stub(this.service.notificationService, "sendNotification").callsFake(() => __awaiter(this, void 0, void 0, function* () { }));
112
- // New model as owner
113
- let ctx = yield this.newContext();
114
- let user = yield this.authentication.getUserStore().save({ displayName: "Webda.io Test" });
115
- ctx.getSession().userId = user.getUuid();
116
- let res = yield this.execute(ctx, "test.webda.io", "POST", "/companies", { name: "MyTestCompany" });
117
- const company = yield this.store.get(res.uuid);
118
- // Auto register 2 users
119
- yield this.authentication.createUserWithIdent("email", "test1@webda.io");
120
- yield this.authentication.createUserWithIdent("email", "test2@webda.io");
121
- const ident1 = yield this.authentication.getIdentStore().get(`test1@webda.io_email`);
122
- const ident2 = yield this.authentication.getIdentStore().get(`test2@webda.io_email`);
123
- // Add four users to the ACL
124
- // 2 unregistered , 2 registered
125
- yield this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
126
- idents: ["test1@webda.io_email", "test3@webda.io_email", "test4@webda.io_email"],
127
- users: [ident2.getUser(), "unknown"],
128
- metadata: "read"
129
- });
130
- yield company.refresh();
131
- assert.deepStrictEqual(company.__acl, {
132
- [ident1.getUser()]: "read",
133
- [ident2.getUser()]: "read",
134
- [user.getUuid()]: "all"
135
- });
136
- let getter = yield this.execute(ctx, "test.webda.io", "GET", `/companies/${company.getUuid()}/invitations`);
137
- // @ts-ignore
138
- assert.deepStrictEqual(company.__invitations, {
139
- "ident_test3@webda.io_email": "read",
140
- "ident_test4@webda.io_email": "read"
141
- });
142
- // @ts-ignore
143
- assert.deepStrictEqual(company.__invitations, getter);
144
- assert.deepStrictEqual((yield this.invitations.getAll()).map(i => (Object.assign({ uuid: i.getUuid() }, i[this.service.getInvitationAttribute(company.getUuid())]))), [
145
- {
146
- uuid: "test3@webda.io_email_invit",
147
- metadata: "read",
148
- inviter: {
149
- uuid: user.getUuid(),
150
- displayName: "Webda.io Test"
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
- // Reinviting should be handled and metadata overwritten
163
- yield this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
164
- idents: ["test2@webda.io_email", "test3@webda.io_email", "test4@webda.io_email"],
165
- users: [ident1.getUser()],
166
- metadata: "read,write"
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
- // @ts-ignore
189
- assert.deepStrictEqual(company.__invitations, {
190
- "ident_test3@webda.io_email": "read,write",
191
- "ident_test4@webda.io_email": "read,write"
192
- });
193
- assert.deepStrictEqual((yield this.invitations.getAll()).map(i => (Object.assign({ uuid: i.getUuid() }, i[this.service.getInvitationAttribute(company.getUuid())]))), [
194
- {
195
- uuid: "test3@webda.io_email_invit",
196
- metadata: "read,write",
197
- inviter: {
198
- uuid: user.getUuid(),
199
- displayName: "Webda.io Test"
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
- uuid: "test4@webda.io_email_invit",
204
- metadata: "read,write",
205
- inviter: {
206
- uuid: user.getUuid(),
207
- displayName: "Webda.io Test"
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
- // Remove 1 unregistered and one registered from the ACL
212
- yield this.execute(ctx, "test.webda.io", "DELETE", `/companies/${company.getUuid()}/invitations`, {
213
- idents: ["test1@webda.io_email", "test3@webda.io_email"]
214
- });
215
- yield company.refresh();
216
- assert.deepStrictEqual(company.__acl, {
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
- // Missing model
236
- yield this.invitations.setAttribute("test4@webda.io_email_invit", "invit_test", "all");
237
- // Register user 3 and 4
238
- yield this.authentication.createUserWithIdent("email", "test3@webda.io");
239
- yield this.authentication.createUserWithIdent("email", "test4@webda.io");
240
- const ident3 = yield this.authentication.getIdentStore().get(`test3@webda.io_email`);
241
- const ident4 = yield this.authentication.getIdentStore().get(`test4@webda.io_email`);
242
- yield company.refresh();
243
- assert.deepStrictEqual(company.__acl, {
244
- [ident2.getUser()]: "read,write",
245
- [ident4.getUser()]: "read,write",
246
- [user.getUuid()]: "all"
247
- });
248
- // @ts-ignore
249
- assert.deepStrictEqual(company.__invitations, {});
250
- assert.deepStrictEqual((yield this.invitations.getAll()).map(i => ({
251
- uuid: i.getUuid(),
252
- metadata: i[this.service.getInvitationAttribute(company.getUuid())]
253
- })), []);
254
- userCheck = yield this.authentication.getUserStore().get(ident3.getUser());
255
- assert.deepStrictEqual(userCheck["_companies"] || [], []);
256
- userCheck = yield this.authentication.getUserStore().get(ident4.getUser());
257
- assert.deepStrictEqual(userCheck["_companies"], [
258
- {
259
- inviter: {
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
- inviteOnAclWithoutAutoAccept() {
273
- return __awaiter(this, void 0, void 0, function* () {
274
- this.service.getParameters().autoAccept = false;
275
- // New model as owner
276
- let ctx = yield this.newContext();
277
- let user = yield this.authentication.getUserStore().save({
278
- displayName: "Webda.io Test"
279
- });
280
- ctx.getSession().userId = user.getUuid();
281
- let res = yield this.execute(ctx, "test.webda.io", "POST", "/companies", { name: "MyTestCompany" });
282
- const company = yield this.store.get(res.uuid);
283
- // Auto register 2 users
284
- yield this.authentication.createUserWithIdent("email", "test1@webda.io");
285
- yield this.authentication.createUserWithIdent("email", "test2@webda.io");
286
- const ident1 = yield this.authentication.getIdentStore().get(`test1@webda.io_email`);
287
- const ident2 = yield this.authentication.getIdentStore().get(`test2@webda.io_email`);
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
- uuid: "test4@webda.io_email_invit",
317
- metadata: "read",
318
- inviter: {
319
- uuid: user.getUuid(),
320
- displayName: "Webda.io Test"
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
- let userCheck = yield this.authentication.getUserStore().get(ident1.getUser());
325
- assert.deepStrictEqual(userCheck["_companies"], [
326
- {
327
- inviter: {
328
- displayName: "Webda.io Test",
329
- uuid: user.getUuid()
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
- yield userCheck.update({
339
- _companies: [
340
- {
341
- model: "Test"
342
- },
343
- ...userCheck["_companies"]
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
- uuid: "test4@webda.io_email_invit",
385
- metadata: "read,write",
386
- inviter: {
387
- uuid: user.getUuid(),
388
- displayName: "Webda.io Test"
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
- // Remove 1 unregistered and one registered from the ACL
393
- yield this.execute(ctx, "test.webda.io", "DELETE", `/companies/${company.getUuid()}/invitations`, {
394
- idents: ["test3@webda.io_email"],
395
- users: [ident1.getUser(), ident2.getUser()]
396
- });
397
- yield company.refresh();
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
- userCheck = yield this.authentication.getUserStore().get(ident1.getUser());
417
- assert.deepStrictEqual(userCheck["_companies"], [
418
- {
419
- model: "Test"
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
- userCheck = yield this.authentication.getUserStore().get(ident2.getUser());
423
- assert.deepStrictEqual(userCheck["_companies"], []);
424
- // Missing model
425
- yield this.invitations.setAttribute("test4@webda.io_email_invit", "invit_test", "all");
426
- // Register user 3 and 4
427
- yield this.authentication.createUserWithIdent("email", "test3@webda.io");
428
- yield this.authentication.createUserWithIdent("email", "test4@webda.io");
429
- yield this.authentication.getIdentStore().get(`test3@webda.io_email`);
430
- const ident4 = yield this.authentication.getIdentStore().get(`test4@webda.io_email`);
431
- yield company.refresh();
432
- assert.deepStrictEqual(company.__acl, {
433
- [user.getUuid()]: "all"
434
- });
435
- // @ts-ignore
436
- assert.deepStrictEqual(company.__invitations, {
437
- "ident_test4@webda.io_email": "read,write"
438
- });
439
- assert.deepStrictEqual((yield this.invitations.getAll()).map(i => (Object.assign({ uuid: i.getUuid() }, i[this.service.getInvitationAttribute(company.getUuid())]))), []);
440
- ctx2.getSession().userId = ident4.getUser();
441
- // Force refresh of user as we changed user manually
442
- yield ctx2.getCurrentUser(true);
443
- yield this.execute(ctx2, "test.webda.io", "PUT", `/companies/${company.getUuid()}/invitations`, {
444
- accept: true
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
- return __awaiter(this, void 0, void 0, function* () {
457
- this.service.getParameters().autoAccept = false;
458
- // New model as owner
459
- let ctx = yield this.newContext();
460
- let user = yield this.authentication.getUserStore().save({
461
- displayName: "Webda.io Test"
462
- });
463
- ctx.getSession().userId = user.getUuid();
464
- let res = yield this.execute(ctx, "test.webda.io", "POST", "/companies", { name: "MyTestCompany" });
465
- const company = yield this.store.get(res.uuid);
466
- // Auto register 2 users
467
- yield this.authentication.createUserWithIdent("email", "test1@webda.io");
468
- const ident1 = yield this.authentication.getIdentStore().get(`test1@webda.io_email`);
469
- // Add two users to the ACL
470
- // 1 unregistered , 1 registered
471
- yield this.execute(ctx, "test.webda.io", "POST", `/companies/${company.getUuid()}/invitations`, {
472
- idents: ["test2@webda.io_email"],
473
- users: [ident1.getUser()],
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
- mocha_1.test
491
+ test
498
492
  ], InvitationTest.prototype, "params", null);
499
493
  __decorate([
500
- mocha_1.test
494
+ test
501
495
  ], InvitationTest.prototype, "initNoTemplate", null);
502
496
  __decorate([
503
- mocha_1.test
497
+ test
504
498
  ], InvitationTest.prototype, "inviteOnMissing", null);
505
499
  __decorate([
506
- mocha_1.test
500
+ test
507
501
  ], InvitationTest.prototype, "inviteOnAclWithAutoAccept", null);
508
502
  __decorate([
509
- mocha_1.test
503
+ test
510
504
  ], InvitationTest.prototype, "inviteOnAclWithoutAutoAccept", null);
511
505
  __decorate([
512
- mocha_1.test
506
+ test
513
507
  ], InvitationTest.prototype, "invitationDeletedModel", null);
514
508
  InvitationTest = __decorate([
515
- mocha_1.suite
509
+ suite
516
510
  ], InvitationTest);
517
511
  //# sourceMappingURL=invitationservice.spec.js.map