cap-user-info 0.1.0 → 0.1.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/README.md CHANGED
@@ -29,6 +29,8 @@ associations `_toCreatedUserInfo` / `_toModifiedUserInfo` resolve via
29
29
  `UserTracked` extends `managed`, so consuming entities automatically
30
30
  inherit `createdBy` / `modifiedBy` (and the corresponding timestamps):
31
31
 
32
+ It will add a quickview to the createdBy and modifiedBy to show the user details. The details are stored from the req.user upon changes to the entity.
33
+ ![alt text](image.png)
32
34
  ```cds
33
35
  aspect UserTracked : managed { ... }
34
36
  ```
@@ -1,4 +1,4 @@
1
- import cds from '@sap/cds';
1
+ import cds from "@sap/cds";
2
2
  interface CsnEntity {
3
3
  name: string;
4
4
  kind?: string;
package/dist/handlers.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.hasUserTrackedAspect = hasUserTrackedAspect;
7
7
  exports.registerHandlers = registerHandlers;
8
8
  const cds_1 = __importDefault(require("@sap/cds"));
9
- const UPSERTED_FLAG = Symbol.for('cap-user-info.upserted-this-tx');
9
+ const UPSERTED_FLAG = Symbol.for("cap-user-info.upserted-this-tx");
10
10
  function hasUserTrackedAspect(entity) {
11
11
  const els = entity?.elements;
12
12
  if (!els)
@@ -15,27 +15,32 @@ function hasUserTrackedAspect(entity) {
15
15
  }
16
16
  async function upsertUserInfo(req) {
17
17
  const user = req.user;
18
- if (!user?.id || user.is('system-user') || user._is_anonymous)
18
+ if (!user?.id || user.is("system-user") || user._is_anonymous)
19
19
  return;
20
20
  const ctx = cds_1.default.context;
21
21
  if (ctx && ctx[UPSERTED_FLAG])
22
22
  return;
23
23
  if (ctx)
24
24
  ctx[UPSERTED_FLAG] = true;
25
- const { UserInfo } = cds_1.default.entities('cap.userinfo');
26
- const attr = user.attr ?? {};
25
+ const { UserInfo } = cds_1.default.entities("cap.userinfo");
26
+ let attr = user.attr ?? {};
27
+ if (Object.keys(attr).length === 0) {
28
+ attr.email = "Dummy@example.com";
29
+ attr.givenName = user.id || "FirstName";
30
+ attr.familyName = "LastName";
31
+ }
27
32
  await UPSERT.into(UserInfo).entries({
28
33
  ID: user.id,
29
34
  Email: attr.email,
30
35
  GivenName: attr.givenName,
31
- FamilyName: attr.familyName
36
+ FamilyName: attr.familyName,
32
37
  });
33
38
  }
34
39
  function registerHandlers(srv) {
35
40
  const tracked = [...srv.entities].filter(hasUserTrackedAspect);
36
41
  if (tracked.length === 0)
37
42
  return;
38
- srv.after(['CREATE', 'UPDATE'], tracked, async (_data, req) => {
43
+ srv.after(["CREATE", "UPDATE"], tracked, async (_data, req) => {
39
44
  await upsertUserInfo(req);
40
45
  });
41
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cap-user-info",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CDS plugin: track created/modified user details on managed entities",
5
5
  "main": "cds-plugin.js",
6
6
  "repository": {