directus 9.3.0 → 9.4.3

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 (92) hide show
  1. package/dist/app.js +25 -4
  2. package/dist/auth/auth.d.ts +4 -6
  3. package/dist/auth/auth.js +5 -9
  4. package/dist/auth/drivers/ldap.d.ts +3 -3
  5. package/dist/auth/drivers/ldap.js +2 -3
  6. package/dist/auth/drivers/local.d.ts +2 -2
  7. package/dist/auth/drivers/local.js +7 -13
  8. package/dist/auth/drivers/oauth2.d.ts +3 -3
  9. package/dist/auth/drivers/oauth2.js +4 -4
  10. package/dist/auth/drivers/openid.d.ts +3 -3
  11. package/dist/auth/drivers/openid.js +4 -4
  12. package/dist/cache.js +1 -3
  13. package/dist/cli/commands/schema/apply.js +1 -1
  14. package/dist/cli/index.js +1 -1
  15. package/dist/constants.d.ts +8 -0
  16. package/dist/constants.js +16 -2
  17. package/dist/controllers/activity.js +2 -1
  18. package/dist/controllers/auth.js +5 -4
  19. package/dist/controllers/extensions.js +1 -1
  20. package/dist/controllers/shares.d.ts +2 -0
  21. package/dist/controllers/shares.js +212 -0
  22. package/dist/controllers/users.js +21 -9
  23. package/dist/database/index.js +3 -0
  24. package/dist/database/migrations/20211211A-add-shares.d.ts +3 -0
  25. package/dist/database/migrations/20211211A-add-shares.js +38 -0
  26. package/dist/database/migrations/20211230A-add-project-descriptor.d.ts +3 -0
  27. package/dist/database/migrations/20211230A-add-project-descriptor.js +15 -0
  28. package/dist/database/migrations/run.js +1 -1
  29. package/dist/database/run-ast.js +5 -5
  30. package/dist/database/system-data/app-access-permissions/app-access-permissions.yaml +0 -15
  31. package/dist/database/system-data/app-access-permissions/index.d.ts +1 -0
  32. package/dist/database/system-data/app-access-permissions/index.js +4 -2
  33. package/dist/database/system-data/app-access-permissions/schema-access-permissions.yaml +17 -0
  34. package/dist/database/system-data/collections/collections.yaml +3 -0
  35. package/dist/database/system-data/fields/_defaults.yaml +2 -0
  36. package/dist/database/system-data/fields/sessions.yaml +1 -1
  37. package/dist/database/system-data/fields/settings.yaml +20 -1
  38. package/dist/database/system-data/fields/shares.yaml +77 -0
  39. package/dist/database/system-data/fields/users.yaml +1 -1
  40. package/dist/database/system-data/relations/relations.yaml +15 -0
  41. package/dist/env.js +4 -1
  42. package/dist/extensions.d.ts +11 -6
  43. package/dist/extensions.js +97 -42
  44. package/dist/middleware/authenticate.js +7 -16
  45. package/dist/middleware/check-ip.js +9 -6
  46. package/dist/middleware/rate-limiter.js +2 -1
  47. package/dist/middleware/respond.js +4 -1
  48. package/dist/services/activity.d.ts +2 -1
  49. package/dist/services/activity.js +2 -2
  50. package/dist/services/assets.js +3 -3
  51. package/dist/services/authentication.d.ts +2 -7
  52. package/dist/services/authentication.js +84 -41
  53. package/dist/services/authorization.js +3 -3
  54. package/dist/services/collections.d.ts +1 -2
  55. package/dist/services/collections.js +2 -2
  56. package/dist/services/files.d.ts +2 -2
  57. package/dist/services/graphql.d.ts +1 -1
  58. package/dist/services/graphql.js +51 -10
  59. package/dist/services/index.d.ts +1 -0
  60. package/dist/services/index.js +1 -0
  61. package/dist/services/items.d.ts +1 -15
  62. package/dist/services/notifications.d.ts +2 -2
  63. package/dist/services/permissions.d.ts +2 -2
  64. package/dist/services/roles.d.ts +2 -2
  65. package/dist/services/server.js +1 -0
  66. package/dist/services/shares.d.ts +17 -0
  67. package/dist/services/shares.js +135 -0
  68. package/dist/services/specifications.js +1 -1
  69. package/dist/services/users.d.ts +2 -2
  70. package/dist/services/webhooks.d.ts +2 -2
  71. package/dist/types/ast.d.ts +3 -3
  72. package/dist/types/auth.d.ts +31 -0
  73. package/dist/types/items.d.ts +14 -0
  74. package/dist/utils/apply-query.d.ts +0 -38
  75. package/dist/utils/apply-query.js +66 -67
  76. package/dist/utils/get-ast-from-query.js +3 -3
  77. package/dist/utils/get-default-value.js +3 -1
  78. package/dist/utils/get-ip-from-req.d.ts +2 -0
  79. package/dist/utils/get-ip-from-req.js +24 -0
  80. package/dist/utils/get-local-type.js +1 -1
  81. package/dist/utils/get-permissions.js +15 -7
  82. package/dist/utils/get-relation-type.d.ts +1 -1
  83. package/dist/utils/get-relation-type.js +1 -1
  84. package/dist/utils/merge-permissions-for-share.d.ts +5 -0
  85. package/dist/utils/merge-permissions-for-share.js +116 -0
  86. package/dist/utils/merge-permissions.d.ts +13 -1
  87. package/dist/utils/merge-permissions.js +27 -19
  88. package/dist/utils/reduce-schema.d.ts +2 -2
  89. package/dist/utils/reduce-schema.js +7 -7
  90. package/dist/utils/user-name.js +3 -0
  91. package/example.env +1 -1
  92. package/package.json +15 -13
