@directus/api 20.0.0-rc.0 → 20.0.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.
- package/dist/app.js +9 -4
- package/dist/auth/drivers/ldap.js +4 -4
- package/dist/auth/drivers/local.js +4 -4
- package/dist/auth/drivers/oauth2.js +4 -4
- package/dist/auth/drivers/openid.js +4 -2
- package/dist/cache.js +0 -3
- package/dist/cli/commands/bootstrap/index.js +2 -8
- package/dist/cli/commands/init/index.js +10 -9
- package/dist/cli/utils/defaults.d.ts +11 -4
- package/dist/cli/utils/defaults.js +1 -7
- package/dist/constants.d.ts +9 -1
- package/dist/constants.js +10 -0
- package/dist/controllers/auth.js +16 -5
- package/dist/controllers/permissions.js +2 -14
- package/dist/controllers/roles.js +1 -22
- package/dist/controllers/{access.d.ts → tus.d.ts} +1 -0
- package/dist/controllers/tus.js +72 -0
- package/dist/controllers/users.js +55 -0
- package/dist/database/helpers/fn/types.d.ts +1 -2
- package/dist/database/helpers/fn/types.js +1 -1
- package/dist/database/helpers/geometry/dialects/mssql.d.ts +1 -1
- package/dist/database/helpers/geometry/dialects/mssql.js +2 -4
- package/dist/database/helpers/geometry/dialects/mysql.js +1 -1
- package/dist/database/helpers/geometry/dialects/oracle.d.ts +1 -1
- package/dist/database/helpers/geometry/dialects/oracle.js +3 -5
- package/dist/database/helpers/geometry/types.d.ts +1 -1
- package/dist/database/helpers/geometry/types.js +2 -4
- package/dist/database/index.js +1 -2
- package/dist/database/migrations/20240701A-add-tus-data.js +12 -0
- package/dist/database/{run-ast/types.d.ts → run-ast.d.ts} +9 -3
- package/dist/database/run-ast.js +450 -0
- package/dist/flows.js +4 -3
- package/dist/middleware/authenticate.js +7 -2
- package/dist/middleware/cache.js +1 -1
- package/dist/middleware/check-ip.d.ts +2 -0
- package/dist/middleware/check-ip.js +37 -0
- package/dist/middleware/get-permissions.d.ts +3 -0
- package/dist/middleware/get-permissions.js +10 -0
- package/dist/middleware/respond.js +1 -1
- package/dist/services/activity.js +10 -22
- package/dist/services/assets.d.ts +3 -2
- package/dist/services/assets.js +5 -10
- package/dist/services/authentication.js +26 -32
- package/dist/services/authorization.d.ts +17 -0
- package/dist/services/authorization.js +456 -0
- package/dist/services/collections.js +17 -18
- package/dist/services/fields.d.ts +1 -0
- package/dist/services/fields.js +24 -53
- package/dist/services/files/lib/extract-metadata.d.ts +3 -0
- package/dist/services/files/lib/extract-metadata.js +32 -0
- package/dist/services/files/utils/get-metadata.d.ts +5 -0
- package/dist/services/files/utils/get-metadata.js +107 -0
- package/dist/services/files.d.ts +4 -6
- package/dist/services/files.js +24 -140
- package/dist/services/graphql/index.d.ts +3 -3
- package/dist/services/graphql/index.js +22 -126
- package/dist/services/graphql/subscription.js +4 -2
- package/dist/services/import-export.js +4 -18
- package/dist/services/index.d.ts +2 -3
- package/dist/services/index.js +2 -3
- package/dist/services/items.js +44 -115
- package/dist/services/meta.js +23 -60
- package/dist/services/payload.d.ts +10 -9
- package/dist/services/payload.js +3 -18
- package/dist/services/{permissions.d.ts → permissions/index.d.ts} +7 -5
- package/dist/services/{permissions.js → permissions/index.js} +54 -30
- package/dist/{permissions → services/permissions}/lib/with-app-minimal-permissions.d.ts +1 -1
- package/dist/services/permissions/lib/with-app-minimal-permissions.js +13 -0
- package/dist/services/relations.d.ts +6 -0
- package/dist/services/relations.js +29 -26
- package/dist/services/roles.d.ts +12 -4
- package/dist/services/roles.js +424 -57
- package/dist/services/server.js +6 -0
- package/dist/services/shares.d.ts +2 -0
- package/dist/services/shares.js +8 -12
- package/dist/services/specifications.d.ts +2 -2
- package/dist/services/specifications.js +27 -39
- package/dist/services/tus/data-store.d.ts +36 -0
- package/dist/services/tus/data-store.js +214 -0
- package/dist/services/tus/index.d.ts +2 -0
- package/dist/services/tus/index.js +2 -0
- package/dist/services/tus/lockers.d.ts +36 -0
- package/dist/services/tus/lockers.js +83 -0
- package/dist/services/tus/server.d.ts +8 -0
- package/dist/services/tus/server.js +80 -0
- package/dist/services/tus/utils/wait-timeout.d.ts +1 -0
- package/dist/services/tus/utils/wait-timeout.js +13 -0
- package/dist/services/users.d.ts +5 -1
- package/dist/services/users.js +161 -78
- package/dist/services/utils.js +7 -11
- package/dist/services/versions.d.ts +2 -0
- package/dist/services/versions.js +10 -34
- package/dist/storage/register-locations.js +5 -1
- package/dist/telemetry/lib/get-report.js +2 -2
- package/dist/telemetry/utils/check-increased-user-limits.d.ts +7 -0
- package/dist/telemetry/utils/check-increased-user-limits.js +25 -0
- package/dist/telemetry/utils/get-role-counts-by-roles.d.ts +6 -0
- package/dist/telemetry/utils/get-role-counts-by-roles.js +27 -0
- package/dist/telemetry/utils/get-role-counts-by-users.d.ts +11 -0
- package/dist/telemetry/utils/get-role-counts-by-users.js +34 -0
- package/dist/telemetry/utils/get-user-count.d.ts +8 -0
- package/dist/telemetry/utils/get-user-count.js +33 -0
- package/dist/telemetry/utils/get-user-counts-by-roles.d.ts +7 -0
- package/dist/telemetry/utils/get-user-counts-by-roles.js +35 -0
- package/dist/types/ast.d.ts +1 -43
- package/dist/types/items.d.ts +0 -11
- package/dist/utils/apply-query.d.ts +3 -4
- package/dist/utils/apply-query.js +8 -37
- package/dist/utils/get-accountability-for-role.js +25 -16
- package/dist/utils/get-accountability-for-token.js +16 -17
- package/dist/utils/get-ast-from-query.d.ts +13 -0
- package/dist/utils/get-ast-from-query.js +297 -0
- package/dist/utils/get-cache-key.d.ts +1 -1
- package/dist/utils/get-cache-key.js +1 -12
- package/dist/utils/get-column.d.ts +1 -2
- package/dist/utils/get-column.js +0 -1
- package/dist/utils/get-permissions.d.ts +2 -0
- package/dist/utils/get-permissions.js +150 -0
- package/dist/utils/get-service.js +1 -5
- package/dist/utils/merge-permissions-for-share.d.ts +4 -0
- package/dist/utils/merge-permissions-for-share.js +109 -0
- package/dist/utils/merge-permissions.d.ts +3 -0
- package/dist/utils/merge-permissions.js +95 -0
- package/dist/utils/reduce-schema.d.ts +6 -4
- package/dist/utils/reduce-schema.js +34 -14
- package/dist/utils/verify-session-jwt.js +2 -1
- package/dist/websocket/authenticate.d.ts +2 -0
- package/dist/websocket/authenticate.js +12 -0
- package/dist/websocket/controllers/graphql.js +4 -1
- package/dist/websocket/controllers/hooks.js +0 -4
- package/dist/websocket/controllers/rest.js +2 -0
- package/dist/websocket/handlers/subscribe.js +2 -0
- package/dist/websocket/utils/items.d.ts +1 -1
- package/package.json +35 -33
- package/dist/controllers/access.js +0 -148
- package/dist/controllers/policies.d.ts +0 -2
- package/dist/controllers/policies.js +0 -169
- package/dist/database/get-ast-from-query/get-ast-from-query.d.ts +0 -16
- package/dist/database/get-ast-from-query/get-ast-from-query.js +0 -82
- package/dist/database/get-ast-from-query/lib/convert-wildcards.d.ts +0 -13
- package/dist/database/get-ast-from-query/lib/convert-wildcards.js +0 -69
- package/dist/database/get-ast-from-query/lib/parse-fields.d.ts +0 -15
- package/dist/database/get-ast-from-query/lib/parse-fields.js +0 -190
- package/dist/database/get-ast-from-query/utils/get-deep-query.d.ts +0 -14
- package/dist/database/get-ast-from-query/utils/get-deep-query.js +0 -17
- package/dist/database/get-ast-from-query/utils/get-related-collection.d.ts +0 -2
- package/dist/database/get-ast-from-query/utils/get-related-collection.js +0 -13
- package/dist/database/get-ast-from-query/utils/get-relation.d.ts +0 -2
- package/dist/database/get-ast-from-query/utils/get-relation.js +0 -7
- package/dist/database/migrations/20240619A-permissions-policies.js +0 -163
- package/dist/database/run-ast/lib/get-db-query.d.ts +0 -4
- package/dist/database/run-ast/lib/get-db-query.js +0 -194
- package/dist/database/run-ast/lib/parse-current-level.d.ts +0 -7
- package/dist/database/run-ast/lib/parse-current-level.js +0 -41
- package/dist/database/run-ast/run-ast.d.ts +0 -7
- package/dist/database/run-ast/run-ast.js +0 -107
- package/dist/database/run-ast/types.js +0 -1
- package/dist/database/run-ast/utils/apply-case-when.d.ts +0 -16
- package/dist/database/run-ast/utils/apply-case-when.js +0 -26
- package/dist/database/run-ast/utils/apply-parent-filters.d.ts +0 -3
- package/dist/database/run-ast/utils/apply-parent-filters.js +0 -55
- package/dist/database/run-ast/utils/get-column-pre-processor.d.ts +0 -10
- package/dist/database/run-ast/utils/get-column-pre-processor.js +0 -57
- package/dist/database/run-ast/utils/get-field-alias.d.ts +0 -2
- package/dist/database/run-ast/utils/get-field-alias.js +0 -4
- package/dist/database/run-ast/utils/get-inner-query-column-pre-processor.d.ts +0 -5
- package/dist/database/run-ast/utils/get-inner-query-column-pre-processor.js +0 -23
- package/dist/database/run-ast/utils/merge-with-parent-items.d.ts +0 -3
- package/dist/database/run-ast/utils/merge-with-parent-items.js +0 -87
- package/dist/database/run-ast/utils/remove-temporary-fields.d.ts +0 -3
- package/dist/database/run-ast/utils/remove-temporary-fields.js +0 -73
- package/dist/permissions/cache.d.ts +0 -2
- package/dist/permissions/cache.js +0 -23
- package/dist/permissions/lib/fetch-permissions.d.ts +0 -10
- package/dist/permissions/lib/fetch-permissions.js +0 -55
- package/dist/permissions/lib/fetch-policies.d.ts +0 -7
- package/dist/permissions/lib/fetch-policies.js +0 -28
- package/dist/permissions/lib/fetch-roles-tree.d.ts +0 -3
- package/dist/permissions/lib/fetch-roles-tree.js +0 -28
- package/dist/permissions/lib/with-app-minimal-permissions.js +0 -10
- package/dist/permissions/modules/fetch-accountability-collection-access/fetch-accountability-collection-access.d.ts +0 -7
- package/dist/permissions/modules/fetch-accountability-collection-access/fetch-accountability-collection-access.js +0 -56
- package/dist/permissions/modules/fetch-accountability-policy-globals/fetch-accountability-policy-globals.d.ts +0 -3
- package/dist/permissions/modules/fetch-accountability-policy-globals/fetch-accountability-policy-globals.js +0 -16
- package/dist/permissions/modules/fetch-allowed-collections/fetch-allowed-collections.d.ts +0 -8
- package/dist/permissions/modules/fetch-allowed-collections/fetch-allowed-collections.js +0 -24
- package/dist/permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.d.ts +0 -9
- package/dist/permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.js +0 -31
- package/dist/permissions/modules/fetch-allowed-fields/fetch-allowed-fields.d.ts +0 -16
- package/dist/permissions/modules/fetch-allowed-fields/fetch-allowed-fields.js +0 -27
- package/dist/permissions/modules/fetch-global-access/fetch-global-access.d.ts +0 -10
- package/dist/permissions/modules/fetch-global-access/fetch-global-access.js +0 -23
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.d.ts +0 -5
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.js +0 -7
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.d.ts +0 -5
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.js +0 -10
- package/dist/permissions/modules/fetch-global-access/types.d.ts +0 -4
- package/dist/permissions/modules/fetch-global-access/types.js +0 -1
- package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.d.ts +0 -4
- package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.js +0 -27
- package/dist/permissions/modules/fetch-inconsistent-field-map/fetch-inconsistent-field-map.d.ts +0 -12
- package/dist/permissions/modules/fetch-inconsistent-field-map/fetch-inconsistent-field-map.js +0 -32
- package/dist/permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.d.ts +0 -4
- package/dist/permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.js +0 -29
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-children.d.ts +0 -4
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-children.js +0 -49
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-query.d.ts +0 -3
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-query.js +0 -56
- package/dist/permissions/modules/process-ast/lib/field-map-from-ast.d.ts +0 -4
- package/dist/permissions/modules/process-ast/lib/field-map-from-ast.js +0 -8
- package/dist/permissions/modules/process-ast/lib/inject-cases.d.ts +0 -9
- package/dist/permissions/modules/process-ast/lib/inject-cases.js +0 -93
- package/dist/permissions/modules/process-ast/process-ast.d.ts +0 -9
- package/dist/permissions/modules/process-ast/process-ast.js +0 -39
- package/dist/permissions/modules/process-ast/types.d.ts +0 -24
- package/dist/permissions/modules/process-ast/types.js +0 -1
- package/dist/permissions/modules/process-ast/utils/collections-in-field-map.d.ts +0 -2
- package/dist/permissions/modules/process-ast/utils/collections-in-field-map.js +0 -7
- package/dist/permissions/modules/process-ast/utils/dedupe-access.d.ts +0 -12
- package/dist/permissions/modules/process-ast/utils/dedupe-access.js +0 -30
- package/dist/permissions/modules/process-ast/utils/extract-paths-from-query.d.ts +0 -15
- package/dist/permissions/modules/process-ast/utils/extract-paths-from-query.js +0 -50
- package/dist/permissions/modules/process-ast/utils/find-related-collection.d.ts +0 -3
- package/dist/permissions/modules/process-ast/utils/find-related-collection.js +0 -9
- package/dist/permissions/modules/process-ast/utils/flatten-filter.d.ts +0 -3
- package/dist/permissions/modules/process-ast/utils/flatten-filter.js +0 -24
- package/dist/permissions/modules/process-ast/utils/format-a2o-key.d.ts +0 -1
- package/dist/permissions/modules/process-ast/utils/format-a2o-key.js +0 -3
- package/dist/permissions/modules/process-ast/utils/get-info-for-path.d.ts +0 -5
- package/dist/permissions/modules/process-ast/utils/get-info-for-path.js +0 -7
- package/dist/permissions/modules/process-ast/utils/has-item-permissions.d.ts +0 -2
- package/dist/permissions/modules/process-ast/utils/has-item-permissions.js +0 -3
- package/dist/permissions/modules/process-ast/utils/stringify-query-path.d.ts +0 -2
- package/dist/permissions/modules/process-ast/utils/stringify-query-path.js +0 -3
- package/dist/permissions/modules/process-ast/utils/validate-path/create-error.d.ts +0 -3
- package/dist/permissions/modules/process-ast/utils/validate-path/create-error.js +0 -16
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-existence.d.ts +0 -2
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-existence.js +0 -12
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-permissions.d.ts +0 -2
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-permissions.js +0 -28
- package/dist/permissions/modules/process-payload/lib/is-field-nullable.d.ts +0 -5
- package/dist/permissions/modules/process-payload/lib/is-field-nullable.js +0 -12
- package/dist/permissions/modules/process-payload/process-payload.d.ts +0 -13
- package/dist/permissions/modules/process-payload/process-payload.js +0 -77
- package/dist/permissions/modules/validate-access/lib/validate-collection-access.d.ts +0 -12
- package/dist/permissions/modules/validate-access/lib/validate-collection-access.js +0 -11
- package/dist/permissions/modules/validate-access/lib/validate-item-access.d.ts +0 -9
- package/dist/permissions/modules/validate-access/lib/validate-item-access.js +0 -33
- package/dist/permissions/modules/validate-access/validate-access.d.ts +0 -14
- package/dist/permissions/modules/validate-access/validate-access.js +0 -28
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.d.ts +0 -1
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.js +0 -8
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-users.d.ts +0 -5
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-users.js +0 -10
- package/dist/permissions/types.d.ts +0 -6
- package/dist/permissions/types.js +0 -1
- package/dist/permissions/utils/create-default-accountability.d.ts +0 -2
- package/dist/permissions/utils/create-default-accountability.js +0 -11
- package/dist/permissions/utils/extract-required-dynamic-variable-context.d.ts +0 -8
- package/dist/permissions/utils/extract-required-dynamic-variable-context.js +0 -27
- package/dist/permissions/utils/fetch-dynamic-variable-context.d.ts +0 -9
- package/dist/permissions/utils/fetch-dynamic-variable-context.js +0 -43
- package/dist/permissions/utils/filter-policies-by-ip.d.ts +0 -2
- package/dist/permissions/utils/filter-policies-by-ip.js +0 -15
- package/dist/permissions/utils/get-unaliased-field-key.d.ts +0 -5
- package/dist/permissions/utils/get-unaliased-field-key.js +0 -17
- package/dist/permissions/utils/process-permissions.d.ts +0 -7
- package/dist/permissions/utils/process-permissions.js +0 -9
- package/dist/permissions/utils/with-cache.d.ts +0 -10
- package/dist/permissions/utils/with-cache.js +0 -25
- package/dist/services/access.d.ts +0 -10
- package/dist/services/access.js +0 -43
- package/dist/services/policies.d.ts +0 -12
- package/dist/services/policies.js +0 -87
- package/dist/telemetry/utils/check-user-limits.d.ts +0 -5
- package/dist/telemetry/utils/check-user-limits.js +0 -19
- package/dist/utils/fetch-user-count/fetch-access-lookup.d.ts +0 -17
- package/dist/utils/fetch-user-count/fetch-access-lookup.js +0 -22
- package/dist/utils/fetch-user-count/fetch-access-roles.d.ts +0 -16
- package/dist/utils/fetch-user-count/fetch-access-roles.js +0 -37
- package/dist/utils/fetch-user-count/fetch-active-users.d.ts +0 -6
- package/dist/utils/fetch-user-count/fetch-active-users.js +0 -3
- package/dist/utils/fetch-user-count/fetch-user-count.d.ts +0 -12
- package/dist/utils/fetch-user-count/fetch-user-count.js +0 -57
- package/dist/utils/fetch-user-count/get-user-count-query.d.ts +0 -20
- package/dist/utils/fetch-user-count/get-user-count-query.js +0 -17
- package/dist/utils/validate-user-count-integrity.d.ts +0 -13
- package/dist/utils/validate-user-count-integrity.js +0 -29
- /package/dist/database/migrations/{20240619A-permissions-policies.d.ts → 20240701A-add-tus-data.d.ts} +0 -0
- /package/dist/{utils → services/files/utils}/parse-image-metadata.d.ts +0 -0
- /package/dist/{utils → services/files/utils}/parse-image-metadata.js +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { flatten, intersection, isEqual, merge, omit } from 'lodash-es';
|
|
2
|
+
export function mergePermissions(strategy, ...permissions) {
|
|
3
|
+
const allPermissions = flatten(permissions);
|
|
4
|
+
const mergedPermissions = allPermissions
|
|
5
|
+
.reduce((acc, val) => {
|
|
6
|
+
const key = `${val.collection}__${val.action}__${val.role || '$PUBLIC'}`;
|
|
7
|
+
const current = acc.get(key);
|
|
8
|
+
acc.set(key, current ? mergePermission(strategy, current, val) : val);
|
|
9
|
+
return acc;
|
|
10
|
+
}, new Map())
|
|
11
|
+
.values();
|
|
12
|
+
return Array.from(mergedPermissions);
|
|
13
|
+
}
|
|
14
|
+
export function mergePermission(strategy, currentPerm, newPerm) {
|
|
15
|
+
const logicalKey = `_${strategy}`;
|
|
16
|
+
let permissions = currentPerm.permissions;
|
|
17
|
+
let validation = currentPerm.validation;
|
|
18
|
+
let fields = currentPerm.fields;
|
|
19
|
+
let presets = currentPerm.presets;
|
|
20
|
+
if (newPerm.permissions) {
|
|
21
|
+
if (currentPerm.permissions && Object.keys(currentPerm.permissions)[0] === logicalKey) {
|
|
22
|
+
permissions = {
|
|
23
|
+
[logicalKey]: [
|
|
24
|
+
...currentPerm.permissions[logicalKey],
|
|
25
|
+
newPerm.permissions,
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
else if (currentPerm.permissions) {
|
|
30
|
+
// Empty {} supersedes other permissions in _OR merge
|
|
31
|
+
if (strategy === 'or' && (isEqual(currentPerm.permissions, {}) || isEqual(newPerm.permissions, {}))) {
|
|
32
|
+
permissions = {};
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
permissions = {
|
|
36
|
+
[logicalKey]: [currentPerm.permissions, newPerm.permissions],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
permissions = {
|
|
42
|
+
[logicalKey]: [newPerm.permissions],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (newPerm.validation) {
|
|
47
|
+
if (currentPerm.validation && Object.keys(currentPerm.validation)[0] === logicalKey) {
|
|
48
|
+
validation = {
|
|
49
|
+
[logicalKey]: [
|
|
50
|
+
...currentPerm.validation[logicalKey],
|
|
51
|
+
newPerm.validation,
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else if (currentPerm.validation) {
|
|
56
|
+
// Empty {} supersedes other validations in _OR merge
|
|
57
|
+
if (strategy === 'or' && (isEqual(currentPerm.validation, {}) || isEqual(newPerm.validation, {}))) {
|
|
58
|
+
validation = {};
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
validation = {
|
|
62
|
+
[logicalKey]: [currentPerm.validation, newPerm.validation],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
validation = {
|
|
68
|
+
[logicalKey]: [newPerm.validation],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (newPerm.fields) {
|
|
73
|
+
if (Array.isArray(currentPerm.fields) && strategy === 'or') {
|
|
74
|
+
fields = [...new Set([...currentPerm.fields, ...newPerm.fields])];
|
|
75
|
+
}
|
|
76
|
+
else if (Array.isArray(currentPerm.fields) && strategy === 'and') {
|
|
77
|
+
fields = intersection(currentPerm.fields, newPerm.fields);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
fields = newPerm.fields;
|
|
81
|
+
}
|
|
82
|
+
if (fields.includes('*'))
|
|
83
|
+
fields = ['*'];
|
|
84
|
+
}
|
|
85
|
+
if (newPerm.presets) {
|
|
86
|
+
presets = merge({}, presets, newPerm.presets);
|
|
87
|
+
}
|
|
88
|
+
return omit({
|
|
89
|
+
...currentPerm,
|
|
90
|
+
permissions,
|
|
91
|
+
validation,
|
|
92
|
+
fields,
|
|
93
|
+
presets,
|
|
94
|
+
}, ['id', 'system']);
|
|
95
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { SchemaOverview } from '@directus/types';
|
|
2
|
-
import type { FieldMap } from '../permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.js';
|
|
1
|
+
import type { Permission, PermissionsAction, SchemaOverview } from '@directus/types';
|
|
3
2
|
/**
|
|
4
3
|
* Reduces the schema based on the included permissions. The resulting object is the schema structure, but with only
|
|
5
|
-
* the allowed collections/fields/relations included based on the
|
|
4
|
+
* the allowed collections/fields/relations included based on the permissions.
|
|
5
|
+
* @param schema The full project schema
|
|
6
|
+
* @param actions Array of permissions actions (crud)
|
|
7
|
+
* @returns Reduced schema
|
|
6
8
|
*/
|
|
7
|
-
export declare function reduceSchema(schema: SchemaOverview,
|
|
9
|
+
export declare function reduceSchema(schema: SchemaOverview, permissions: Permission[] | null, actions?: PermissionsAction[]): SchemaOverview;
|
|
@@ -1,20 +1,40 @@
|
|
|
1
|
+
import { uniq } from 'lodash-es';
|
|
1
2
|
/**
|
|
2
3
|
* Reduces the schema based on the included permissions. The resulting object is the schema structure, but with only
|
|
3
|
-
* the allowed collections/fields/relations included based on the
|
|
4
|
+
* the allowed collections/fields/relations included based on the permissions.
|
|
5
|
+
* @param schema The full project schema
|
|
6
|
+
* @param actions Array of permissions actions (crud)
|
|
7
|
+
* @returns Reduced schema
|
|
4
8
|
*/
|
|
5
|
-
export function reduceSchema(schema,
|
|
9
|
+
export function reduceSchema(schema, permissions, actions = ['create', 'read', 'update', 'delete']) {
|
|
6
10
|
const reduced = {
|
|
7
11
|
collections: {},
|
|
8
12
|
relations: [],
|
|
9
13
|
};
|
|
14
|
+
const allowedFieldsInCollection = permissions
|
|
15
|
+
?.filter((permission) => actions.includes(permission.action))
|
|
16
|
+
.reduce((acc, permission) => {
|
|
17
|
+
if (!acc[permission.collection]) {
|
|
18
|
+
acc[permission.collection] = [];
|
|
19
|
+
}
|
|
20
|
+
if (permission.fields) {
|
|
21
|
+
acc[permission.collection] = uniq([...acc[permission.collection], ...permission.fields]);
|
|
22
|
+
}
|
|
23
|
+
return acc;
|
|
24
|
+
}, {}) ?? {};
|
|
10
25
|
for (const [collectionName, collection] of Object.entries(schema.collections)) {
|
|
26
|
+
if (!permissions?.some((permission) => permission.collection === collectionName && actions.includes(permission.action))) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
11
29
|
const fields = {};
|
|
12
30
|
for (const [fieldName, field] of Object.entries(schema.collections[collectionName].fields)) {
|
|
13
|
-
if (!
|
|
31
|
+
if (!allowedFieldsInCollection[collectionName]?.includes('*') &&
|
|
32
|
+
!allowedFieldsInCollection[collectionName]?.includes(fieldName)) {
|
|
14
33
|
continue;
|
|
15
34
|
}
|
|
16
35
|
const o2mRelation = schema.relations.find((relation) => relation.related_collection === collectionName && relation.meta?.one_field === fieldName);
|
|
17
|
-
if (o2mRelation &&
|
|
36
|
+
if (o2mRelation &&
|
|
37
|
+
!permissions?.some((permission) => permission.collection === o2mRelation.collection && actions.includes(permission.action))) {
|
|
18
38
|
continue;
|
|
19
39
|
}
|
|
20
40
|
fields[fieldName] = field;
|
|
@@ -27,29 +47,29 @@ export function reduceSchema(schema, fieldMap) {
|
|
|
27
47
|
reduced.relations = schema.relations.filter((relation) => {
|
|
28
48
|
let collectionsAllowed = true;
|
|
29
49
|
let fieldsAllowed = true;
|
|
30
|
-
if (Object.keys(
|
|
50
|
+
if (Object.keys(allowedFieldsInCollection).includes(relation.collection) === false) {
|
|
31
51
|
collectionsAllowed = false;
|
|
32
52
|
}
|
|
33
53
|
if (relation.related_collection &&
|
|
34
|
-
(Object.keys(
|
|
54
|
+
(Object.keys(allowedFieldsInCollection).includes(relation.related_collection) === false ||
|
|
35
55
|
// Ignore legacy permissions with an empty fields array
|
|
36
|
-
|
|
56
|
+
allowedFieldsInCollection[relation.related_collection]?.length === 0)) {
|
|
37
57
|
collectionsAllowed = false;
|
|
38
58
|
}
|
|
39
59
|
if (relation.meta?.one_allowed_collections &&
|
|
40
|
-
relation.meta.one_allowed_collections.every((collection) => Object.keys(
|
|
60
|
+
relation.meta.one_allowed_collections.every((collection) => Object.keys(allowedFieldsInCollection).includes(collection)) === false) {
|
|
41
61
|
collectionsAllowed = false;
|
|
42
62
|
}
|
|
43
|
-
if (!
|
|
44
|
-
(
|
|
45
|
-
|
|
63
|
+
if (!allowedFieldsInCollection[relation.collection] ||
|
|
64
|
+
(allowedFieldsInCollection[relation.collection]?.includes('*') === false &&
|
|
65
|
+
allowedFieldsInCollection[relation.collection]?.includes(relation.field) === false)) {
|
|
46
66
|
fieldsAllowed = false;
|
|
47
67
|
}
|
|
48
68
|
if (relation.related_collection &&
|
|
49
69
|
relation.meta?.one_field &&
|
|
50
|
-
(!
|
|
51
|
-
(
|
|
52
|
-
|
|
70
|
+
(!allowedFieldsInCollection[relation.related_collection] ||
|
|
71
|
+
(allowedFieldsInCollection[relation.related_collection]?.includes('*') === false &&
|
|
72
|
+
allowedFieldsInCollection[relation.related_collection]?.includes(relation.meta?.one_field) === false))) {
|
|
53
73
|
fieldsAllowed = false;
|
|
54
74
|
}
|
|
55
75
|
return collectionsAllowed && fieldsAllowed;
|
|
@@ -12,7 +12,8 @@ export async function verifySessionJWT(payload) {
|
|
|
12
12
|
.from('directus_sessions')
|
|
13
13
|
.where({
|
|
14
14
|
token: payload['session'],
|
|
15
|
-
user: payload['id'],
|
|
15
|
+
user: payload['id'] || null,
|
|
16
|
+
share: payload['share'] || null,
|
|
16
17
|
})
|
|
17
18
|
.andWhere('expires', '>=', new Date())
|
|
18
19
|
.first();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Accountability } from '@directus/types';
|
|
1
2
|
import type { BasicAuthMessage } from './messages.js';
|
|
2
3
|
import type { AuthenticationState } from './types.js';
|
|
3
4
|
export declare function authenticateConnection(message: BasicAuthMessage & Record<string, any>): Promise<AuthenticationState>;
|
|
5
|
+
export declare function refreshAccountability(accountability: Accountability | null | undefined): Promise<Accountability>;
|
|
4
6
|
export declare function authenticationSuccess(uid?: string | number, refresh_token?: string): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_AUTH_PROVIDER } from '../constants.js';
|
|
2
2
|
import { AuthenticationService } from '../services/index.js';
|
|
3
3
|
import { getAccountabilityForToken } from '../utils/get-accountability-for-token.js';
|
|
4
|
+
import { getPermissions } from '../utils/get-permissions.js';
|
|
4
5
|
import { getSchema } from '../utils/get-schema.js';
|
|
5
6
|
import { WebSocketError } from './errors.js';
|
|
6
7
|
import { getExpiresAtForToken } from './utils/get-expires-at-for-token.js';
|
|
@@ -32,6 +33,17 @@ export async function authenticateConnection(message) {
|
|
|
32
33
|
throw new WebSocketError('auth', 'AUTH_FAILED', 'Authentication failed.', message['uid']);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
36
|
+
export async function refreshAccountability(accountability) {
|
|
37
|
+
accountability = accountability ?? {
|
|
38
|
+
role: null,
|
|
39
|
+
user: null,
|
|
40
|
+
admin: false,
|
|
41
|
+
app: false,
|
|
42
|
+
};
|
|
43
|
+
const schema = await getSchema();
|
|
44
|
+
const permissions = await getPermissions(accountability, schema);
|
|
45
|
+
return { ...accountability, permissions };
|
|
46
|
+
}
|
|
35
47
|
export function authenticationSuccess(uid, refresh_token) {
|
|
36
48
|
const message = {
|
|
37
49
|
type: 'auth',
|
|
@@ -4,7 +4,7 @@ import { useLogger } from '../../logger.js';
|
|
|
4
4
|
import { bindPubSub } from '../../services/graphql/subscription.js';
|
|
5
5
|
import { GraphQLService } from '../../services/index.js';
|
|
6
6
|
import { getSchema } from '../../utils/get-schema.js';
|
|
7
|
-
import { authenticateConnection } from '../authenticate.js';
|
|
7
|
+
import { authenticateConnection, refreshAccountability } from '../authenticate.js';
|
|
8
8
|
import { handleWebSocketError } from '../errors.js';
|
|
9
9
|
import { ConnectionParams, WebSocketMessage } from '../messages.js';
|
|
10
10
|
import { getMessageType } from '../utils/message.js';
|
|
@@ -64,6 +64,9 @@ export class GraphQLSubscriptionController extends SocketController {
|
|
|
64
64
|
client.close(CloseCode.Forbidden, 'Forbidden');
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
+
else {
|
|
68
|
+
client.accountability = await refreshAccountability(client.accountability);
|
|
69
|
+
}
|
|
67
70
|
await cb(JSON.stringify(message));
|
|
68
71
|
}
|
|
69
72
|
catch (error) {
|
|
@@ -7,23 +7,19 @@ export function registerWebSocketEvents() {
|
|
|
7
7
|
actionsRegistered = true;
|
|
8
8
|
registerActionHooks([
|
|
9
9
|
'items',
|
|
10
|
-
'access',
|
|
11
10
|
'activity',
|
|
12
11
|
'collections',
|
|
13
12
|
'dashboards',
|
|
14
|
-
'flows',
|
|
15
13
|
'folders',
|
|
16
14
|
'notifications',
|
|
17
15
|
'operations',
|
|
18
16
|
'panels',
|
|
19
17
|
'permissions',
|
|
20
|
-
'policies',
|
|
21
18
|
'presets',
|
|
22
19
|
'revisions',
|
|
23
20
|
'roles',
|
|
24
21
|
'settings',
|
|
25
22
|
'shares',
|
|
26
|
-
'translations',
|
|
27
23
|
'users',
|
|
28
24
|
'versions',
|
|
29
25
|
'webhooks',
|
|
@@ -2,6 +2,7 @@ import { useEnv } from '@directus/env';
|
|
|
2
2
|
import { parseJSON } from '@directus/utils';
|
|
3
3
|
import emitter from '../../emitter.js';
|
|
4
4
|
import { useLogger } from '../../logger.js';
|
|
5
|
+
import { refreshAccountability } from '../authenticate.js';
|
|
5
6
|
import { WebSocketError, handleWebSocketError } from '../errors.js';
|
|
6
7
|
import { WebSocketMessage } from '../messages.js';
|
|
7
8
|
import SocketController from './base.js';
|
|
@@ -19,6 +20,7 @@ export class WebSocketController extends SocketController {
|
|
|
19
20
|
client.on('parsed-message', async (message) => {
|
|
20
21
|
try {
|
|
21
22
|
message = WebSocketMessage.parse(await emitter.emitFilter('websocket.message', message, { client }));
|
|
23
|
+
client.accountability = await refreshAccountability(client.accountability);
|
|
22
24
|
emitter.emitAction('websocket.message', { message, client });
|
|
23
25
|
}
|
|
24
26
|
catch (error) {
|
|
@@ -4,6 +4,7 @@ import { useBus } from '../../bus/index.js';
|
|
|
4
4
|
import emitter from '../../emitter.js';
|
|
5
5
|
import { getSchema } from '../../utils/get-schema.js';
|
|
6
6
|
import { sanitizeQuery } from '../../utils/sanitize-query.js';
|
|
7
|
+
import { refreshAccountability } from '../authenticate.js';
|
|
7
8
|
import { WebSocketError, handleWebSocketError } from '../errors.js';
|
|
8
9
|
import { WebSocketSubscribeMessage } from '../messages.js';
|
|
9
10
|
import { getPayload } from '../utils/items.js';
|
|
@@ -111,6 +112,7 @@ export class SubscribeHandler {
|
|
|
111
112
|
continue;
|
|
112
113
|
}
|
|
113
114
|
try {
|
|
115
|
+
client.accountability = await refreshAccountability(client.accountability);
|
|
114
116
|
const result = await getPayload(subscription, client.accountability, schema, event);
|
|
115
117
|
if (Array.isArray(result?.['data']) && result?.['data']?.length === 0)
|
|
116
118
|
continue;
|
|
@@ -39,5 +39,5 @@ export declare function getFieldsPayload(subscription: PSubscription, accountabi
|
|
|
39
39
|
* @param event Event data
|
|
40
40
|
* @returns the fetched data
|
|
41
41
|
*/
|
|
42
|
-
export declare function getItemsPayload(subscription: PSubscription, accountability: Accountability | null, schema: SchemaOverview, event?: WebSocketEvent): Promise<string | number |
|
|
42
|
+
export declare function getItemsPayload(subscription: PSubscription, accountability: Accountability | null, schema: SchemaOverview, event?: WebSocketEvent): Promise<string | number | import("@directus/types").Item | (string | number)[] | import("@directus/types").Item[]>;
|
|
43
43
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directus/api",
|
|
3
|
-
"version": "20.0.0
|
|
3
|
+
"version": "20.0.0",
|
|
4
4
|
"description": "Directus is a real-time API and App dashboard for managing SQL database content",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"directus",
|
|
@@ -59,11 +59,14 @@
|
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@authenio/samlify-node-xmllint": "2.0.0",
|
|
62
|
-
"@aws-sdk/client-ses": "3.
|
|
62
|
+
"@aws-sdk/client-ses": "3.600.0",
|
|
63
63
|
"@godaddy/terminus": "4.12.1",
|
|
64
64
|
"@rollup/plugin-alias": "5.1.0",
|
|
65
65
|
"@rollup/plugin-node-resolve": "15.2.3",
|
|
66
66
|
"@rollup/plugin-virtual": "3.0.2",
|
|
67
|
+
"@tus/file-store": "1.3.3",
|
|
68
|
+
"@tus/server": "1.6.0",
|
|
69
|
+
"@tus/utils": "0.2.0",
|
|
67
70
|
"@types/cookie": "0.6.0",
|
|
68
71
|
"argon2": "0.40.3",
|
|
69
72
|
"async": "3.2.5",
|
|
@@ -91,7 +94,7 @@
|
|
|
91
94
|
"flat": "6.0.1",
|
|
92
95
|
"fs-extra": "11.2.0",
|
|
93
96
|
"glob-to-regexp": "0.4.1",
|
|
94
|
-
"graphql": "16.
|
|
97
|
+
"graphql": "16.9.0",
|
|
95
98
|
"graphql-compose": "9.0.11",
|
|
96
99
|
"graphql-ws": "5.16.0",
|
|
97
100
|
"helmet": "7.1.0",
|
|
@@ -100,7 +103,7 @@
|
|
|
100
103
|
"ioredis": "5.4.1",
|
|
101
104
|
"ip-matching": "2.1.2",
|
|
102
105
|
"isolated-vm": "4.7.2",
|
|
103
|
-
"joi": "17.13.
|
|
106
|
+
"joi": "17.13.3",
|
|
104
107
|
"js-yaml": "4.1.0",
|
|
105
108
|
"js2xmlparser": "5.0.0",
|
|
106
109
|
"json2csv": "5.0.7",
|
|
@@ -108,7 +111,7 @@
|
|
|
108
111
|
"keyv": "4.5.4",
|
|
109
112
|
"knex": "3.1.0",
|
|
110
113
|
"ldapjs": "2.3.3",
|
|
111
|
-
"liquidjs": "10.
|
|
114
|
+
"liquidjs": "10.14.0",
|
|
112
115
|
"lodash-es": "4.17.21",
|
|
113
116
|
"marked": "12.0.2",
|
|
114
117
|
"micromustache": "8.0.3",
|
|
@@ -140,35 +143,35 @@
|
|
|
140
143
|
"sharp": "0.33.4",
|
|
141
144
|
"snappy": "7.2.2",
|
|
142
145
|
"stream-json": "1.8.0",
|
|
143
|
-
"tar": "7.
|
|
146
|
+
"tar": "7.4.0",
|
|
144
147
|
"tsx": "4.12.0",
|
|
145
148
|
"wellknown": "0.5.0",
|
|
146
|
-
"ws": "8.17.
|
|
149
|
+
"ws": "8.17.1",
|
|
147
150
|
"zod": "3.23.8",
|
|
148
151
|
"zod-validation-error": "3.3.0",
|
|
149
|
-
"@directus/app": "
|
|
150
|
-
"@directus/constants": "11.
|
|
151
|
-
"@directus/
|
|
152
|
-
"@directus/errors": "0.
|
|
153
|
-
"@directus/
|
|
154
|
-
"@directus/extensions-
|
|
152
|
+
"@directus/app": "12.2.0",
|
|
153
|
+
"@directus/constants": "11.0.4",
|
|
154
|
+
"@directus/extensions": "1.0.9",
|
|
155
|
+
"@directus/errors": "0.3.3",
|
|
156
|
+
"@directus/env": "1.2.0",
|
|
157
|
+
"@directus/extensions-registry": "1.0.9",
|
|
158
|
+
"@directus/extensions-sdk": "11.0.9",
|
|
155
159
|
"@directus/format-title": "10.1.2",
|
|
156
|
-
"@directus/
|
|
157
|
-
"@directus/
|
|
158
|
-
"@directus/pressure": "1.0.21-rc.0",
|
|
159
|
-
"@directus/specs": "10.2.10",
|
|
160
|
+
"@directus/memory": "1.0.10",
|
|
161
|
+
"@directus/pressure": "1.0.21",
|
|
160
162
|
"@directus/schema": "11.0.3",
|
|
161
|
-
"@directus/
|
|
162
|
-
"@directus/storage-driver-azure": "10.0.23
|
|
163
|
-
"@directus/storage-driver-cloudinary": "10.0.23
|
|
164
|
-
"@directus/storage-driver-gcs": "10.0.24
|
|
165
|
-
"@directus/storage
|
|
166
|
-
"@directus/storage-driver-
|
|
167
|
-
"@directus/storage-driver-s3": "10.
|
|
168
|
-
"@directus/
|
|
169
|
-
"@directus/
|
|
170
|
-
"@directus/
|
|
171
|
-
"directus": "
|
|
163
|
+
"@directus/specs": "10.2.10",
|
|
164
|
+
"@directus/storage-driver-azure": "10.0.23",
|
|
165
|
+
"@directus/storage-driver-cloudinary": "10.0.23",
|
|
166
|
+
"@directus/storage-driver-gcs": "10.0.24",
|
|
167
|
+
"@directus/storage": "10.1.0",
|
|
168
|
+
"@directus/storage-driver-local": "10.1.0",
|
|
169
|
+
"@directus/storage-driver-s3": "10.1.0",
|
|
170
|
+
"@directus/system-data": "1.1.0",
|
|
171
|
+
"@directus/storage-driver-supabase": "1.0.15",
|
|
172
|
+
"@directus/utils": "11.0.10",
|
|
173
|
+
"@directus/validation": "0.0.18",
|
|
174
|
+
"directus": "10.13.0"
|
|
172
175
|
},
|
|
173
176
|
"devDependencies": {
|
|
174
177
|
"@ngneat/falso": "7.2.0",
|
|
@@ -211,15 +214,15 @@
|
|
|
211
214
|
"vitest": "1.5.3",
|
|
212
215
|
"@directus/random": "0.2.8",
|
|
213
216
|
"@directus/tsconfig": "1.0.1",
|
|
214
|
-
"@directus/types": "
|
|
217
|
+
"@directus/types": "11.2.0"
|
|
215
218
|
},
|
|
216
219
|
"optionalDependencies": {
|
|
217
220
|
"@keyv/redis": "2.8.4",
|
|
218
|
-
"
|
|
221
|
+
"mysql": "2.18.1",
|
|
219
222
|
"nodemailer-mailgun-transport": "2.1.5",
|
|
220
223
|
"nodemailer-sendgrid": "1.0.3",
|
|
221
224
|
"oracledb": "6.5.1",
|
|
222
|
-
"pg": "8.
|
|
225
|
+
"pg": "8.12.0",
|
|
223
226
|
"sqlite3": "5.1.7",
|
|
224
227
|
"tedious": "18.2.0"
|
|
225
228
|
},
|
|
@@ -230,7 +233,6 @@
|
|
|
230
233
|
"build": "tsc --project tsconfig.prod.json && copyfiles \"src/**/*.{yaml,liquid}\" -u 1 dist",
|
|
231
234
|
"cli": "NODE_ENV=development SERVE_APP=false tsx src/cli/run.ts",
|
|
232
235
|
"dev": "NODE_ENV=development SERVE_APP=true tsx watch --ignore extensions --clear-screen=false src/start.ts",
|
|
233
|
-
"test": "vitest
|
|
234
|
-
"test:watch": "vitest"
|
|
236
|
+
"test": "vitest --watch=false"
|
|
235
237
|
}
|
|
236
238
|
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { ErrorCode, isDirectusError } from '@directus/errors';
|
|
2
|
-
import express from 'express';
|
|
3
|
-
import { respond } from '../middleware/respond.js';
|
|
4
|
-
import useCollection from '../middleware/use-collection.js';
|
|
5
|
-
import { validateBatch } from '../middleware/validate-batch.js';
|
|
6
|
-
import { MetaService } from '../services/meta.js';
|
|
7
|
-
import { AccessService } from '../services/access.js';
|
|
8
|
-
import asyncHandler from '../utils/async-handler.js';
|
|
9
|
-
import { sanitizeQuery } from '../utils/sanitize-query.js';
|
|
10
|
-
const router = express.Router();
|
|
11
|
-
router.use(useCollection('directus_access'));
|
|
12
|
-
router.post('/', asyncHandler(async (req, res, next) => {
|
|
13
|
-
const service = new AccessService({
|
|
14
|
-
accountability: req.accountability,
|
|
15
|
-
schema: req.schema,
|
|
16
|
-
});
|
|
17
|
-
const savedKeys = [];
|
|
18
|
-
if (Array.isArray(req.body)) {
|
|
19
|
-
const keys = await service.createMany(req.body);
|
|
20
|
-
savedKeys.push(...keys);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
const key = await service.createOne(req.body);
|
|
24
|
-
savedKeys.push(key);
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
if (Array.isArray(req.body)) {
|
|
28
|
-
const items = await service.readMany(savedKeys, req.sanitizedQuery);
|
|
29
|
-
res.locals['payload'] = { data: items };
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const item = await service.readOne(savedKeys[0], req.sanitizedQuery);
|
|
33
|
-
res.locals['payload'] = { data: item };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
if (isDirectusError(error, ErrorCode.Forbidden)) {
|
|
38
|
-
return next();
|
|
39
|
-
}
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
42
|
-
return next();
|
|
43
|
-
}), respond);
|
|
44
|
-
const readHandler = asyncHandler(async (req, res, next) => {
|
|
45
|
-
const service = new AccessService({
|
|
46
|
-
accountability: req.accountability,
|
|
47
|
-
schema: req.schema,
|
|
48
|
-
});
|
|
49
|
-
const metaService = new MetaService({
|
|
50
|
-
accountability: req.accountability,
|
|
51
|
-
schema: req.schema,
|
|
52
|
-
});
|
|
53
|
-
let result;
|
|
54
|
-
if (req.body.keys) {
|
|
55
|
-
result = await service.readMany(req.body.keys, req.sanitizedQuery);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
result = await service.readByQuery(req.sanitizedQuery);
|
|
59
|
-
}
|
|
60
|
-
const meta = await metaService.getMetaForQuery('directus_access', req.sanitizedQuery);
|
|
61
|
-
res.locals['payload'] = { data: result, meta };
|
|
62
|
-
return next();
|
|
63
|
-
});
|
|
64
|
-
router.get('/', validateBatch('read'), readHandler, respond);
|
|
65
|
-
router.search('/', validateBatch('read'), readHandler, respond);
|
|
66
|
-
router.get('/:pk', asyncHandler(async (req, res, next) => {
|
|
67
|
-
if (req.path.endsWith('me'))
|
|
68
|
-
return next();
|
|
69
|
-
const service = new AccessService({
|
|
70
|
-
accountability: req.accountability,
|
|
71
|
-
schema: req.schema,
|
|
72
|
-
});
|
|
73
|
-
const record = await service.readOne(req.params['pk'], req.sanitizedQuery);
|
|
74
|
-
res.locals['payload'] = { data: record };
|
|
75
|
-
return next();
|
|
76
|
-
}), respond);
|
|
77
|
-
router.patch('/', validateBatch('update'), asyncHandler(async (req, res, next) => {
|
|
78
|
-
const service = new AccessService({
|
|
79
|
-
accountability: req.accountability,
|
|
80
|
-
schema: req.schema,
|
|
81
|
-
});
|
|
82
|
-
let keys = [];
|
|
83
|
-
if (Array.isArray(req.body)) {
|
|
84
|
-
keys = await service.updateBatch(req.body);
|
|
85
|
-
}
|
|
86
|
-
else if (req.body.keys) {
|
|
87
|
-
keys = await service.updateMany(req.body.keys, req.body.data);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
const sanitizedQuery = sanitizeQuery(req.body.query, req.accountability);
|
|
91
|
-
keys = await service.updateByQuery(sanitizedQuery, req.body.data);
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
const result = await service.readMany(keys, req.sanitizedQuery);
|
|
95
|
-
res.locals['payload'] = { data: result };
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
if (isDirectusError(error, ErrorCode.Forbidden)) {
|
|
99
|
-
return next();
|
|
100
|
-
}
|
|
101
|
-
throw error;
|
|
102
|
-
}
|
|
103
|
-
return next();
|
|
104
|
-
}), respond);
|
|
105
|
-
router.patch('/:pk', asyncHandler(async (req, res, next) => {
|
|
106
|
-
const service = new AccessService({
|
|
107
|
-
accountability: req.accountability,
|
|
108
|
-
schema: req.schema,
|
|
109
|
-
});
|
|
110
|
-
const primaryKey = await service.updateOne(req.params['pk'], req.body);
|
|
111
|
-
try {
|
|
112
|
-
const item = await service.readOne(primaryKey, req.sanitizedQuery);
|
|
113
|
-
res.locals['payload'] = { data: item || null };
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
if (isDirectusError(error, ErrorCode.Forbidden)) {
|
|
117
|
-
return next();
|
|
118
|
-
}
|
|
119
|
-
throw error;
|
|
120
|
-
}
|
|
121
|
-
return next();
|
|
122
|
-
}), respond);
|
|
123
|
-
router.delete('/', validateBatch('delete'), asyncHandler(async (req, _res, next) => {
|
|
124
|
-
const service = new AccessService({
|
|
125
|
-
accountability: req.accountability,
|
|
126
|
-
schema: req.schema,
|
|
127
|
-
});
|
|
128
|
-
if (Array.isArray(req.body)) {
|
|
129
|
-
await service.deleteMany(req.body);
|
|
130
|
-
}
|
|
131
|
-
else if (req.body.keys) {
|
|
132
|
-
await service.deleteMany(req.body.keys);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
const sanitizedQuery = sanitizeQuery(req.body.query, req.accountability);
|
|
136
|
-
await service.deleteByQuery(sanitizedQuery);
|
|
137
|
-
}
|
|
138
|
-
return next();
|
|
139
|
-
}), respond);
|
|
140
|
-
router.delete('/:pk', asyncHandler(async (req, _res, next) => {
|
|
141
|
-
const service = new AccessService({
|
|
142
|
-
accountability: req.accountability,
|
|
143
|
-
schema: req.schema,
|
|
144
|
-
});
|
|
145
|
-
await service.deleteOne(req.params['pk']);
|
|
146
|
-
return next();
|
|
147
|
-
}), respond);
|
|
148
|
-
export default router;
|