directus 9.23.1 → 9.23.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.
- package/dist/app.js +14 -10
- package/dist/auth/auth.d.ts +3 -3
- package/dist/auth/auth.js +2 -0
- package/dist/auth/drivers/ldap.d.ts +1 -1
- package/dist/auth/drivers/ldap.js +39 -28
- package/dist/auth/drivers/local.d.ts +1 -1
- package/dist/auth/drivers/local.js +13 -10
- package/dist/auth/drivers/oauth2.d.ts +1 -1
- package/dist/auth/drivers/oauth2.js +20 -13
- package/dist/auth/drivers/openid.d.ts +1 -1
- package/dist/auth/drivers/openid.js +21 -14
- package/dist/auth/drivers/saml.d.ts +1 -1
- package/dist/auth/drivers/saml.js +10 -7
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +4 -4
- package/dist/cache.d.ts +9 -1
- package/dist/cache.js +57 -14
- package/dist/cli/commands/bootstrap/index.js +2 -2
- package/dist/cli/commands/init/index.js +3 -3
- package/dist/cli/commands/schema/apply.js +14 -15
- package/dist/cli/commands/schema/snapshot.js +2 -2
- package/dist/cli/utils/create-db-connection.d.ts +1 -1
- package/dist/cli/utils/create-db-connection.js +2 -1
- package/dist/cli/utils/create-env/index.d.ts +2 -2
- package/dist/cli/utils/drivers.d.ts +1 -1
- package/dist/constants.d.ts +2 -2
- package/dist/constants.js +2 -3
- package/dist/controllers/activity.js +1 -2
- package/dist/controllers/assets.js +14 -9
- package/dist/controllers/auth.js +29 -15
- package/dist/controllers/dashboards.js +5 -2
- package/dist/controllers/fields.js +4 -4
- package/dist/controllers/files.js +10 -5
- package/dist/controllers/flows.js +5 -2
- package/dist/controllers/folders.js +5 -2
- package/dist/controllers/graphql.js +2 -4
- package/dist/controllers/items.js +5 -2
- package/dist/controllers/not-found.d.ts +1 -1
- package/dist/controllers/not-found.js +1 -2
- package/dist/controllers/notifications.js +5 -2
- package/dist/controllers/operations.js +5 -2
- package/dist/controllers/panels.js +5 -2
- package/dist/controllers/permissions.js +5 -2
- package/dist/controllers/presets.js +5 -2
- package/dist/controllers/roles.js +5 -2
- package/dist/controllers/shares.js +8 -5
- package/dist/controllers/users.js +16 -20
- package/dist/controllers/utils.js +6 -11
- package/dist/controllers/webhooks.js +5 -2
- package/dist/database/helpers/fn/dialects/mssql.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/mssql.js +10 -11
- package/dist/database/helpers/fn/dialects/mysql.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/mysql.js +2 -3
- package/dist/database/helpers/fn/dialects/oracle.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/oracle.js +10 -11
- package/dist/database/helpers/fn/dialects/postgres.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/postgres.js +10 -11
- package/dist/database/helpers/fn/dialects/sqlite.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/sqlite.js +10 -11
- package/dist/database/helpers/fn/types.d.ts +5 -5
- package/dist/database/helpers/fn/types.js +5 -4
- package/dist/database/helpers/geometry/dialects/mssql.d.ts +3 -3
- package/dist/database/helpers/geometry/dialects/mysql.d.ts +1 -1
- package/dist/database/helpers/geometry/dialects/oracle.d.ts +3 -3
- package/dist/database/helpers/geometry/dialects/postgres.d.ts +3 -3
- package/dist/database/helpers/geometry/dialects/postgres.js +1 -2
- package/dist/database/helpers/geometry/dialects/redshift.d.ts +2 -2
- package/dist/database/helpers/geometry/dialects/sqlite.d.ts +1 -1
- package/dist/database/helpers/geometry/types.d.ts +2 -2
- package/dist/database/helpers/geometry/types.js +1 -2
- package/dist/database/helpers/index.d.ts +5 -5
- package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mssql.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mysql.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mysql.js +1 -2
- package/dist/database/helpers/schema/dialects/oracle.d.ts +2 -2
- package/dist/database/helpers/schema/dialects/oracle.js +4 -6
- package/dist/database/helpers/schema/types.d.ts +4 -4
- package/dist/database/helpers/types.d.ts +1 -1
- package/dist/database/helpers/types.js +1 -0
- package/dist/database/index.d.ts +1 -1
- package/dist/database/index.js +8 -8
- package/dist/database/migrations/20201028A-remove-collection-foreign-keys.d.ts +1 -1
- package/dist/database/migrations/20201029A-remove-system-relations.d.ts +1 -1
- package/dist/database/migrations/20201029B-remove-system-collections.d.ts +1 -1
- package/dist/database/migrations/20201029C-remove-system-fields.d.ts +1 -1
- package/dist/database/migrations/20201105A-add-cascade-system-relations.d.ts +1 -1
- package/dist/database/migrations/20201105B-change-webhook-url-type.d.ts +1 -1
- package/dist/database/migrations/20210225A-add-relations-sort-field.d.ts +1 -1
- package/dist/database/migrations/20210225A-add-relations-sort-field.js +1 -2
- package/dist/database/migrations/20210304A-remove-locked-fields.d.ts +1 -1
- package/dist/database/migrations/20210312A-webhooks-collections-text.d.ts +1 -1
- package/dist/database/migrations/20210331A-add-refresh-interval.d.ts +1 -1
- package/dist/database/migrations/20210415A-make-filesize-nullable.d.ts +1 -1
- package/dist/database/migrations/20210416A-add-collections-accountability.d.ts +1 -1
- package/dist/database/migrations/20210422A-remove-files-interface.d.ts +1 -1
- package/dist/database/migrations/20210506A-rename-interfaces.d.ts +1 -1
- package/dist/database/migrations/20210510A-restructure-relations.d.ts +1 -1
- package/dist/database/migrations/20210518A-add-foreign-key-constraints.d.ts +1 -1
- package/dist/database/migrations/20210518A-add-foreign-key-constraints.js +1 -1
- package/dist/database/migrations/20210519A-add-system-fk-triggers.d.ts +1 -1
- package/dist/database/migrations/20210519A-add-system-fk-triggers.js +2 -2
- package/dist/database/migrations/20210521A-add-collections-icon-color.d.ts +1 -1
- package/dist/database/migrations/20210525A-add-insights.d.ts +1 -1
- package/dist/database/migrations/20210608A-add-deep-clone-config.d.ts +1 -1
- package/dist/database/migrations/20210626A-change-filesize-bigint.d.ts +1 -1
- package/dist/database/migrations/20210716A-add-conditions-to-fields.d.ts +1 -1
- package/dist/database/migrations/20210721A-add-default-folder.d.ts +1 -1
- package/dist/database/migrations/20210802A-replace-groups.d.ts +1 -1
- package/dist/database/migrations/20210803A-add-required-to-fields.d.ts +1 -1
- package/dist/database/migrations/20210805A-update-groups.d.ts +1 -1
- package/dist/database/migrations/20210805B-change-image-metadata-structure.d.ts +1 -1
- package/dist/database/migrations/20210811A-add-geometry-config.d.ts +1 -1
- package/dist/database/migrations/20210831A-remove-limit-column.d.ts +1 -1
- package/dist/database/migrations/20210903A-add-auth-provider.d.ts +1 -1
- package/dist/database/migrations/20210907A-webhooks-collections-not-null.d.ts +1 -1
- package/dist/database/migrations/20210910A-move-module-setup.d.ts +1 -1
- package/dist/database/migrations/20210920A-webhooks-url-not-null.d.ts +1 -1
- package/dist/database/migrations/20210924A-add-collection-organization.d.ts +1 -1
- package/dist/database/migrations/20210927A-replace-fields-group.d.ts +1 -1
- package/dist/database/migrations/20210927B-replace-m2m-interface.d.ts +1 -1
- package/dist/database/migrations/20210929A-rename-login-action.d.ts +1 -1
- package/dist/database/migrations/20211007A-update-presets.d.ts +1 -1
- package/dist/database/migrations/20211007A-update-presets.js +7 -9
- package/dist/database/migrations/20211009A-add-auth-data.d.ts +1 -1
- package/dist/database/migrations/20211016A-add-webhook-headers.d.ts +1 -1
- package/dist/database/migrations/20211103A-set-unique-to-user-token.d.ts +1 -1
- package/dist/database/migrations/20211103B-update-special-geometry.d.ts +1 -1
- package/dist/database/migrations/20211104A-remove-collections-listing.d.ts +1 -1
- package/dist/database/migrations/20211118A-add-notifications.d.ts +1 -1
- package/dist/database/migrations/20211211A-add-shares.d.ts +1 -1
- package/dist/database/migrations/20211230A-add-project-descriptor.d.ts +1 -1
- package/dist/database/migrations/20220303A-remove-default-project-color.d.ts +1 -1
- package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.d.ts +1 -1
- package/dist/database/migrations/20220314A-add-translation-strings.d.ts +1 -1
- package/dist/database/migrations/20220322A-rename-field-typecast-flags.d.ts +1 -1
- package/dist/database/migrations/20220323A-add-field-validation.d.ts +1 -1
- package/dist/database/migrations/20220325A-fix-typecast-flags.d.ts +1 -1
- package/dist/database/migrations/20220325B-add-default-language.d.ts +1 -1
- package/dist/database/migrations/20220402A-remove-default-value-panel-icon.d.ts +1 -1
- package/dist/database/migrations/20220429A-add-flows.d.ts +1 -1
- package/dist/database/migrations/20220429B-add-color-to-insights-icon.d.ts +1 -1
- package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.d.ts +1 -1
- package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.d.ts +1 -1
- package/dist/database/migrations/20220614A-rename-hook-trigger-to-event.d.ts +1 -1
- package/dist/database/migrations/20220801A-update-notifications-timestamp-column.d.ts +1 -1
- package/dist/database/migrations/20220802A-add-custom-aspect-ratios.d.ts +1 -1
- package/dist/database/migrations/20220826A-add-origin-to-accountability.d.ts +1 -1
- package/dist/database/migrations/run.d.ts +1 -1
- package/dist/database/run-ast.d.ts +3 -3
- package/dist/database/run-ast.js +17 -26
- package/dist/database/seeds/run.d.ts +1 -1
- package/dist/database/seeds/run.js +1 -2
- package/dist/database/system-data/app-access-permissions/index.d.ts +1 -1
- package/dist/database/system-data/collections/index.d.ts +1 -1
- package/dist/database/system-data/fields/collections.yaml +2 -0
- package/dist/database/system-data/fields/index.d.ts +1 -1
- package/dist/database/system-data/fields/index.js +1 -2
- package/dist/database/system-data/fields/settings.yaml +4 -0
- package/dist/database/system-data/relations/index.d.ts +1 -1
- package/dist/emitter.d.ts +1 -1
- package/dist/emitter.js +3 -0
- package/dist/env.js +10 -2
- package/dist/exceptions/database/dialects/mssql.d.ts +1 -1
- package/dist/exceptions/database/dialects/mssql.js +5 -6
- package/dist/exceptions/database/dialects/mysql.d.ts +1 -1
- package/dist/exceptions/database/dialects/mysql.js +19 -25
- package/dist/exceptions/database/dialects/oracle.d.ts +1 -1
- package/dist/exceptions/database/dialects/postgres.d.ts +1 -1
- package/dist/exceptions/database/dialects/sqlite.d.ts +1 -1
- package/dist/exceptions/database/translate.d.ts +1 -1
- package/dist/exceptions/database/value-out-of-range.js +1 -1
- package/dist/exceptions/range-not-satisfiable.js +2 -3
- package/dist/extensions.d.ts +1 -1
- package/dist/extensions.js +33 -23
- package/dist/flows.js +42 -25
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +19 -3
- package/dist/messenger.js +8 -6
- package/dist/middleware/authenticate.d.ts +1 -1
- package/dist/middleware/authenticate.js +12 -5
- package/dist/middleware/cache.d.ts +1 -1
- package/dist/middleware/cache.js +5 -5
- package/dist/middleware/check-ip.d.ts +1 -1
- package/dist/middleware/check-ip.js +1 -1
- package/dist/middleware/collection-exists.d.ts +1 -1
- package/dist/middleware/collection-exists.js +2 -2
- package/dist/middleware/cors.d.ts +1 -1
- package/dist/middleware/error-handler.d.ts +1 -1
- package/dist/middleware/error-handler.js +9 -10
- package/dist/middleware/extract-token.d.ts +1 -1
- package/dist/middleware/get-permissions.d.ts +1 -1
- package/dist/middleware/graphql.d.ts +1 -1
- package/dist/middleware/graphql.js +3 -3
- package/dist/middleware/rate-limiter-global.d.ts +5 -0
- package/dist/middleware/rate-limiter-global.js +48 -0
- package/dist/middleware/{rate-limiter.d.ts → rate-limiter-ip.d.ts} +2 -2
- package/dist/middleware/{rate-limiter.js → rate-limiter-ip.js} +3 -3
- package/dist/middleware/respond.d.ts +1 -1
- package/dist/middleware/respond.js +6 -7
- package/dist/middleware/sanitize-query.d.ts +1 -1
- package/dist/middleware/schema.d.ts +1 -1
- package/dist/middleware/use-collection.d.ts +1 -1
- package/dist/operations/condition/index.d.ts +1 -1
- package/dist/operations/exec/index.js +14 -3
- package/dist/operations/item-create/index.js +1 -2
- package/dist/operations/item-delete/index.d.ts +1 -1
- package/dist/operations/item-read/index.d.ts +1 -1
- package/dist/operations/item-update/index.d.ts +1 -1
- package/dist/operations/item-update/index.js +1 -2
- package/dist/operations/notification/index.js +1 -2
- package/dist/operations/request/index.js +19 -19
- package/dist/operations/trigger/index.js +2 -3
- package/dist/rate-limiter.d.ts +1 -1
- package/dist/rate-limiter.js +8 -8
- package/dist/server.js +8 -9
- package/dist/services/activity.d.ts +1 -1
- package/dist/services/activity.js +7 -6
- package/dist/services/assets.d.ts +3 -3
- package/dist/services/assets.js +33 -35
- package/dist/services/authentication.d.ts +2 -2
- package/dist/services/authentication.js +13 -10
- package/dist/services/authorization.d.ts +3 -3
- package/dist/services/authorization.js +27 -31
- package/dist/services/collections.d.ts +5 -5
- package/dist/services/collections.js +52 -48
- package/dist/services/dashboards.d.ts +1 -1
- package/dist/services/fields.d.ts +5 -5
- package/dist/services/fields.js +48 -48
- package/dist/services/files.d.ts +1 -2
- package/dist/services/files.js +27 -21
- package/dist/services/flows.d.ts +2 -2
- package/dist/services/folders.d.ts +1 -1
- package/dist/services/graphql/index.d.ts +4 -4
- package/dist/services/graphql/index.js +172 -167
- package/dist/services/graphql/utils/add-path-to-validation-error.js +1 -2
- package/dist/services/graphql/utils/process-error.d.ts +2 -2
- package/dist/services/graphql/utils/process-error.js +11 -4
- package/dist/services/import-export.d.ts +3 -3
- package/dist/services/import-export.js +25 -22
- package/dist/services/items.d.ts +3 -3
- package/dist/services/items.js +42 -36
- package/dist/services/mail/index.d.ts +4 -4
- package/dist/services/mail/index.js +9 -5
- package/dist/services/meta.d.ts +3 -3
- package/dist/services/meta.js +10 -9
- package/dist/services/notifications.d.ts +3 -3
- package/dist/services/notifications.js +7 -6
- package/dist/services/operations.d.ts +2 -2
- package/dist/services/panels.d.ts +1 -1
- package/dist/services/payload.d.ts +3 -3
- package/dist/services/payload.js +124 -122
- package/dist/services/permissions.d.ts +3 -3
- package/dist/services/permissions.js +11 -11
- package/dist/services/presets.d.ts +1 -1
- package/dist/services/relations.d.ts +6 -6
- package/dist/services/relations.js +45 -43
- package/dist/services/revisions.d.ts +1 -1
- package/dist/services/roles.d.ts +2 -2
- package/dist/services/roles.js +2 -2
- package/dist/services/schema.d.ts +3 -3
- package/dist/services/schema.js +9 -11
- package/dist/services/server.d.ts +3 -3
- package/dist/services/server.js +69 -13
- package/dist/services/settings.d.ts +1 -1
- package/dist/services/shares.d.ts +1 -1
- package/dist/services/shares.js +5 -6
- package/dist/services/specifications.d.ts +4 -4
- package/dist/services/specifications.js +132 -116
- package/dist/services/tfa.d.ts +2 -2
- package/dist/services/tfa.js +7 -5
- package/dist/services/users.d.ts +3 -3
- package/dist/services/users.js +17 -17
- package/dist/services/utils.d.ts +3 -3
- package/dist/services/utils.js +10 -8
- package/dist/services/webhooks.d.ts +2 -2
- package/dist/services/webhooks.js +2 -1
- package/dist/types/assets.d.ts +1 -1
- package/dist/types/ast.d.ts +1 -1
- package/dist/types/auth.d.ts +2 -2
- package/dist/types/collection.d.ts +2 -2
- package/dist/types/events.d.ts +2 -2
- package/dist/types/graphql.d.ts +2 -2
- package/dist/types/items.d.ts +3 -3
- package/dist/types/services.d.ts +5 -5
- package/dist/types/snapshot.d.ts +4 -4
- package/dist/utils/apply-diff.d.ts +3 -3
- package/dist/utils/apply-diff.js +25 -28
- package/dist/utils/apply-query.d.ts +3 -3
- package/dist/utils/apply-query.js +8 -11
- package/dist/utils/apply-snapshot.d.ts +3 -3
- package/dist/utils/apply-snapshot.js +5 -6
- package/dist/utils/construct-flow-tree.d.ts +1 -1
- package/dist/utils/construct-flow-tree.js +2 -2
- package/dist/utils/filter-items.d.ts +1 -1
- package/dist/utils/get-accountability-for-role.d.ts +2 -2
- package/dist/utils/get-accountability-for-role.js +1 -1
- package/dist/utils/get-ast-from-query.d.ts +3 -3
- package/dist/utils/get-ast-from-query.js +22 -28
- package/dist/utils/get-cache-headers.d.ts +1 -1
- package/dist/utils/get-cache-headers.js +3 -4
- package/dist/utils/get-cache-key.d.ts +1 -1
- package/dist/utils/get-cache-key.js +2 -3
- package/dist/utils/get-collection-from-alias.d.ts +1 -1
- package/dist/utils/get-column-path.d.ts +2 -2
- package/dist/utils/get-column-path.js +3 -4
- package/dist/utils/get-column.d.ts +4 -4
- package/dist/utils/get-column.js +4 -5
- package/dist/utils/get-default-value.d.ts +2 -2
- package/dist/utils/get-default-value.js +1 -2
- package/dist/utils/get-graphql-query-and-variables.d.ts +1 -1
- package/dist/utils/get-graphql-query-and-variables.js +1 -2
- package/dist/utils/get-graphql-type.d.ts +2 -2
- package/dist/utils/get-graphql-type.js +1 -1
- package/dist/utils/get-ip-from-req.d.ts +1 -1
- package/dist/utils/get-local-type.d.ts +1 -1
- package/dist/utils/get-local-type.js +3 -3
- package/dist/utils/get-milliseconds.js +1 -2
- package/dist/utils/get-permissions.d.ts +1 -1
- package/dist/utils/get-permissions.js +1 -1
- package/dist/utils/get-relation-info.d.ts +1 -1
- package/dist/utils/get-relation-info.js +3 -5
- package/dist/utils/get-relation-type.d.ts +1 -1
- package/dist/utils/get-relation-type.js +3 -4
- package/dist/utils/get-schema.d.ts +2 -2
- package/dist/utils/get-schema.js +19 -21
- package/dist/utils/get-snapshot-diff.js +2 -3
- package/dist/utils/get-snapshot.d.ts +3 -3
- package/dist/utils/get-snapshot.js +6 -8
- package/dist/utils/is-directus-jwt.js +1 -1
- package/dist/utils/job-queue.js +2 -0
- package/dist/utils/jwt.d.ts +1 -1
- package/dist/utils/merge-permissions-for-share.d.ts +1 -1
- package/dist/utils/merge-permissions-for-share.js +3 -4
- package/dist/utils/merge-permissions.d.ts +3 -3
- package/dist/utils/redact-header-cookies.d.ts +1 -0
- package/dist/utils/redact-header-cookies.js +11 -0
- package/dist/utils/redact-header-cookies.test.d.ts +1 -0
- package/dist/utils/reduce-schema.d.ts +1 -1
- package/dist/utils/reduce-schema.js +12 -12
- package/dist/utils/sanitize-query.d.ts +1 -1
- package/dist/utils/sanitize-query.js +1 -1
- package/dist/utils/sanitize-schema.d.ts +2 -2
- package/dist/utils/should-skip-cache.d.ts +7 -0
- package/dist/utils/should-skip-cache.js +21 -0
- package/dist/utils/should-skip-cache.test.d.ts +1 -0
- package/dist/utils/transformations.d.ts +1 -1
- package/dist/utils/transformations.js +2 -4
- package/dist/utils/url.js +7 -2
- package/dist/utils/user-name.d.ts +1 -1
- package/dist/utils/validate-diff.js +7 -8
- package/dist/utils/validate-keys.d.ts +2 -2
- package/dist/utils/validate-keys.js +1 -1
- package/dist/utils/validate-query.d.ts +1 -1
- package/dist/utils/validate-query.js +2 -2
- package/dist/webhooks.js +1 -1
- package/package.json +36 -37
- package/dist/utils/with-timeout.d.ts +0 -1
- package/dist/utils/with-timeout.js +0 -16
|
@@ -7,14 +7,18 @@ exports.AuthorizationService = void 0;
|
|
|
7
7
|
const exceptions_1 = require("@directus/shared/exceptions");
|
|
8
8
|
const utils_1 = require("@directus/shared/utils");
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
10
|
+
const constants_1 = require("../constants");
|
|
10
11
|
const database_1 = __importDefault(require("../database"));
|
|
11
12
|
const exceptions_2 = require("../exceptions");
|
|
13
|
+
const get_relation_info_1 = require("../utils/get-relation-info");
|
|
12
14
|
const strip_function_1 = require("../utils/strip-function");
|
|
13
15
|
const items_1 = require("./items");
|
|
14
16
|
const payload_1 = require("./payload");
|
|
15
|
-
const get_relation_info_1 = require("../utils/get-relation-info");
|
|
16
|
-
const constants_1 = require("../constants");
|
|
17
17
|
class AuthorizationService {
|
|
18
|
+
knex;
|
|
19
|
+
accountability;
|
|
20
|
+
payloadService;
|
|
21
|
+
schema;
|
|
18
22
|
constructor(options) {
|
|
19
23
|
this.knex = options.knex || (0, database_1.default)();
|
|
20
24
|
this.accountability = options.accountability || null;
|
|
@@ -25,12 +29,11 @@ class AuthorizationService {
|
|
|
25
29
|
});
|
|
26
30
|
}
|
|
27
31
|
async processAST(ast, action = 'read') {
|
|
28
|
-
var _a, _b, _c;
|
|
29
32
|
const collectionsRequested = getCollectionsFromAST(ast);
|
|
30
|
-
const permissionsForCollections = (
|
|
33
|
+
const permissionsForCollections = (0, lodash_1.uniqWith)(this.accountability?.permissions?.filter((permission) => {
|
|
31
34
|
return (permission.action === action &&
|
|
32
35
|
collectionsRequested.map(({ collection }) => collection).includes(permission.collection));
|
|
33
|
-
}), (curr, prev) => curr.collection === prev.collection && curr.action === prev.action && curr.role === prev.role)
|
|
36
|
+
}), (curr, prev) => curr.collection === prev.collection && curr.action === prev.action && curr.role === prev.role) ?? [];
|
|
34
37
|
// If the permissions don't match the collections, you don't have permission to read all of them
|
|
35
38
|
const uniqueCollectionsRequestedCount = (0, lodash_1.uniq)(collectionsRequested.map(({ collection }) => collection)).length;
|
|
36
39
|
if (uniqueCollectionsRequestedCount !== permissionsForCollections.length) {
|
|
@@ -75,15 +78,14 @@ class AuthorizationService {
|
|
|
75
78
|
return collections;
|
|
76
79
|
}
|
|
77
80
|
function validateFields(ast) {
|
|
78
|
-
var _a, _b, _c;
|
|
79
81
|
if (ast.type !== 'field' && ast.type !== 'functionField') {
|
|
80
82
|
if (ast.type === 'a2o') {
|
|
81
83
|
for (const [collection, children] of Object.entries(ast.children)) {
|
|
82
|
-
checkFields(collection, children,
|
|
84
|
+
checkFields(collection, children, ast.query?.[collection]?.aggregate);
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
else {
|
|
86
|
-
checkFields(ast.name, ast.children,
|
|
88
|
+
checkFields(ast.name, ast.children, ast.query?.aggregate);
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
function checkFields(collection, children, aggregate) {
|
|
@@ -117,12 +119,11 @@ class AuthorizationService {
|
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
function validateFilterPermissions(ast, schema, action, accountability) {
|
|
120
|
-
var _a, _b, _c, _d, _e;
|
|
121
122
|
let requiredFieldPermissions = {};
|
|
122
123
|
if (ast.type !== 'field' && ast.type !== 'functionField') {
|
|
123
124
|
if (ast.type === 'a2o') {
|
|
124
125
|
for (const collection of Object.keys(ast.children)) {
|
|
125
|
-
requiredFieldPermissions = mergeRequiredFieldPermissions(requiredFieldPermissions, extractRequiredFieldPermissions(collection,
|
|
126
|
+
requiredFieldPermissions = mergeRequiredFieldPermissions(requiredFieldPermissions, extractRequiredFieldPermissions(collection, ast.query?.[collection]?.filter ?? {}));
|
|
126
127
|
for (const child of ast.children[collection]) {
|
|
127
128
|
const childPermissions = validateFilterPermissions(child, schema, action, accountability);
|
|
128
129
|
if (Object.keys(childPermissions).length > 0) {
|
|
@@ -136,7 +137,7 @@ class AuthorizationService {
|
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
else {
|
|
139
|
-
requiredFieldPermissions = mergeRequiredFieldPermissions(requiredFieldPermissions, extractRequiredFieldPermissions(ast.name,
|
|
140
|
+
requiredFieldPermissions = mergeRequiredFieldPermissions(requiredFieldPermissions, extractRequiredFieldPermissions(ast.name, ast.query?.filter ?? {}));
|
|
140
141
|
for (const child of ast.children) {
|
|
141
142
|
const childPermissions = validateFilterPermissions(child, schema, action, accountability);
|
|
142
143
|
if (Object.keys(childPermissions).length > 0) {
|
|
@@ -174,7 +175,7 @@ class AuthorizationService {
|
|
|
174
175
|
(result[collection] || (result[collection] = new Set())).add(filterKey);
|
|
175
176
|
// add virtual relation to the required permissions
|
|
176
177
|
const { relation } = (0, get_relation_info_1.getRelationInfo)([], collection, filterKey);
|
|
177
|
-
if (
|
|
178
|
+
if (relation?.collection && relation?.field) {
|
|
178
179
|
(result[relation.collection] || (result[relation.collection] = new Set())).add(relation.field);
|
|
179
180
|
}
|
|
180
181
|
}
|
|
@@ -189,9 +190,8 @@ class AuthorizationService {
|
|
|
189
190
|
}
|
|
190
191
|
else {
|
|
191
192
|
const relation = schema.relations.find((relation) => {
|
|
192
|
-
var _a;
|
|
193
193
|
return ((relation.collection === parentCollection && relation.field === parentField) ||
|
|
194
|
-
(relation.related_collection === parentCollection &&
|
|
194
|
+
(relation.related_collection === parentCollection && relation.meta?.one_field === parentField));
|
|
195
195
|
});
|
|
196
196
|
// Filter key not found in parent collection
|
|
197
197
|
if (!relation)
|
|
@@ -212,9 +212,8 @@ class AuthorizationService {
|
|
|
212
212
|
}
|
|
213
213
|
else {
|
|
214
214
|
const relation = schema.relations.find((relation) => {
|
|
215
|
-
var _a;
|
|
216
215
|
return ((relation.collection === parentCollection && relation.field === parentField) ||
|
|
217
|
-
(relation.related_collection === parentCollection &&
|
|
216
|
+
(relation.related_collection === parentCollection && relation.meta?.one_field === parentField));
|
|
218
217
|
});
|
|
219
218
|
// Filter key not found in parent collection
|
|
220
219
|
if (!relation)
|
|
@@ -260,19 +259,18 @@ class AuthorizationService {
|
|
|
260
259
|
return current;
|
|
261
260
|
}
|
|
262
261
|
function checkFieldPermissions(rootCollection, schema, action, requiredPermissions, aliasMap) {
|
|
263
|
-
|
|
264
|
-
if ((accountability === null || accountability === void 0 ? void 0 : accountability.admin) === true)
|
|
262
|
+
if (accountability?.admin === true)
|
|
265
263
|
return;
|
|
266
264
|
for (const collection of Object.keys(requiredPermissions)) {
|
|
267
|
-
const permission =
|
|
265
|
+
const permission = accountability?.permissions?.find((permission) => permission.collection === collection && permission.action === 'read');
|
|
268
266
|
let allowedFields;
|
|
269
267
|
// Allow the filtering of top level ID for actions such as update and delete
|
|
270
268
|
if (action !== 'read' && collection === rootCollection) {
|
|
271
|
-
const actionPermission =
|
|
269
|
+
const actionPermission = accountability?.permissions?.find((permission) => permission.collection === collection && permission.action === action);
|
|
272
270
|
if (!actionPermission || !actionPermission.fields) {
|
|
273
271
|
throw new exceptions_2.ForbiddenException();
|
|
274
272
|
}
|
|
275
|
-
allowedFields =
|
|
273
|
+
allowedFields = permission?.fields
|
|
276
274
|
? [...permission.fields, schema.collections[collection].primary]
|
|
277
275
|
: [schema.collections[collection].primary];
|
|
278
276
|
}
|
|
@@ -292,7 +290,7 @@ class AuthorizationService {
|
|
|
292
290
|
continue;
|
|
293
291
|
const fieldName = (0, strip_function_1.stripFunction)(field);
|
|
294
292
|
let originalFieldName = fieldName;
|
|
295
|
-
if (collection === rootCollection &&
|
|
293
|
+
if (collection === rootCollection && aliasMap?.[fieldName]) {
|
|
296
294
|
originalFieldName = aliasMap[fieldName];
|
|
297
295
|
}
|
|
298
296
|
if (!allowedFields.includes(originalFieldName)) {
|
|
@@ -345,13 +343,12 @@ class AuthorizationService {
|
|
|
345
343
|
* Checks if the provided payload matches the configured permissions, and adds the presets to the payload.
|
|
346
344
|
*/
|
|
347
345
|
validatePayload(action, collection, data) {
|
|
348
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
349
346
|
const payload = (0, lodash_1.cloneDeep)(data);
|
|
350
347
|
let permission;
|
|
351
|
-
if (
|
|
348
|
+
if (this.accountability?.admin === true) {
|
|
352
349
|
permission = {
|
|
353
350
|
id: 0,
|
|
354
|
-
role:
|
|
351
|
+
role: this.accountability?.role,
|
|
355
352
|
collection,
|
|
356
353
|
action,
|
|
357
354
|
permissions: {},
|
|
@@ -361,7 +358,7 @@ class AuthorizationService {
|
|
|
361
358
|
};
|
|
362
359
|
}
|
|
363
360
|
else {
|
|
364
|
-
permission =
|
|
361
|
+
permission = this.accountability?.permissions?.find((permission) => {
|
|
365
362
|
return permission.collection === collection && permission.action === action;
|
|
366
363
|
});
|
|
367
364
|
if (!permission)
|
|
@@ -376,16 +373,16 @@ class AuthorizationService {
|
|
|
376
373
|
}
|
|
377
374
|
}
|
|
378
375
|
}
|
|
379
|
-
const preset =
|
|
376
|
+
const preset = permission.presets ?? {};
|
|
380
377
|
const payloadWithPresets = (0, lodash_1.merge)({}, preset, payload);
|
|
381
378
|
const fieldValidationRules = Object.values(this.schema.collections[collection].fields)
|
|
382
379
|
.map((field) => field.validation)
|
|
383
380
|
.filter((v) => v);
|
|
384
|
-
const hasValidationRules = (0, lodash_1.isNil)(permission.validation) === false && Object.keys(
|
|
381
|
+
const hasValidationRules = (0, lodash_1.isNil)(permission.validation) === false && Object.keys(permission.validation ?? {}).length > 0;
|
|
385
382
|
const hasFieldValidationRules = fieldValidationRules && fieldValidationRules.length > 0;
|
|
386
383
|
const requiredColumns = [];
|
|
387
384
|
for (const field of Object.values(this.schema.collections[collection].fields)) {
|
|
388
|
-
const specials =
|
|
385
|
+
const specials = field?.special ?? [];
|
|
389
386
|
const hasGenerateSpecial = constants_1.GENERATE_SPECIAL.some((name) => specials.includes(name));
|
|
390
387
|
const nullable = field.nullable || hasGenerateSpecial || field.generated;
|
|
391
388
|
if (!nullable) {
|
|
@@ -427,8 +424,7 @@ class AuthorizationService {
|
|
|
427
424
|
return payloadWithPresets;
|
|
428
425
|
}
|
|
429
426
|
async checkAccess(action, collection, pk) {
|
|
430
|
-
|
|
431
|
-
if (((_a = this.accountability) === null || _a === void 0 ? void 0 : _a.admin) === true)
|
|
427
|
+
if (this.accountability?.admin === true)
|
|
432
428
|
return;
|
|
433
429
|
const itemsService = new items_1.ItemsService(collection, {
|
|
434
430
|
accountability: this.accountability,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import SchemaInspector from '@directus/schema';
|
|
2
|
-
import {
|
|
3
|
-
import Keyv from 'keyv';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { Table } from 'knex-schema-inspector/dist/types/table';
|
|
2
|
+
import type { Accountability, RawField, SchemaOverview } from '@directus/shared/types';
|
|
3
|
+
import type Keyv from 'keyv';
|
|
4
|
+
import type { Knex } from 'knex';
|
|
5
|
+
import type { Table } from 'knex-schema-inspector/dist/types/table';
|
|
7
6
|
import { Helpers } from '../database/helpers';
|
|
7
|
+
import type { AbstractServiceOptions, Collection, CollectionMeta, MutationOptions } from '../types';
|
|
8
8
|
export type RawCollection = {
|
|
9
9
|
collection: string;
|
|
10
10
|
fields?: RawField[];
|
|
@@ -28,20 +28,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.CollectionsService = void 0;
|
|
30
30
|
const schema_1 = __importDefault(require("@directus/schema"));
|
|
31
|
+
const utils_1 = require("@directus/shared/utils");
|
|
32
|
+
const lodash_1 = require("lodash");
|
|
31
33
|
const cache_1 = require("../cache");
|
|
32
34
|
const constants_1 = require("../constants");
|
|
33
35
|
const database_1 = __importStar(require("../database"));
|
|
36
|
+
const helpers_1 = require("../database/helpers");
|
|
34
37
|
const collections_1 = require("../database/system-data/collections");
|
|
38
|
+
const emitter_1 = __importDefault(require("../emitter"));
|
|
35
39
|
const env_1 = __importDefault(require("../env"));
|
|
36
40
|
const exceptions_1 = require("../exceptions");
|
|
37
41
|
const fields_1 = require("../services/fields");
|
|
38
42
|
const items_1 = require("../services/items");
|
|
39
|
-
const utils_1 = require("@directus/shared/utils");
|
|
40
|
-
const helpers_1 = require("../database/helpers");
|
|
41
|
-
const lodash_1 = require("lodash");
|
|
42
43
|
const get_schema_1 = require("../utils/get-schema");
|
|
43
|
-
const emitter_1 = __importDefault(require("../emitter"));
|
|
44
44
|
class CollectionsService {
|
|
45
|
+
knex;
|
|
46
|
+
helpers;
|
|
47
|
+
accountability;
|
|
48
|
+
schemaInspector;
|
|
49
|
+
schema;
|
|
50
|
+
cache;
|
|
51
|
+
systemCache;
|
|
45
52
|
constructor(options) {
|
|
46
53
|
this.knex = options.knex || (0, database_1.default)();
|
|
47
54
|
this.helpers = (0, helpers_1.getHelpers)(this.knex);
|
|
@@ -56,7 +63,6 @@ class CollectionsService {
|
|
|
56
63
|
* Create a single new collection
|
|
57
64
|
*/
|
|
58
65
|
async createOne(payload, opts) {
|
|
59
|
-
var _a, _b;
|
|
60
66
|
if (this.accountability && this.accountability.admin !== true) {
|
|
61
67
|
throw new exceptions_1.ForbiddenException();
|
|
62
68
|
}
|
|
@@ -68,7 +74,8 @@ class CollectionsService {
|
|
|
68
74
|
const nestedActionEvents = [];
|
|
69
75
|
try {
|
|
70
76
|
const existingCollections = [
|
|
71
|
-
...((
|
|
77
|
+
...((await this.knex.select('collection').from('directus_collections'))?.map(({ collection }) => collection) ??
|
|
78
|
+
[]),
|
|
72
79
|
...Object.keys(this.schema.collections),
|
|
73
80
|
];
|
|
74
81
|
if (existingCollections.includes(payload.collection)) {
|
|
@@ -129,7 +136,7 @@ class CollectionsService {
|
|
|
129
136
|
});
|
|
130
137
|
const fieldPayloads = payload.fields.filter((field) => field.meta).map((field) => field.meta);
|
|
131
138
|
await fieldItemsService.createMany(fieldPayloads, {
|
|
132
|
-
bypassEmitAction: (params) =>
|
|
139
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
133
140
|
});
|
|
134
141
|
}
|
|
135
142
|
if (payload.meta) {
|
|
@@ -142,7 +149,7 @@ class CollectionsService {
|
|
|
142
149
|
...payload.meta,
|
|
143
150
|
collection: payload.collection,
|
|
144
151
|
}, {
|
|
145
|
-
bypassEmitAction: (params) =>
|
|
152
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
146
153
|
});
|
|
147
154
|
}
|
|
148
155
|
return payload.collection;
|
|
@@ -150,13 +157,13 @@ class CollectionsService {
|
|
|
150
157
|
return payload.collection;
|
|
151
158
|
}
|
|
152
159
|
finally {
|
|
153
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE &&
|
|
160
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && opts?.autoPurgeCache !== false) {
|
|
154
161
|
await this.cache.clear();
|
|
155
162
|
}
|
|
156
|
-
if (
|
|
157
|
-
await (0, cache_1.clearSystemCache)();
|
|
163
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
164
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
158
165
|
}
|
|
159
|
-
if (
|
|
166
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
160
167
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
161
168
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
162
169
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -191,13 +198,13 @@ class CollectionsService {
|
|
|
191
198
|
return collections;
|
|
192
199
|
}
|
|
193
200
|
finally {
|
|
194
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE &&
|
|
201
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && opts?.autoPurgeCache !== false) {
|
|
195
202
|
await this.cache.clear();
|
|
196
203
|
}
|
|
197
|
-
if (
|
|
198
|
-
await (0, cache_1.clearSystemCache)();
|
|
204
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
205
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
199
206
|
}
|
|
200
|
-
if (
|
|
207
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
201
208
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
202
209
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
203
210
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -210,7 +217,6 @@ class CollectionsService {
|
|
|
210
217
|
* Read all collections. Currently doesn't support any query.
|
|
211
218
|
*/
|
|
212
219
|
async readByQuery() {
|
|
213
|
-
var _a;
|
|
214
220
|
const collectionItemsService = new items_1.ItemsService('directus_collections', {
|
|
215
221
|
knex: this.knex,
|
|
216
222
|
schema: this.schema,
|
|
@@ -250,7 +256,7 @@ class CollectionsService {
|
|
|
250
256
|
const collection = {
|
|
251
257
|
collection: collectionMeta.collection,
|
|
252
258
|
meta: collectionMeta,
|
|
253
|
-
schema:
|
|
259
|
+
schema: tablesInDatabase.find((table) => table.name === collectionMeta.collection) ?? null,
|
|
254
260
|
};
|
|
255
261
|
collections.push(collection);
|
|
256
262
|
}
|
|
@@ -324,25 +330,25 @@ class CollectionsService {
|
|
|
324
330
|
if (exists) {
|
|
325
331
|
await collectionItemsService.updateOne(collectionKey, payload.meta, {
|
|
326
332
|
...opts,
|
|
327
|
-
bypassEmitAction: (params) =>
|
|
333
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
328
334
|
});
|
|
329
335
|
}
|
|
330
336
|
else {
|
|
331
337
|
await collectionItemsService.createOne({ ...payload.meta, collection: collectionKey }, {
|
|
332
338
|
...opts,
|
|
333
|
-
bypassEmitAction: (params) =>
|
|
339
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
334
340
|
});
|
|
335
341
|
}
|
|
336
342
|
return collectionKey;
|
|
337
343
|
}
|
|
338
344
|
finally {
|
|
339
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE &&
|
|
345
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && opts?.autoPurgeCache !== false) {
|
|
340
346
|
await this.cache.clear();
|
|
341
347
|
}
|
|
342
|
-
if (
|
|
343
|
-
await (0, cache_1.clearSystemCache)();
|
|
348
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
349
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
344
350
|
}
|
|
345
|
-
if (
|
|
351
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
346
352
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
347
353
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
348
354
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -377,20 +383,20 @@ class CollectionsService {
|
|
|
377
383
|
await collectionItemsService.updateOne(payload[collectionKey], (0, lodash_1.omit)(payload, collectionKey), {
|
|
378
384
|
autoPurgeCache: false,
|
|
379
385
|
autoPurgeSystemCache: false,
|
|
380
|
-
bypassEmitAction: (params) =>
|
|
386
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
381
387
|
});
|
|
382
388
|
collectionKeys.push(payload[collectionKey]);
|
|
383
389
|
}
|
|
384
390
|
});
|
|
385
391
|
}
|
|
386
392
|
finally {
|
|
387
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE &&
|
|
393
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && opts?.autoPurgeCache !== false) {
|
|
388
394
|
await this.cache.clear();
|
|
389
395
|
}
|
|
390
|
-
if (
|
|
391
|
-
await (0, cache_1.clearSystemCache)();
|
|
396
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
397
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
392
398
|
}
|
|
393
|
-
if (
|
|
399
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
394
400
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
395
401
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
396
402
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -426,13 +432,13 @@ class CollectionsService {
|
|
|
426
432
|
return collectionKeys;
|
|
427
433
|
}
|
|
428
434
|
finally {
|
|
429
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE &&
|
|
435
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && opts?.autoPurgeCache !== false) {
|
|
430
436
|
await this.cache.clear();
|
|
431
437
|
}
|
|
432
|
-
if (
|
|
433
|
-
await (0, cache_1.clearSystemCache)();
|
|
438
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
439
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
434
440
|
}
|
|
435
|
-
if (
|
|
441
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
436
442
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
437
443
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
438
444
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -457,7 +463,6 @@ class CollectionsService {
|
|
|
457
463
|
throw new exceptions_1.ForbiddenException();
|
|
458
464
|
}
|
|
459
465
|
await this.knex.transaction(async (trx) => {
|
|
460
|
-
var _a;
|
|
461
466
|
if (collectionToBeDeleted.schema) {
|
|
462
467
|
await trx.schema.dropTable(collectionKey);
|
|
463
468
|
}
|
|
@@ -470,7 +475,7 @@ class CollectionsService {
|
|
|
470
475
|
schema: this.schema,
|
|
471
476
|
});
|
|
472
477
|
await collectionItemsService.deleteOne(collectionKey, {
|
|
473
|
-
bypassEmitAction: (params) =>
|
|
478
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
474
479
|
});
|
|
475
480
|
}
|
|
476
481
|
if (collectionToBeDeleted.schema) {
|
|
@@ -498,11 +503,11 @@ class CollectionsService {
|
|
|
498
503
|
});
|
|
499
504
|
for (const relation of relations) {
|
|
500
505
|
// Delete related o2m fields that point to current collection
|
|
501
|
-
if (relation.related_collection &&
|
|
506
|
+
if (relation.related_collection && relation.meta?.one_field) {
|
|
502
507
|
await fieldsService.deleteField(relation.related_collection, relation.meta.one_field, {
|
|
503
508
|
autoPurgeCache: false,
|
|
504
509
|
autoPurgeSystemCache: false,
|
|
505
|
-
bypassEmitAction: (params) =>
|
|
510
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
506
511
|
});
|
|
507
512
|
}
|
|
508
513
|
// Delete related m2o fields that point to current collection
|
|
@@ -510,13 +515,12 @@ class CollectionsService {
|
|
|
510
515
|
await fieldsService.deleteField(relation.collection, relation.field, {
|
|
511
516
|
autoPurgeCache: false,
|
|
512
517
|
autoPurgeSystemCache: false,
|
|
513
|
-
bypassEmitAction: (params) =>
|
|
518
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
514
519
|
});
|
|
515
520
|
}
|
|
516
521
|
}
|
|
517
522
|
const a2oRelationsThatIncludeThisCollection = this.schema.relations.filter((relation) => {
|
|
518
|
-
|
|
519
|
-
return (_b = (_a = relation.meta) === null || _a === void 0 ? void 0 : _a.one_allowed_collections) === null || _b === void 0 ? void 0 : _b.includes(collectionKey);
|
|
523
|
+
return relation.meta?.one_allowed_collections?.includes(collectionKey);
|
|
520
524
|
});
|
|
521
525
|
for (const relation of a2oRelationsThatIncludeThisCollection) {
|
|
522
526
|
const newAllowedCollections = relation
|
|
@@ -531,13 +535,13 @@ class CollectionsService {
|
|
|
531
535
|
return collectionKey;
|
|
532
536
|
}
|
|
533
537
|
finally {
|
|
534
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE &&
|
|
538
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && opts?.autoPurgeCache !== false) {
|
|
535
539
|
await this.cache.clear();
|
|
536
540
|
}
|
|
537
|
-
if (
|
|
538
|
-
await (0, cache_1.clearSystemCache)();
|
|
541
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
542
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
539
543
|
}
|
|
540
|
-
if (
|
|
544
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
541
545
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
542
546
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
543
547
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -572,13 +576,13 @@ class CollectionsService {
|
|
|
572
576
|
return collectionKeys;
|
|
573
577
|
}
|
|
574
578
|
finally {
|
|
575
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE &&
|
|
579
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && opts?.autoPurgeCache !== false) {
|
|
576
580
|
await this.cache.clear();
|
|
577
581
|
}
|
|
578
|
-
if (
|
|
579
|
-
await (0, cache_1.clearSystemCache)();
|
|
582
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
583
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
580
584
|
}
|
|
581
|
-
if (
|
|
585
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
582
586
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
583
587
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
584
588
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import SchemaInspector from '@directus/schema';
|
|
2
|
-
import { Accountability, Field, RawField, SchemaOverview, Type } from '@directus/shared/types';
|
|
3
|
-
import Keyv from 'keyv';
|
|
4
|
-
import { Knex } from 'knex';
|
|
5
|
-
import { Column } from 'knex-schema-inspector/dist/types/column';
|
|
2
|
+
import type { Accountability, Field, RawField, SchemaOverview, Type } from '@directus/shared/types';
|
|
3
|
+
import type Keyv from 'keyv';
|
|
4
|
+
import type { Knex } from 'knex';
|
|
5
|
+
import type { Column } from 'knex-schema-inspector/dist/types/column';
|
|
6
6
|
import { Helpers } from '../database/helpers';
|
|
7
7
|
import { ItemsService } from '../services/items';
|
|
8
8
|
import { PayloadService } from '../services/payload';
|
|
9
|
-
import { AbstractServiceOptions, MutationOptions } from '../types';
|
|
9
|
+
import type { AbstractServiceOptions, MutationOptions } from '../types';
|
|
10
10
|
export declare class FieldsService {
|
|
11
11
|
knex: Knex;
|
|
12
12
|
helpers: Helpers;
|