@directus/api 19.3.1 → 20.0.0-rc.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 +4 -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 +2 -4
- package/dist/cache.js +3 -0
- package/dist/cli/commands/bootstrap/index.js +8 -2
- package/dist/cli/commands/init/index.js +9 -10
- package/dist/cli/utils/defaults.d.ts +4 -11
- package/dist/cli/utils/defaults.js +7 -1
- package/dist/constants.d.ts +1 -1
- package/dist/controllers/access.d.ts +2 -0
- package/dist/controllers/access.js +148 -0
- package/dist/controllers/auth.js +5 -16
- package/dist/controllers/permissions.js +14 -2
- package/dist/controllers/policies.d.ts +2 -0
- package/dist/controllers/policies.js +169 -0
- package/dist/controllers/roles.js +22 -1
- package/dist/controllers/users.js +0 -55
- package/dist/database/errors/dialects/mysql.js +23 -23
- package/dist/database/get-ast-from-query/get-ast-from-query.d.ts +16 -0
- package/dist/database/get-ast-from-query/get-ast-from-query.js +82 -0
- package/dist/database/get-ast-from-query/lib/convert-wildcards.d.ts +13 -0
- package/dist/database/get-ast-from-query/lib/convert-wildcards.js +69 -0
- package/dist/database/get-ast-from-query/lib/parse-fields.d.ts +15 -0
- package/dist/database/get-ast-from-query/lib/parse-fields.js +190 -0
- package/dist/database/get-ast-from-query/utils/get-deep-query.d.ts +14 -0
- package/dist/database/get-ast-from-query/utils/get-deep-query.js +17 -0
- package/dist/database/get-ast-from-query/utils/get-related-collection.d.ts +2 -0
- package/dist/database/get-ast-from-query/utils/get-related-collection.js +13 -0
- package/dist/database/get-ast-from-query/utils/get-relation.d.ts +2 -0
- package/dist/database/get-ast-from-query/utils/get-relation.js +7 -0
- package/dist/database/helpers/fn/types.d.ts +2 -1
- 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 +4 -2
- 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 +5 -3
- package/dist/database/helpers/geometry/types.d.ts +1 -1
- package/dist/database/helpers/geometry/types.js +4 -2
- package/dist/database/index.js +2 -1
- package/dist/database/migrations/20240619A-permissions-policies.d.ts +3 -0
- package/dist/database/migrations/20240619A-permissions-policies.js +163 -0
- package/dist/database/run-ast/lib/get-db-query.d.ts +4 -0
- package/dist/database/run-ast/lib/get-db-query.js +194 -0
- package/dist/database/run-ast/lib/parse-current-level.d.ts +7 -0
- package/dist/database/run-ast/lib/parse-current-level.js +41 -0
- package/dist/database/run-ast/run-ast.d.ts +7 -0
- package/dist/database/run-ast/run-ast.js +107 -0
- package/dist/database/{run-ast.d.ts → run-ast/types.d.ts} +3 -9
- package/dist/database/run-ast/types.js +1 -0
- package/dist/database/run-ast/utils/apply-case-when.d.ts +16 -0
- package/dist/database/run-ast/utils/apply-case-when.js +26 -0
- package/dist/database/run-ast/utils/apply-parent-filters.d.ts +3 -0
- package/dist/database/run-ast/utils/apply-parent-filters.js +55 -0
- package/dist/database/run-ast/utils/get-column-pre-processor.d.ts +10 -0
- package/dist/database/run-ast/utils/get-column-pre-processor.js +57 -0
- package/dist/database/run-ast/utils/get-field-alias.d.ts +2 -0
- package/dist/database/run-ast/utils/get-field-alias.js +4 -0
- package/dist/database/run-ast/utils/get-inner-query-column-pre-processor.d.ts +5 -0
- package/dist/database/run-ast/utils/get-inner-query-column-pre-processor.js +23 -0
- package/dist/database/run-ast/utils/merge-with-parent-items.d.ts +3 -0
- package/dist/database/run-ast/utils/merge-with-parent-items.js +87 -0
- package/dist/database/run-ast/utils/remove-temporary-fields.d.ts +3 -0
- package/dist/database/run-ast/utils/remove-temporary-fields.js +73 -0
- package/dist/extensions/lib/sandbox/generate-api-extensions-sandbox-entrypoint.d.ts +1 -1
- package/dist/flows.js +3 -4
- package/dist/middleware/authenticate.js +2 -7
- package/dist/middleware/cache.js +1 -1
- package/dist/middleware/cors.js +4 -4
- package/dist/middleware/respond.js +1 -1
- package/dist/permissions/cache.d.ts +2 -0
- package/dist/permissions/cache.js +23 -0
- package/dist/permissions/lib/fetch-permissions.d.ts +10 -0
- package/dist/permissions/lib/fetch-permissions.js +55 -0
- package/dist/permissions/lib/fetch-policies.d.ts +7 -0
- package/dist/permissions/lib/fetch-policies.js +28 -0
- package/dist/permissions/lib/fetch-roles-tree.d.ts +3 -0
- package/dist/permissions/lib/fetch-roles-tree.js +28 -0
- package/dist/{services/permissions → permissions}/lib/with-app-minimal-permissions.d.ts +1 -1
- package/dist/permissions/lib/with-app-minimal-permissions.js +10 -0
- package/dist/permissions/modules/fetch-accountability-collection-access/fetch-accountability-collection-access.d.ts +7 -0
- package/dist/permissions/modules/fetch-accountability-collection-access/fetch-accountability-collection-access.js +56 -0
- package/dist/permissions/modules/fetch-accountability-policy-globals/fetch-accountability-policy-globals.d.ts +3 -0
- package/dist/permissions/modules/fetch-accountability-policy-globals/fetch-accountability-policy-globals.js +16 -0
- package/dist/permissions/modules/fetch-allowed-collections/fetch-allowed-collections.d.ts +8 -0
- package/dist/permissions/modules/fetch-allowed-collections/fetch-allowed-collections.js +24 -0
- package/dist/permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.d.ts +9 -0
- package/dist/permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.js +31 -0
- package/dist/permissions/modules/fetch-allowed-fields/fetch-allowed-fields.d.ts +16 -0
- package/dist/permissions/modules/fetch-allowed-fields/fetch-allowed-fields.js +27 -0
- package/dist/permissions/modules/fetch-global-access/fetch-global-access.d.ts +10 -0
- package/dist/permissions/modules/fetch-global-access/fetch-global-access.js +23 -0
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.d.ts +5 -0
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.js +7 -0
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.d.ts +5 -0
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.js +10 -0
- package/dist/permissions/modules/fetch-global-access/types.d.ts +4 -0
- package/dist/permissions/modules/fetch-global-access/types.js +1 -0
- package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.d.ts +4 -0
- package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.js +27 -0
- package/dist/permissions/modules/fetch-inconsistent-field-map/fetch-inconsistent-field-map.d.ts +12 -0
- package/dist/permissions/modules/fetch-inconsistent-field-map/fetch-inconsistent-field-map.js +32 -0
- package/dist/permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.d.ts +4 -0
- package/dist/permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.js +29 -0
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-children.d.ts +4 -0
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-children.js +49 -0
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-query.d.ts +3 -0
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-query.js +56 -0
- package/dist/permissions/modules/process-ast/lib/field-map-from-ast.d.ts +4 -0
- package/dist/permissions/modules/process-ast/lib/field-map-from-ast.js +8 -0
- package/dist/permissions/modules/process-ast/lib/inject-cases.d.ts +9 -0
- package/dist/permissions/modules/process-ast/lib/inject-cases.js +93 -0
- package/dist/permissions/modules/process-ast/process-ast.d.ts +9 -0
- package/dist/permissions/modules/process-ast/process-ast.js +39 -0
- package/dist/permissions/modules/process-ast/types.d.ts +24 -0
- package/dist/permissions/modules/process-ast/types.js +1 -0
- package/dist/permissions/modules/process-ast/utils/collections-in-field-map.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/collections-in-field-map.js +7 -0
- package/dist/permissions/modules/process-ast/utils/dedupe-access.d.ts +12 -0
- package/dist/permissions/modules/process-ast/utils/dedupe-access.js +30 -0
- package/dist/permissions/modules/process-ast/utils/extract-paths-from-query.d.ts +15 -0
- package/dist/permissions/modules/process-ast/utils/extract-paths-from-query.js +50 -0
- package/dist/permissions/modules/process-ast/utils/find-related-collection.d.ts +3 -0
- package/dist/permissions/modules/process-ast/utils/find-related-collection.js +9 -0
- package/dist/permissions/modules/process-ast/utils/flatten-filter.d.ts +3 -0
- package/dist/permissions/modules/process-ast/utils/flatten-filter.js +24 -0
- package/dist/permissions/modules/process-ast/utils/format-a2o-key.d.ts +1 -0
- package/dist/permissions/modules/process-ast/utils/format-a2o-key.js +3 -0
- package/dist/permissions/modules/process-ast/utils/get-info-for-path.d.ts +5 -0
- package/dist/permissions/modules/process-ast/utils/get-info-for-path.js +7 -0
- package/dist/permissions/modules/process-ast/utils/has-item-permissions.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/has-item-permissions.js +3 -0
- package/dist/permissions/modules/process-ast/utils/stringify-query-path.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/stringify-query-path.js +3 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/create-error.d.ts +3 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/create-error.js +16 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-existence.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-existence.js +12 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-permissions.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-permissions.js +28 -0
- package/dist/permissions/modules/process-payload/lib/is-field-nullable.d.ts +5 -0
- package/dist/permissions/modules/process-payload/lib/is-field-nullable.js +12 -0
- package/dist/permissions/modules/process-payload/process-payload.d.ts +13 -0
- package/dist/permissions/modules/process-payload/process-payload.js +77 -0
- package/dist/permissions/modules/validate-access/lib/validate-collection-access.d.ts +12 -0
- package/dist/permissions/modules/validate-access/lib/validate-collection-access.js +11 -0
- package/dist/permissions/modules/validate-access/lib/validate-item-access.d.ts +9 -0
- package/dist/permissions/modules/validate-access/lib/validate-item-access.js +33 -0
- package/dist/permissions/modules/validate-access/validate-access.d.ts +14 -0
- package/dist/permissions/modules/validate-access/validate-access.js +28 -0
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.d.ts +1 -0
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.js +8 -0
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-users.d.ts +5 -0
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-users.js +10 -0
- package/dist/permissions/types.d.ts +6 -0
- package/dist/permissions/types.js +1 -0
- package/dist/permissions/utils/create-default-accountability.d.ts +2 -0
- package/dist/permissions/utils/create-default-accountability.js +11 -0
- package/dist/permissions/utils/extract-required-dynamic-variable-context.d.ts +8 -0
- package/dist/permissions/utils/extract-required-dynamic-variable-context.js +27 -0
- package/dist/permissions/utils/fetch-dynamic-variable-context.d.ts +9 -0
- package/dist/permissions/utils/fetch-dynamic-variable-context.js +43 -0
- package/dist/permissions/utils/filter-policies-by-ip.d.ts +2 -0
- package/dist/permissions/utils/filter-policies-by-ip.js +15 -0
- package/dist/permissions/utils/get-unaliased-field-key.d.ts +5 -0
- package/dist/permissions/utils/get-unaliased-field-key.js +17 -0
- package/dist/permissions/utils/process-permissions.d.ts +7 -0
- package/dist/permissions/utils/process-permissions.js +9 -0
- package/dist/permissions/utils/with-cache.d.ts +10 -0
- package/dist/permissions/utils/with-cache.js +25 -0
- package/dist/services/access.d.ts +10 -0
- package/dist/services/access.js +43 -0
- package/dist/services/activity.js +22 -10
- package/dist/services/assets.d.ts +2 -3
- package/dist/services/assets.js +10 -5
- package/dist/services/authentication.js +18 -18
- package/dist/services/collections.js +18 -17
- package/dist/services/fields.d.ts +0 -1
- package/dist/services/fields.js +53 -24
- package/dist/services/files.d.ts +0 -4
- package/dist/services/files.js +10 -10
- package/dist/services/flows.d.ts +0 -2
- package/dist/services/flows.js +2 -14
- package/dist/services/graphql/index.d.ts +3 -3
- package/dist/services/graphql/index.js +126 -22
- package/dist/services/graphql/subscription.js +2 -4
- package/dist/services/import-export.js +23 -9
- package/dist/services/index.d.ts +3 -2
- package/dist/services/index.js +3 -2
- package/dist/services/items.d.ts +40 -14
- package/dist/services/items.js +182 -79
- package/dist/services/meta.js +60 -23
- package/dist/services/notifications.d.ts +0 -1
- package/dist/services/notifications.js +0 -7
- package/dist/services/operations.d.ts +0 -2
- package/dist/services/operations.js +2 -14
- package/dist/services/payload.d.ts +9 -10
- package/dist/services/payload.js +35 -19
- package/dist/services/{permissions/index.d.ts → permissions.d.ts} +5 -7
- package/dist/services/{permissions/index.js → permissions.js} +30 -54
- package/dist/services/policies.d.ts +12 -0
- package/dist/services/policies.js +87 -0
- package/dist/services/relations.d.ts +0 -6
- package/dist/services/relations.js +26 -29
- package/dist/services/roles.d.ts +4 -14
- package/dist/services/roles.js +56 -430
- package/dist/services/shares.d.ts +0 -2
- package/dist/services/shares.js +12 -8
- package/dist/services/specifications.d.ts +2 -2
- package/dist/services/specifications.js +39 -27
- package/dist/services/users.d.ts +2 -20
- package/dist/services/users.js +87 -192
- package/dist/services/utils.js +11 -7
- package/dist/services/versions.d.ts +0 -2
- package/dist/services/versions.js +34 -10
- package/dist/telemetry/lib/get-report.js +6 -3
- package/dist/telemetry/types/report.d.ts +4 -0
- package/dist/telemetry/utils/check-user-limits.d.ts +5 -0
- package/dist/telemetry/utils/check-user-limits.js +19 -0
- package/dist/telemetry/utils/get-filesize-sum.d.ts +5 -0
- package/dist/telemetry/utils/get-filesize-sum.js +7 -0
- package/dist/types/ast.d.ts +43 -1
- package/dist/types/items.d.ts +11 -0
- package/dist/utils/apply-query.d.ts +4 -3
- package/dist/utils/apply-query.js +37 -8
- package/dist/utils/fetch-user-count/fetch-access-lookup.d.ts +17 -0
- package/dist/utils/fetch-user-count/fetch-access-lookup.js +22 -0
- package/dist/utils/fetch-user-count/fetch-access-roles.d.ts +16 -0
- package/dist/utils/fetch-user-count/fetch-access-roles.js +37 -0
- package/dist/utils/fetch-user-count/fetch-active-users.d.ts +6 -0
- package/dist/utils/fetch-user-count/fetch-active-users.js +3 -0
- package/dist/utils/fetch-user-count/fetch-user-count.d.ts +12 -0
- package/dist/utils/fetch-user-count/fetch-user-count.js +57 -0
- package/dist/utils/fetch-user-count/get-user-count-query.d.ts +20 -0
- package/dist/utils/fetch-user-count/get-user-count-query.js +17 -0
- package/dist/utils/get-accountability-for-role.js +16 -25
- package/dist/utils/get-accountability-for-token.js +17 -16
- package/dist/utils/get-cache-key.d.ts +1 -1
- package/dist/utils/get-cache-key.js +12 -1
- package/dist/utils/get-column.d.ts +2 -1
- package/dist/utils/get-column.js +1 -0
- package/dist/utils/get-graphql-type.js +1 -0
- package/dist/utils/get-service.d.ts +1 -1
- package/dist/utils/get-service.js +14 -10
- package/dist/utils/reduce-schema.d.ts +4 -6
- package/dist/utils/reduce-schema.js +14 -34
- package/dist/utils/validate-user-count-integrity.d.ts +13 -0
- package/dist/utils/validate-user-count-integrity.js +29 -0
- package/dist/websocket/authenticate.d.ts +0 -2
- package/dist/websocket/authenticate.js +0 -12
- package/dist/websocket/controllers/graphql.js +1 -4
- package/dist/websocket/controllers/hooks.js +4 -0
- package/dist/websocket/controllers/rest.js +0 -2
- package/dist/websocket/handlers/subscribe.js +0 -2
- package/dist/websocket/utils/items.d.ts +1 -1
- package/dist/websocket/utils/items.js +4 -1
- package/package.json +31 -30
- package/dist/database/run-ast.js +0 -450
- package/dist/middleware/check-ip.d.ts +0 -2
- package/dist/middleware/check-ip.js +0 -37
- package/dist/middleware/get-permissions.d.ts +0 -3
- package/dist/middleware/get-permissions.js +0 -10
- package/dist/services/authorization.d.ts +0 -17
- package/dist/services/authorization.js +0 -456
- package/dist/services/permissions/lib/with-app-minimal-permissions.js +0 -13
- package/dist/telemetry/utils/check-increased-user-limits.d.ts +0 -7
- package/dist/telemetry/utils/check-increased-user-limits.js +0 -22
- package/dist/telemetry/utils/get-role-counts-by-roles.d.ts +0 -6
- package/dist/telemetry/utils/get-role-counts-by-roles.js +0 -27
- package/dist/telemetry/utils/get-role-counts-by-users.d.ts +0 -11
- package/dist/telemetry/utils/get-role-counts-by-users.js +0 -34
- package/dist/telemetry/utils/get-user-count.d.ts +0 -8
- package/dist/telemetry/utils/get-user-count.js +0 -33
- package/dist/telemetry/utils/get-user-counts-by-roles.d.ts +0 -7
- package/dist/telemetry/utils/get-user-counts-by-roles.js +0 -35
- package/dist/utils/get-ast-from-query.d.ts +0 -13
- package/dist/utils/get-ast-from-query.js +0 -297
- package/dist/utils/get-permissions.d.ts +0 -2
- package/dist/utils/get-permissions.js +0 -150
- package/dist/utils/merge-permissions-for-share.d.ts +0 -4
- package/dist/utils/merge-permissions-for-share.js +0 -109
- package/dist/utils/merge-permissions.d.ts +0 -3
- package/dist/utils/merge-permissions.js +0 -95
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function getUserCountQuery(knex, options) {
|
|
2
|
+
// Safety check for an empty list of includeRoles, which would otherwise return all users
|
|
3
|
+
if (options.includeRoles && options.includeRoles.length === 0) {
|
|
4
|
+
return Promise.resolve({ count: 0 });
|
|
5
|
+
}
|
|
6
|
+
let query = knex('directus_users').count({ count: '*' }).as('count').where('status', 'active');
|
|
7
|
+
if (options.excludeIds && options.excludeIds.length > 0) {
|
|
8
|
+
query = query.whereNotIn('id', options.excludeIds);
|
|
9
|
+
}
|
|
10
|
+
if (options.excludeRoles && options.excludeRoles.length > 0) {
|
|
11
|
+
query = query.whereNotIn('role', options.excludeRoles);
|
|
12
|
+
}
|
|
13
|
+
if (options.includeRoles && options.includeRoles.length > 0) {
|
|
14
|
+
query = query.whereIn('role', options.includeRoles);
|
|
15
|
+
}
|
|
16
|
+
return query.first();
|
|
17
|
+
}
|
|
@@ -1,40 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fetchRolesTree } from '../permissions/lib/fetch-roles-tree.js';
|
|
2
|
+
import { fetchGlobalAccess } from '../permissions/modules/fetch-global-access/fetch-global-access.js';
|
|
3
|
+
import { createDefaultAccountability } from '../permissions/utils/create-default-accountability.js';
|
|
2
4
|
export async function getAccountabilityForRole(role, context) {
|
|
3
|
-
let generatedAccountability
|
|
5
|
+
let generatedAccountability;
|
|
4
6
|
if (role === null) {
|
|
5
|
-
generatedAccountability =
|
|
6
|
-
role: null,
|
|
7
|
-
user: null,
|
|
8
|
-
admin: false,
|
|
9
|
-
app: false,
|
|
10
|
-
};
|
|
11
|
-
generatedAccountability.permissions = await getPermissions(generatedAccountability, context.schema);
|
|
7
|
+
generatedAccountability = createDefaultAccountability();
|
|
12
8
|
}
|
|
13
9
|
else if (role === 'system') {
|
|
14
|
-
generatedAccountability = {
|
|
15
|
-
user: null,
|
|
16
|
-
role: null,
|
|
10
|
+
generatedAccountability = createDefaultAccountability({
|
|
17
11
|
admin: true,
|
|
18
12
|
app: true,
|
|
19
|
-
|
|
20
|
-
};
|
|
13
|
+
});
|
|
21
14
|
}
|
|
22
15
|
else {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.first();
|
|
28
|
-
if (!roleInfo) {
|
|
16
|
+
const roles = await fetchRolesTree(role, context.database);
|
|
17
|
+
// The roles tree should always include the passed role. If it doesn't, it's because it
|
|
18
|
+
// couldn't be read from the database and therefore doesn't exist
|
|
19
|
+
if (roles.length === 0) {
|
|
29
20
|
throw new Error(`Configured role "${role}" isn't a valid role ID or doesn't exist.`);
|
|
30
21
|
}
|
|
31
|
-
|
|
22
|
+
const globalAccess = await fetchGlobalAccess({ user: null, roles, ip: context.accountability?.ip ?? null }, context.database);
|
|
23
|
+
generatedAccountability = createDefaultAccountability({
|
|
32
24
|
role,
|
|
25
|
+
roles,
|
|
33
26
|
user: null,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
generatedAccountability.permissions = await getPermissions(generatedAccountability, context.schema);
|
|
27
|
+
...globalAccess,
|
|
28
|
+
});
|
|
38
29
|
}
|
|
39
30
|
return generatedAccountability;
|
|
40
31
|
}
|
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
import { InvalidCredentialsError } from '@directus/errors';
|
|
2
2
|
import getDatabase from '../database/index.js';
|
|
3
|
+
import { fetchRolesTree } from '../permissions/lib/fetch-roles-tree.js';
|
|
4
|
+
import { fetchGlobalAccess } from '../permissions/modules/fetch-global-access/fetch-global-access.js';
|
|
5
|
+
import { createDefaultAccountability } from '../permissions/utils/create-default-accountability.js';
|
|
3
6
|
import { getSecret } from './get-secret.js';
|
|
4
7
|
import isDirectusJWT from './is-directus-jwt.js';
|
|
5
|
-
import { verifySessionJWT } from './verify-session-jwt.js';
|
|
6
8
|
import { verifyAccessJWT } from './jwt.js';
|
|
9
|
+
import { verifySessionJWT } from './verify-session-jwt.js';
|
|
7
10
|
export async function getAccountabilityForToken(token, accountability) {
|
|
8
11
|
if (!accountability) {
|
|
9
|
-
accountability =
|
|
10
|
-
user: null,
|
|
11
|
-
role: null,
|
|
12
|
-
admin: false,
|
|
13
|
-
app: false,
|
|
14
|
-
};
|
|
12
|
+
accountability = createDefaultAccountability();
|
|
15
13
|
}
|
|
14
|
+
// Try finding the user with the provided token
|
|
15
|
+
const database = getDatabase();
|
|
16
16
|
if (token) {
|
|
17
17
|
if (isDirectusJWT(token)) {
|
|
18
18
|
const payload = verifyAccessJWT(token, getSecret());
|
|
19
19
|
if ('session' in payload) {
|
|
20
20
|
await verifySessionJWT(payload);
|
|
21
21
|
}
|
|
22
|
-
accountability.role = payload.role;
|
|
23
|
-
accountability.admin = payload.admin_access === true || payload.admin_access == 1;
|
|
24
|
-
accountability.app = payload.app_access === true || payload.app_access == 1;
|
|
25
22
|
if (payload.share)
|
|
26
23
|
accountability.share = payload.share;
|
|
27
24
|
if (payload.share_scope)
|
|
28
25
|
accountability.share_scope = payload.share_scope;
|
|
29
26
|
if (payload.id)
|
|
30
27
|
accountability.user = payload.id;
|
|
28
|
+
accountability.role = payload.role;
|
|
29
|
+
accountability.roles = await fetchRolesTree(payload.role, database);
|
|
30
|
+
const { admin, app } = await fetchGlobalAccess(accountability, database);
|
|
31
|
+
accountability.admin = admin;
|
|
32
|
+
accountability.app = app;
|
|
31
33
|
}
|
|
32
34
|
else {
|
|
33
|
-
// Try finding the user with the provided token
|
|
34
|
-
const database = getDatabase();
|
|
35
35
|
const user = await database
|
|
36
|
-
.select('directus_users.id', 'directus_users.role'
|
|
36
|
+
.select('directus_users.id', 'directus_users.role')
|
|
37
37
|
.from('directus_users')
|
|
38
|
-
.leftJoin('directus_roles', 'directus_users.role', 'directus_roles.id')
|
|
39
38
|
.where({
|
|
40
39
|
'directus_users.token': token,
|
|
41
40
|
status: 'active',
|
|
@@ -46,8 +45,10 @@ export async function getAccountabilityForToken(token, accountability) {
|
|
|
46
45
|
}
|
|
47
46
|
accountability.user = user.id;
|
|
48
47
|
accountability.role = user.role;
|
|
49
|
-
accountability.
|
|
50
|
-
|
|
48
|
+
accountability.roles = await fetchRolesTree(user.role, database);
|
|
49
|
+
const { admin, app } = await fetchGlobalAccess(accountability, database);
|
|
50
|
+
accountability.admin = admin;
|
|
51
|
+
accountability.app = app;
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
return accountability;
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import hash from 'object-hash';
|
|
2
2
|
import url from 'url';
|
|
3
|
+
import getDatabase from '../database/index.js';
|
|
4
|
+
import { fetchPoliciesIpAccess } from '../permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.js';
|
|
3
5
|
import { getGraphqlQueryAndVariables } from './get-graphql-query-and-variables.js';
|
|
4
6
|
import { version } from 'directus/version';
|
|
5
|
-
|
|
7
|
+
import { ipInNetworks } from './ip-in-networks.js';
|
|
8
|
+
export async function getCacheKey(req) {
|
|
6
9
|
const path = url.parse(req.originalUrl).pathname;
|
|
7
10
|
const isGraphQl = path?.startsWith('/graphql');
|
|
11
|
+
let includeIp = false;
|
|
12
|
+
if (req.accountability && req.accountability.ip) {
|
|
13
|
+
// Check if the IP influences the result of the request, that can be the case if some policies have an ip_access
|
|
14
|
+
// filter and the request IP matches any of those filters
|
|
15
|
+
const ipFilters = await fetchPoliciesIpAccess(req.accountability, getDatabase());
|
|
16
|
+
includeIp = ipFilters.length > 0 && ipFilters.some((networks) => ipInNetworks(req.accountability.ip, networks));
|
|
17
|
+
}
|
|
8
18
|
const info = {
|
|
9
19
|
version,
|
|
10
20
|
user: req.accountability?.user || null,
|
|
11
21
|
path,
|
|
12
22
|
query: isGraphQl ? getGraphqlQueryAndVariables(req) : req.sanitizedQuery,
|
|
23
|
+
...(includeIp && { ip: req.accountability.ip }),
|
|
13
24
|
};
|
|
14
25
|
const key = hash(info);
|
|
15
26
|
return key;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { Query, SchemaOverview } from '@directus/types';
|
|
1
|
+
import type { Filter, Query, SchemaOverview } from '@directus/types';
|
|
2
2
|
import type { Knex } from 'knex';
|
|
3
3
|
type GetColumnOptions = {
|
|
4
4
|
query?: Query | undefined;
|
|
5
|
+
cases?: Filter[];
|
|
5
6
|
originalCollectionName?: string | undefined;
|
|
6
7
|
};
|
|
7
8
|
/**
|
package/dist/utils/get-column.js
CHANGED
|
@@ -30,6 +30,7 @@ export function getColumn(knex, table, column, alias = applyFunctionToColumnName
|
|
|
30
30
|
const result = fn[functionName](table, columnName, {
|
|
31
31
|
type,
|
|
32
32
|
query: options?.query,
|
|
33
|
+
cases: options?.cases,
|
|
33
34
|
originalCollectionName: options?.originalCollectionName,
|
|
34
35
|
});
|
|
35
36
|
if (alias) {
|
|
@@ -2,6 +2,6 @@ import { ItemsService } from '../services/index.js';
|
|
|
2
2
|
import type { AbstractServiceOptions } from '../types/services.js';
|
|
3
3
|
/**
|
|
4
4
|
* Select the correct service for the given collection. This allows the individual services to run
|
|
5
|
-
* their custom checks (f.e. it allows UsersService to prevent updating TFA secret from outside)
|
|
5
|
+
* their custom checks (f.e. it allows `UsersService` to prevent updating TFA secret from outside).
|
|
6
6
|
*/
|
|
7
7
|
export declare function getService(collection: string, opts: AbstractServiceOptions): ItemsService;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ForbiddenError } from '@directus/errors';
|
|
2
|
+
import { AccessService, ActivityService, DashboardsService, FilesService, FlowsService, FoldersService, ItemsService, NotificationsService, OperationsService, PanelsService, PermissionsService, PoliciesService, PresetsService, RevisionsService, RolesService, SettingsService, SharesService, TranslationsService, UsersService, VersionsService, WebhooksService, } from '../services/index.js';
|
|
2
3
|
/**
|
|
3
4
|
* Select the correct service for the given collection. This allows the individual services to run
|
|
4
|
-
* their custom checks (f.e. it allows UsersService to prevent updating TFA secret from outside)
|
|
5
|
+
* their custom checks (f.e. it allows `UsersService` to prevent updating TFA secret from outside).
|
|
5
6
|
*/
|
|
6
7
|
export function getService(collection, opts) {
|
|
7
8
|
switch (collection) {
|
|
9
|
+
case 'directus_access':
|
|
10
|
+
return new AccessService(opts);
|
|
8
11
|
case 'directus_activity':
|
|
9
12
|
return new ActivityService(opts);
|
|
10
|
-
// case 'directus_collections':
|
|
11
|
-
// return new CollectionsService(opts);
|
|
12
13
|
case 'directus_dashboards':
|
|
13
14
|
return new DashboardsService(opts);
|
|
14
|
-
// case 'directus_fields':
|
|
15
|
-
// return new FieldsService(opts);
|
|
16
15
|
case 'directus_files':
|
|
17
16
|
return new FilesService(opts);
|
|
18
17
|
case 'directus_flows':
|
|
@@ -29,8 +28,8 @@ export function getService(collection, opts) {
|
|
|
29
28
|
return new PermissionsService(opts);
|
|
30
29
|
case 'directus_presets':
|
|
31
30
|
return new PresetsService(opts);
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
case 'directus_policies':
|
|
32
|
+
return new PoliciesService(opts);
|
|
34
33
|
case 'directus_revisions':
|
|
35
34
|
return new RevisionsService(opts);
|
|
36
35
|
case 'directus_roles':
|
|
@@ -39,13 +38,18 @@ export function getService(collection, opts) {
|
|
|
39
38
|
return new SettingsService(opts);
|
|
40
39
|
case 'directus_shares':
|
|
41
40
|
return new SharesService(opts);
|
|
41
|
+
case 'directus_translations':
|
|
42
|
+
return new TranslationsService(opts);
|
|
42
43
|
case 'directus_users':
|
|
43
44
|
return new UsersService(opts);
|
|
44
|
-
case 'directus_webhooks':
|
|
45
|
-
return new WebhooksService(opts);
|
|
46
45
|
case 'directus_versions':
|
|
47
46
|
return new VersionsService(opts);
|
|
47
|
+
case 'directus_webhooks':
|
|
48
|
+
return new WebhooksService(opts);
|
|
48
49
|
default:
|
|
50
|
+
// Deny usage of other system collections via ItemsService
|
|
51
|
+
if (collection.startsWith('directus_'))
|
|
52
|
+
throw new ForbiddenError();
|
|
49
53
|
return new ItemsService(collection, opts);
|
|
50
54
|
}
|
|
51
55
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SchemaOverview } from '@directus/types';
|
|
2
|
+
import type { FieldMap } from '../permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.js';
|
|
2
3
|
/**
|
|
3
4
|
* Reduces the schema based on the included permissions. The resulting object is the schema structure, but with only
|
|
4
|
-
* the allowed collections/fields/relations included based on the
|
|
5
|
-
* @param schema The full project schema
|
|
6
|
-
* @param actions Array of permissions actions (crud)
|
|
7
|
-
* @returns Reduced schema
|
|
5
|
+
* the allowed collections/fields/relations included based on the passed field map.
|
|
8
6
|
*/
|
|
9
|
-
export declare function reduceSchema(schema: SchemaOverview,
|
|
7
|
+
export declare function reduceSchema(schema: SchemaOverview, fieldMap: FieldMap): SchemaOverview;
|
|
@@ -1,40 +1,20 @@
|
|
|
1
|
-
import { uniq } from 'lodash-es';
|
|
2
1
|
/**
|
|
3
2
|
* Reduces the schema based on the included permissions. The resulting object is the schema structure, but with only
|
|
4
|
-
* the allowed collections/fields/relations included based on the
|
|
5
|
-
* @param schema The full project schema
|
|
6
|
-
* @param actions Array of permissions actions (crud)
|
|
7
|
-
* @returns Reduced schema
|
|
3
|
+
* the allowed collections/fields/relations included based on the passed field map.
|
|
8
4
|
*/
|
|
9
|
-
export function reduceSchema(schema,
|
|
5
|
+
export function reduceSchema(schema, fieldMap) {
|
|
10
6
|
const reduced = {
|
|
11
7
|
collections: {},
|
|
12
8
|
relations: [],
|
|
13
9
|
};
|
|
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
|
-
}, {}) ?? {};
|
|
25
10
|
for (const [collectionName, collection] of Object.entries(schema.collections)) {
|
|
26
|
-
if (!permissions?.some((permission) => permission.collection === collectionName && actions.includes(permission.action))) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
11
|
const fields = {};
|
|
30
12
|
for (const [fieldName, field] of Object.entries(schema.collections[collectionName].fields)) {
|
|
31
|
-
if (!
|
|
32
|
-
!allowedFieldsInCollection[collectionName]?.includes(fieldName)) {
|
|
13
|
+
if (!fieldMap[collectionName]?.includes('*') && !fieldMap[collectionName]?.includes(fieldName)) {
|
|
33
14
|
continue;
|
|
34
15
|
}
|
|
35
16
|
const o2mRelation = schema.relations.find((relation) => relation.related_collection === collectionName && relation.meta?.one_field === fieldName);
|
|
36
|
-
if (o2mRelation &&
|
|
37
|
-
!permissions?.some((permission) => permission.collection === o2mRelation.collection && actions.includes(permission.action))) {
|
|
17
|
+
if (o2mRelation && !fieldMap[collectionName]) {
|
|
38
18
|
continue;
|
|
39
19
|
}
|
|
40
20
|
fields[fieldName] = field;
|
|
@@ -47,29 +27,29 @@ export function reduceSchema(schema, permissions, actions = ['create', 'read', '
|
|
|
47
27
|
reduced.relations = schema.relations.filter((relation) => {
|
|
48
28
|
let collectionsAllowed = true;
|
|
49
29
|
let fieldsAllowed = true;
|
|
50
|
-
if (Object.keys(
|
|
30
|
+
if (Object.keys(fieldMap).includes(relation.collection) === false) {
|
|
51
31
|
collectionsAllowed = false;
|
|
52
32
|
}
|
|
53
33
|
if (relation.related_collection &&
|
|
54
|
-
(Object.keys(
|
|
34
|
+
(Object.keys(fieldMap).includes(relation.related_collection) === false ||
|
|
55
35
|
// Ignore legacy permissions with an empty fields array
|
|
56
|
-
|
|
36
|
+
fieldMap[relation.related_collection]?.length === 0)) {
|
|
57
37
|
collectionsAllowed = false;
|
|
58
38
|
}
|
|
59
39
|
if (relation.meta?.one_allowed_collections &&
|
|
60
|
-
relation.meta.one_allowed_collections.every((collection) => Object.keys(
|
|
40
|
+
relation.meta.one_allowed_collections.every((collection) => Object.keys(fieldMap).includes(collection)) === false) {
|
|
61
41
|
collectionsAllowed = false;
|
|
62
42
|
}
|
|
63
|
-
if (!
|
|
64
|
-
(
|
|
65
|
-
|
|
43
|
+
if (!fieldMap[relation.collection] ||
|
|
44
|
+
(fieldMap[relation.collection]?.includes('*') === false &&
|
|
45
|
+
fieldMap[relation.collection]?.includes(relation.field) === false)) {
|
|
66
46
|
fieldsAllowed = false;
|
|
67
47
|
}
|
|
68
48
|
if (relation.related_collection &&
|
|
69
49
|
relation.meta?.one_field &&
|
|
70
|
-
(!
|
|
71
|
-
(
|
|
72
|
-
|
|
50
|
+
(!fieldMap[relation.related_collection] ||
|
|
51
|
+
(fieldMap[relation.related_collection]?.includes('*') === false &&
|
|
52
|
+
fieldMap[relation.related_collection]?.includes(relation.meta?.one_field) === false))) {
|
|
73
53
|
fieldsAllowed = false;
|
|
74
54
|
}
|
|
75
55
|
return collectionsAllowed && fieldsAllowed;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type FetchUserCountOptions } from './fetch-user-count/fetch-user-count.js';
|
|
2
|
+
export declare enum UserIntegrityCheckFlag {
|
|
3
|
+
None = 0,
|
|
4
|
+
/** Check if the number of remaining admin users is greater than 0 */
|
|
5
|
+
RemainingAdmins = 1,
|
|
6
|
+
/** Check if the number of users is within the limits */
|
|
7
|
+
UserLimits = 2,
|
|
8
|
+
All = 3
|
|
9
|
+
}
|
|
10
|
+
export interface ValidateUserCountIntegrityOptions extends Omit<FetchUserCountOptions, 'adminOnly'> {
|
|
11
|
+
flags: UserIntegrityCheckFlag;
|
|
12
|
+
}
|
|
13
|
+
export declare function validateUserCountIntegrity(options: ValidateUserCountIntegrityOptions): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { validateRemainingAdminCount } from '../permissions/modules/validate-remaining-admin/validate-remaining-admin-count.js';
|
|
2
|
+
import { checkUserLimits } from '../telemetry/utils/check-user-limits.js';
|
|
3
|
+
import { shouldCheckUserLimits } from '../telemetry/utils/should-check-user-limits.js';
|
|
4
|
+
import { fetchUserCount } from './fetch-user-count/fetch-user-count.js';
|
|
5
|
+
export var UserIntegrityCheckFlag;
|
|
6
|
+
(function (UserIntegrityCheckFlag) {
|
|
7
|
+
UserIntegrityCheckFlag[UserIntegrityCheckFlag["None"] = 0] = "None";
|
|
8
|
+
/** Check if the number of remaining admin users is greater than 0 */
|
|
9
|
+
UserIntegrityCheckFlag[UserIntegrityCheckFlag["RemainingAdmins"] = 1] = "RemainingAdmins";
|
|
10
|
+
/** Check if the number of users is within the limits */
|
|
11
|
+
UserIntegrityCheckFlag[UserIntegrityCheckFlag["UserLimits"] = 2] = "UserLimits";
|
|
12
|
+
UserIntegrityCheckFlag[UserIntegrityCheckFlag["All"] = 3] = "All";
|
|
13
|
+
})(UserIntegrityCheckFlag || (UserIntegrityCheckFlag = {}));
|
|
14
|
+
export async function validateUserCountIntegrity(options) {
|
|
15
|
+
const validateUserLimits = (options.flags & UserIntegrityCheckFlag.UserLimits) !== 0;
|
|
16
|
+
const validateRemainingAdminUsers = (options.flags & UserIntegrityCheckFlag.RemainingAdmins) !== 0;
|
|
17
|
+
const limitCheck = validateUserLimits && shouldCheckUserLimits();
|
|
18
|
+
if (!validateRemainingAdminUsers && !limitCheck) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const adminOnly = validateRemainingAdminUsers && !limitCheck;
|
|
22
|
+
const userCounts = await fetchUserCount({ ...options, adminOnly });
|
|
23
|
+
if (limitCheck) {
|
|
24
|
+
await checkUserLimits(userCounts);
|
|
25
|
+
}
|
|
26
|
+
if (validateRemainingAdminUsers) {
|
|
27
|
+
validateRemainingAdminCount(userCounts.admin);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { Accountability } from '@directus/types';
|
|
2
1
|
import type { BasicAuthMessage } from './messages.js';
|
|
3
2
|
import type { AuthenticationState } from './types.js';
|
|
4
3
|
export declare function authenticateConnection(message: BasicAuthMessage & Record<string, any>): Promise<AuthenticationState>;
|
|
5
|
-
export declare function refreshAccountability(accountability: Accountability | null | undefined): Promise<Accountability>;
|
|
6
4
|
export declare function authenticationSuccess(uid?: string | number, refresh_token?: string): string;
|
|
@@ -1,7 +1,6 @@
|
|
|
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';
|
|
5
4
|
import { getSchema } from '../utils/get-schema.js';
|
|
6
5
|
import { WebSocketError } from './errors.js';
|
|
7
6
|
import { getExpiresAtForToken } from './utils/get-expires-at-for-token.js';
|
|
@@ -33,17 +32,6 @@ export async function authenticateConnection(message) {
|
|
|
33
32
|
throw new WebSocketError('auth', 'AUTH_FAILED', 'Authentication failed.', message['uid']);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
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
|
-
}
|
|
47
35
|
export function authenticationSuccess(uid, refresh_token) {
|
|
48
36
|
const message = {
|
|
49
37
|
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
|
|
7
|
+
import { authenticateConnection } 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,9 +64,6 @@ 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
|
-
}
|
|
70
67
|
await cb(JSON.stringify(message));
|
|
71
68
|
}
|
|
72
69
|
catch (error) {
|
|
@@ -7,19 +7,23 @@ export function registerWebSocketEvents() {
|
|
|
7
7
|
actionsRegistered = true;
|
|
8
8
|
registerActionHooks([
|
|
9
9
|
'items',
|
|
10
|
+
'access',
|
|
10
11
|
'activity',
|
|
11
12
|
'collections',
|
|
12
13
|
'dashboards',
|
|
14
|
+
'flows',
|
|
13
15
|
'folders',
|
|
14
16
|
'notifications',
|
|
15
17
|
'operations',
|
|
16
18
|
'panels',
|
|
17
19
|
'permissions',
|
|
20
|
+
'policies',
|
|
18
21
|
'presets',
|
|
19
22
|
'revisions',
|
|
20
23
|
'roles',
|
|
21
24
|
'settings',
|
|
22
25
|
'shares',
|
|
26
|
+
'translations',
|
|
23
27
|
'users',
|
|
24
28
|
'versions',
|
|
25
29
|
'webhooks',
|
|
@@ -2,7 +2,6 @@ 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';
|
|
6
5
|
import { WebSocketError, handleWebSocketError } from '../errors.js';
|
|
7
6
|
import { WebSocketMessage } from '../messages.js';
|
|
8
7
|
import SocketController from './base.js';
|
|
@@ -20,7 +19,6 @@ export class WebSocketController extends SocketController {
|
|
|
20
19
|
client.on('parsed-message', async (message) => {
|
|
21
20
|
try {
|
|
22
21
|
message = WebSocketMessage.parse(await emitter.emitFilter('websocket.message', message, { client }));
|
|
23
|
-
client.accountability = await refreshAccountability(client.accountability);
|
|
24
22
|
emitter.emitAction('websocket.message', { message, client });
|
|
25
23
|
}
|
|
26
24
|
catch (error) {
|
|
@@ -4,7 +4,6 @@ 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';
|
|
8
7
|
import { WebSocketError, handleWebSocketError } from '../errors.js';
|
|
9
8
|
import { WebSocketSubscribeMessage } from '../messages.js';
|
|
10
9
|
import { getPayload } from '../utils/items.js';
|
|
@@ -112,7 +111,6 @@ export class SubscribeHandler {
|
|
|
112
111
|
continue;
|
|
113
112
|
}
|
|
114
113
|
try {
|
|
115
|
-
client.accountability = await refreshAccountability(client.accountability);
|
|
116
114
|
const result = await getPayload(subscription, client.accountability, schema, event);
|
|
117
115
|
if (Array.isArray(result?.['data']) && result?.['data']?.length === 0)
|
|
118
116
|
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 | import("@directus/types").Item |
|
|
42
|
+
export declare function getItemsPayload(subscription: PSubscription, accountability: Accountability | null, schema: SchemaOverview, event?: WebSocketEvent): Promise<string | number | (string | number)[] | import("@directus/types").Item | import("@directus/types").Item[]>;
|
|
43
43
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InvalidPayloadError } from '@directus/errors';
|
|
2
2
|
import { CollectionsService, FieldsService, MetaService } from '../../services/index.js';
|
|
3
|
+
import { getService } from '../../utils/get-service.js';
|
|
3
4
|
/**
|
|
4
5
|
* Get items from a collection using the appropriate service
|
|
5
6
|
*
|
|
@@ -24,6 +25,8 @@ export async function getPayload(subscription, accountability, schema, event) {
|
|
|
24
25
|
case 'directus_relations':
|
|
25
26
|
result['data'] = event?.payload;
|
|
26
27
|
break;
|
|
28
|
+
case 'directus_extensions':
|
|
29
|
+
throw new InvalidPayloadError({ reason: '"directus_extensions" is currently not supported.' });
|
|
27
30
|
default:
|
|
28
31
|
result['data'] = await getItemsPayload(subscription, accountability, schema, event);
|
|
29
32
|
break;
|