@@ -1,66 +1,73 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergePermissions = void 0;
3
+ exports.mergePermission = exports.mergePermissions = void 0;
4
4
  const lodash_1 = require("lodash");
5
- function mergePermissions(...permissions) {
5
+ function mergePermissions(strategy, ...permissions) {
6
6
  const allPermissions = (0, lodash_1.flatten)(permissions);
7
7
  const mergedPermissions = allPermissions
8
8
  .reduce((acc, val) => {
9
9
  const key = `${val.collection}__${val.action}__${val.role || '$PUBLIC'}`;
10
10
  const current = acc.get(key);
11
- acc.set(key, current ? mergePerm(current, val) : val);
11
+ acc.set(key, current ? mergePermission(strategy, current, val) : val);
12
12
  return acc;
13
13
  }, new Map())
14
14
  .values();
15
- const result = Array.from(mergedPermissions).map((perm) => {
16
- return (0, lodash_1.omit)(perm, ['id', 'system']);
17
- });
18
- return result;
15
+ return Array.from(mergedPermissions);
19
16
  }
20
17
  exports.mergePermissions = mergePermissions;
21
- function mergePerm(currentPerm, newPerm) {
18
+ function mergePermission(strategy, currentPerm, newPerm) {
19
+ const logicalKey = `_${strategy}`;
22
20
  let permissions = currentPerm.permissions;
23
21
  let validation = currentPerm.validation;
24
22
  let fields = currentPerm.fields;
25
23
  let presets = currentPerm.presets;
26
24
  if (newPerm.permissions) {
27
- if (currentPerm.permissions && Object.keys(currentPerm.permissions)[0] === '_or') {
25
+ if (currentPerm.permissions && Object.keys(currentPerm.permissions)[0] === logicalKey) {
28
26
  permissions = {
29
- _or: [...currentPerm.permissions._or, newPerm.permissions],
27
+ [logicalKey]: [
28
+ ...currentPerm.permissions[logicalKey],
29
+ newPerm.permissions,
30
+ ],
30
31
  };
31
32
  }
32
33
  else if (currentPerm.permissions) {
33
34
  permissions = {
34
- _or: [currentPerm.permissions, newPerm.permissions],
35
+ [logicalKey]: [currentPerm.permissions, newPerm.permissions],
35
36
  };
36
37
  }
37
38
  else {
38
39
  permissions = {
39
- _or: [newPerm.permissions],
40
+ [logicalKey]: [newPerm.permissions],
40
41
  };
41
42
  }
42
43
  }
43
44
  if (newPerm.validation) {
44
- if (currentPerm.validation && Object.keys(currentPerm.validation)[0] === '_or') {
45
+ if (currentPerm.validation && Object.keys(currentPerm.validation)[0] === logicalKey) {
45
46
  validation = {
46
- _or: [...currentPerm.validation._or, newPerm.validation],
47
+ [logicalKey]: [
48
+ ...currentPerm.validation[logicalKey],
49
+ newPerm.validation,
50
+ ],
47
51
  };
48
52
  }
49
53
  else if (currentPerm.validation) {
50
54
  validation = {
51
- _or: [currentPerm.validation, newPerm.validation],
55
+ [logicalKey]: [currentPerm.validation, newPerm.validation],
52
56
  };
53
57
  }
54
58
  else {
55
59
  validation = {
56
- _or: [newPerm.validation],
60
+ [logicalKey]: [newPerm.validation],
57
61
  };
58
62
  }
59
63
  }
60
64
  if (newPerm.fields) {
61
- if (Array.isArray(currentPerm.fields)) {
65
+ if (Array.isArray(currentPerm.fields) && strategy === 'or') {
62
66
  fields = [...new Set([...currentPerm.fields, ...newPerm.fields])];
63
67
  }
68
+ else if (Array.isArray(currentPerm.fields) && strategy === 'and') {
69
+ fields = (0, lodash_1.intersection)(currentPerm.fields, newPerm.fields);
70
+ }
64
71
  else {
65
72
  fields = newPerm.fields;
66
73
  }
@@ -70,11 +77,12 @@ function mergePerm(currentPerm, newPerm) {
70
77
  if (newPerm.presets) {
71
78
  presets = (0, lodash_1.merge)({}, presets, newPerm.presets);
72
79
  }
73
- return {
80
+ return (0, lodash_1.omit)({
74
81
  ...currentPerm,
75
82
  permissions,
76
83
  validation,
77
84
  fields,
78
85
  presets,
79
- };
86
+ }, ['id', 'system']);
80
87
  }
88
+ exports.mergePermission = mergePermission;
@@ -1,5 +1,5 @@
1
1
  import { SchemaOverview } from '../types';
2
- import { Accountability, PermissionsAction } from '@directus/shared/types';
2
+ import { Permission, PermissionsAction } from '@directus/shared/types';
3
3
  /**
4
4
  * Reduces the schema based on the included permissions. The resulting object is the schema structure, but with only
5
5
  * the allowed collections/fields/relations included based on the permissions.
@@ -7,4 +7,4 @@ import { Accountability, PermissionsAction } from '@directus/shared/types';
7
7
  * @param actions Array of permissions actions (crud)
8
8
  * @returns Reduced schema
9
9
  */
10
- export declare function reduceSchema(schema: SchemaOverview, accountability: Accountability | null, actions?: PermissionsAction[]): SchemaOverview;
10
+ export declare function reduceSchema(schema: SchemaOverview, permissions: Permission[] | null, actions?: PermissionsAction[]): SchemaOverview;
@@ -9,13 +9,13 @@ const lodash_1 = require("lodash");
9
9
  * @param actions Array of permissions actions (crud)
10
10
  * @returns Reduced schema
11
11
  */
12
- function reduceSchema(schema, accountability, actions = ['create', 'read', 'update', 'delete']) {
13
- var _a, _b, _c, _d, _e;
12
+ function reduceSchema(schema, permissions, actions = ['create', 'read', 'update', 'delete']) {
13
+ var _a, _b, _c;
14
14
  const reduced = {
15
15
  collections: {},
16
16
  relations: [],
17
17
  };
18
- const allowedFieldsInCollection = (_b = (_a = accountability === null || accountability === void 0 ? void 0 : accountability.permissions) === null || _a === void 0 ? void 0 : _a.filter((permission) => actions.includes(permission.action)).reduce((acc, permission) => {
18
+ const allowedFieldsInCollection = (_a = permissions === null || permissions === void 0 ? void 0 : permissions.filter((permission) => actions.includes(permission.action)).reduce((acc, permission) => {
19
19
  if (!acc[permission.collection]) {
20
20
  acc[permission.collection] = [];
21
21
  }
@@ -23,13 +23,13 @@ function reduceSchema(schema, accountability, actions = ['create', 'read', 'upda
23
23
  acc[permission.collection] = (0, lodash_1.uniq)([...acc[permission.collection], ...permission.fields]);
24
24
  }
25
25
  return acc;
26
- }, {})) !== null && _b !== void 0 ? _b : {};
26
+ }, {})) !== null && _a !== void 0 ? _a : {};
27
27
  for (const [collectionName, collection] of Object.entries(schema.collections)) {
28
- if ((_c = accountability === null || accountability === void 0 ? void 0 : accountability.permissions) === null || _c === void 0 ? void 0 : _c.some((permission) => permission.collection === collectionName && actions.includes(permission.action))) {
28
+ if (permissions === null || permissions === void 0 ? void 0 : permissions.some((permission) => permission.collection === collectionName && actions.includes(permission.action))) {
29
29
  const fields = {};
30
30
  for (const [fieldName, field] of Object.entries(schema.collections[collectionName].fields)) {
31
- if (((_d = allowedFieldsInCollection[collectionName]) === null || _d === void 0 ? void 0 : _d.includes('*')) ||
32
- ((_e = allowedFieldsInCollection[collectionName]) === null || _e === void 0 ? void 0 : _e.includes(fieldName))) {
31
+ if (((_b = allowedFieldsInCollection[collectionName]) === null || _b === void 0 ? void 0 : _b.includes('*')) ||
32
+ ((_c = allowedFieldsInCollection[collectionName]) === null || _c === void 0 ? void 0 : _c.includes(fieldName))) {
33
33
  fields[fieldName] = field;
34
34
  }
35
35
  }
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.userName = void 0;
4
4
  function userName(user) {
5
+ if (!user) {
6
+ return 'Unknown User';
7
+ }
5
8
  if (user.first_name && user.last_name) {
6
9
  return `${user.first_name} ${user.last_name}`;
7
10
  }
package/example.env CHANGED
@@ -44,7 +44,7 @@ DB_PASSWORD="secret"
44
44
  # DB_PASSWORD="Test@123"
45
45
 
46
46
  ## OracleDB
47
- # DB_CLIENT="oracle"
47
+ # DB_CLIENT="oracledb"
48
48
  # DB_CONNECT_STRING="localhost:5104/XE"
49
49
  # DB_USER="secretsysuser"
50
50
  # DB_PASSWORD="secretpassword"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directus",
3
- "version": "9.3.0",
3
+ "version": "9.4.3",
4
4
  "license": "GPL-3.0-only",
5
5
  "homepage": "https://github.com/directus/directus#readme",
6
6
  "description": "Directus is a real-time API and App dashboard for managing SQL database content.",
@@ -60,7 +60,7 @@
60
60
  "prebuild": "npm run cleanup",
61
61
  "build": "tsc --build && copyfiles \"src/**/*.*\" -e \"src/**/*.ts\" -u 1 dist",
62
62
  "cleanup": "rimraf dist",
63
- "dev": "cross-env NODE_ENV=development SERVE_APP=false ts-node-dev --files --transpile-only --respawn --watch \".env\" --inspect --exit-child -- src/start.ts",
63
+ "dev": "cross-env NODE_ENV=development SERVE_APP=false ts-node-dev --files --transpile-only --respawn --watch \".env\" --inspect=0 --exit-child -- src/start.ts",
64
64
  "cli": "cross-env NODE_ENV=development SERVE_APP=false ts-node --script-mode --transpile-only src/cli/run.ts",
65
65
  "test": "jest --coverage",
66
66
  "test:watch": "jest --watchAll"
@@ -76,16 +76,16 @@
76
76
  ],
77
77
  "dependencies": {
78
78
  "@aws-sdk/client-ses": "^3.40.0",
79
- "@directus/app": "9.3.0",
80
- "@directus/drive": "9.3.0",
81
- "@directus/drive-azure": "9.3.0",
82
- "@directus/drive-gcs": "9.3.0",
83
- "@directus/drive-s3": "9.3.0",
84
- "@directus/extensions-sdk": "9.3.0",
85
- "@directus/format-title": "9.3.0",
86
- "@directus/schema": "9.3.0",
87
- "@directus/shared": "9.3.0",
88
- "@directus/specs": "9.3.0",
79
+ "@directus/app": "9.4.3",
80
+ "@directus/drive": "9.4.3",
81
+ "@directus/drive-azure": "9.4.3",
82
+ "@directus/drive-gcs": "9.4.3",
83
+ "@directus/drive-s3": "9.4.3",
84
+ "@directus/extensions-sdk": "9.4.3",
85
+ "@directus/format-title": "9.4.3",
86
+ "@directus/schema": "9.4.3",
87
+ "@directus/shared": "9.4.3",
88
+ "@directus/specs": "9.4.3",
89
89
  "@godaddy/terminus": "^4.9.0",
90
90
  "@rollup/plugin-alias": "^3.1.2",
91
91
  "@rollup/plugin-virtual": "^2.0.3",
@@ -97,6 +97,7 @@
97
97
  "busboy": "^0.3.1",
98
98
  "camelcase": "^6.2.0",
99
99
  "chalk": "^4.1.1",
100
+ "chokidar": "^3.5.2",
100
101
  "commander": "^8.0.0",
101
102
  "cookie-parser": "^1.4.5",
102
103
  "cors": "^2.8.5",
@@ -114,6 +115,7 @@
114
115
  "fs-extra": "^10.0.0",
115
116
  "graphql": "^15.5.0",
116
117
  "graphql-compose": "^9.0.1",
118
+ "helmet": "^4.6.0",
117
119
  "inquirer": "^8.1.1",
118
120
  "joi": "^17.3.0",
119
121
  "js-yaml": "^4.1.0",
@@ -169,7 +171,7 @@
169
171
  "sqlite3": "^5.0.2",
170
172
  "tedious": "^13.0.0"
171
173
  },
172
- "gitHead": "4b444baf5b73467a74f6d57c33277146bc86285c",
174
+ "gitHead": "65bfe68b0c7993a1bd5b0daac0855265911313d0",
173
175
  "devDependencies": {
174
176
  "@types/async": "3.2.10",
175
177
  "@types/atob": "2.1.2",