@directus/api 20.0.0 → 21.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 +5 -5
- package/dist/auth/drivers/ldap.js +5 -5
- package/dist/auth/drivers/local.js +4 -4
- package/dist/auth/drivers/oauth2.js +5 -5
- package/dist/auth/drivers/openid.js +3 -5
- package/dist/auth/drivers/saml.js +1 -1
- package/dist/auth.js +1 -1
- package/dist/cache.js +4 -1
- package/dist/cli/commands/bootstrap/index.js +10 -3
- package/dist/cli/commands/count/index.js +1 -1
- package/dist/cli/commands/database/install.js +1 -1
- package/dist/cli/commands/database/migrate.js +1 -1
- package/dist/cli/commands/init/index.js +9 -10
- package/dist/cli/commands/roles/create.js +1 -1
- package/dist/cli/commands/schema/apply.js +1 -1
- package/dist/cli/commands/schema/snapshot.js +1 -1
- package/dist/cli/commands/users/create.js +1 -1
- package/dist/cli/commands/users/passwd.js +1 -1
- package/dist/cli/load-extensions.js +1 -1
- 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/constants.js +2 -2
- package/dist/controllers/access.d.ts +2 -0
- package/dist/controllers/access.js +148 -0
- package/dist/controllers/assets.js +1 -1
- package/dist/controllers/auth.js +6 -17
- package/dist/controllers/files.js +1 -1
- 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/schema.js +1 -1
- package/dist/controllers/tus.js +11 -23
- package/dist/controllers/users.js +0 -55
- 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 +3 -2
- package/dist/database/migrations/20210518A-add-foreign-key-constraints.js +1 -1
- package/dist/database/migrations/20210519A-add-system-fk-triggers.js +1 -1
- package/dist/database/migrations/20210802A-replace-groups.js +1 -1
- package/dist/database/migrations/20230721A-require-shares-fields.js +1 -1
- package/dist/database/migrations/20240710A-permissions-policies.d.ts +3 -0
- package/dist/database/migrations/20240710A-permissions-policies.js +169 -0
- package/dist/database/migrations/run.js +1 -1
- package/dist/database/run-ast/lib/get-db-query.d.ts +4 -0
- package/dist/database/run-ast/lib/get-db-query.js +208 -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/emitter.js +1 -1
- package/dist/extensions/lib/get-shared-deps-mapping.js +1 -1
- package/dist/extensions/lib/installation/manager.js +1 -1
- package/dist/extensions/lib/sandbox/register/call-reference.js +1 -1
- package/dist/extensions/lib/sandbox/sdk/generators/log.js +1 -1
- package/dist/extensions/lib/sync-extensions.js +1 -1
- package/dist/extensions/manager.js +1 -1
- package/dist/flows.js +4 -5
- package/dist/{logger.js → logger/index.js} +2 -8
- package/dist/logger/redact-query.d.ts +1 -0
- package/dist/logger/redact-query.js +13 -0
- package/dist/mailer.js +1 -1
- package/dist/middleware/authenticate.js +2 -7
- package/dist/middleware/cache.js +2 -2
- package/dist/middleware/error-handler.js +1 -1
- package/dist/middleware/rate-limiter-global.js +1 -1
- package/dist/middleware/respond.js +2 -2
- package/dist/operations/log/index.js +1 -1
- package/dist/operations/mail/index.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 +34 -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/request/is-denied-ip.js +1 -1
- package/dist/server.js +1 -1
- package/dist/services/access.d.ts +10 -0
- package/dist/services/access.js +43 -0
- package/dist/services/activity.js +23 -11
- package/dist/services/assets.d.ts +2 -3
- package/dist/services/assets.js +11 -6
- 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/utils/get-metadata.js +1 -1
- package/dist/services/files.js +25 -15
- 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/graphql/utils/process-error.js +1 -1
- package/dist/services/graphql/utils/sanitize-gql-schema.js +1 -1
- package/dist/services/import-export.js +19 -5
- package/dist/services/index.d.ts +3 -2
- package/dist/services/index.js +3 -2
- package/dist/services/items.d.ts +3 -3
- package/dist/services/items.js +115 -44
- package/dist/services/mail/index.js +1 -1
- package/dist/services/meta.js +60 -23
- package/dist/services/notifications.js +15 -7
- package/dist/services/payload.d.ts +9 -10
- package/dist/services/payload.js +18 -3
- 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 -12
- package/dist/services/roles.js +57 -424
- package/dist/services/server.js +1 -1
- package/dist/services/shares.d.ts +0 -2
- package/dist/services/shares.js +13 -9
- package/dist/services/specifications.d.ts +2 -2
- package/dist/services/specifications.js +39 -27
- package/dist/services/tus/data-store.js +3 -1
- package/dist/services/users.d.ts +1 -5
- package/dist/services/users.js +79 -162
- package/dist/services/utils.js +11 -7
- package/dist/services/versions.d.ts +0 -2
- package/dist/services/versions.js +34 -10
- package/dist/services/webhooks.js +1 -1
- package/dist/telemetry/lib/get-report.js +2 -2
- package/dist/telemetry/lib/track.js +1 -1
- package/dist/telemetry/utils/check-user-limits.d.ts +5 -0
- package/dist/telemetry/utils/check-user-limits.js +19 -0
- package/dist/types/ast.d.ts +43 -1
- package/dist/types/items.d.ts +11 -0
- package/dist/utils/apply-diff.js +1 -1
- package/dist/utils/apply-query.d.ts +4 -3
- package/dist/utils/apply-query.js +37 -8
- package/dist/utils/delete-from-require-cache.js +1 -1
- 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-default-value.js +1 -1
- package/dist/utils/get-ip-from-req.js +1 -1
- package/dist/utils/get-schema.js +1 -1
- package/dist/utils/get-service.js +5 -1
- package/dist/utils/is-url-allowed.js +1 -1
- package/dist/utils/reduce-schema.d.ts +4 -6
- package/dist/utils/reduce-schema.js +16 -32
- package/dist/utils/sanitize-query.js +1 -1
- package/dist/utils/transaction.js +1 -1
- package/dist/utils/validate-env.js +1 -1
- package/dist/utils/validate-storage.js +1 -1
- 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/base.d.ts +1 -1
- package/dist/websocket/controllers/base.js +21 -17
- package/dist/websocket/controllers/graphql.js +2 -5
- package/dist/websocket/controllers/hooks.js +4 -0
- package/dist/websocket/controllers/rest.js +1 -3
- package/dist/websocket/errors.js +1 -1
- package/dist/websocket/handlers/subscribe.js +0 -2
- package/dist/websocket/utils/items.d.ts +1 -1
- package/package.json +28 -27
- 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 -25
- 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
- /package/dist/{logger.d.ts → logger/index.d.ts} +0 -0
package/dist/services/roles.js
CHANGED
|
@@ -1,441 +1,51 @@
|
|
|
1
|
-
import { InvalidPayloadError
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { checkIncreasedUserLimits } from '../telemetry/utils/check-increased-user-limits.js';
|
|
5
|
-
import { getRoleCountsByUsers } from '../telemetry/utils/get-role-counts-by-users.js';
|
|
6
|
-
import {} from '../telemetry/utils/get-user-count.js';
|
|
7
|
-
import { getUserCountsByRoles } from '../telemetry/utils/get-user-counts-by-roles.js';
|
|
8
|
-
import { shouldCheckUserLimits } from '../telemetry/utils/should-check-user-limits.js';
|
|
9
|
-
import { shouldClearCache } from '../utils/should-clear-cache.js';
|
|
1
|
+
import { InvalidPayloadError } from '@directus/errors';
|
|
2
|
+
import { clearSystemCache } from '../cache.js';
|
|
3
|
+
import { fetchRolesTree } from '../permissions/lib/fetch-roles-tree.js';
|
|
10
4
|
import { transaction } from '../utils/transaction.js';
|
|
5
|
+
import { UserIntegrityCheckFlag } from '../utils/validate-user-count-integrity.js';
|
|
11
6
|
import { ItemsService } from './items.js';
|
|
12
|
-
import {
|
|
7
|
+
import { AccessService } from './access.js';
|
|
13
8
|
import { PresetsService } from './presets.js';
|
|
14
9
|
import { UsersService } from './users.js';
|
|
15
10
|
export class RolesService extends ItemsService {
|
|
16
11
|
constructor(options) {
|
|
17
12
|
super('directus_roles', options);
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const usersBefore = (await this.knex.select('id').from('directus_users').where('role', '=', key)).map((user) => user.id);
|
|
38
|
-
const usersAdded = [];
|
|
39
|
-
const usersUpdated = [];
|
|
40
|
-
const usersCreated = [];
|
|
41
|
-
const usersRemoved = [];
|
|
42
|
-
if (Array.isArray(users)) {
|
|
43
|
-
const usersKept = [];
|
|
44
|
-
for (const user of users) {
|
|
45
|
-
if (typeof user === 'string') {
|
|
46
|
-
if (usersBefore.includes(user)) {
|
|
47
|
-
usersKept.push(user);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
usersAdded.push({ id: user });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (user.id) {
|
|
54
|
-
if (usersBefore.includes(user.id)) {
|
|
55
|
-
usersKept.push(user.id);
|
|
56
|
-
usersUpdated.push(user);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
usersAdded.push(user);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
usersCreated.push(user);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
usersRemoved.push(...usersBefore.filter((user) => !usersKept.includes(user)));
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
for (const user of users.update) {
|
|
70
|
-
if (usersBefore.includes(user['id'])) {
|
|
71
|
-
usersUpdated.push(user);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
usersAdded.push(user);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
usersCreated.push(...users.create);
|
|
78
|
-
usersRemoved.push(...users.delete);
|
|
79
|
-
}
|
|
80
|
-
if (role.admin_access === false || role.admin_access === 0) {
|
|
81
|
-
// Admin users might have moved in from other role, thus becoming non-admin
|
|
82
|
-
if (usersAdded.length > 0) {
|
|
83
|
-
const otherAdminUsers = await this.knex
|
|
84
|
-
.count('*', { as: 'count' })
|
|
85
|
-
.from('directus_users')
|
|
86
|
-
.leftJoin('directus_roles', 'directus_users.role', 'directus_roles.id')
|
|
87
|
-
.whereNotIn('directus_users.id', usersAdded.map((user) => user.id))
|
|
88
|
-
.andWhere({ 'directus_roles.admin_access': true, status: 'active' })
|
|
89
|
-
.first();
|
|
90
|
-
const otherAdminUsersCount = Number(otherAdminUsers?.count ?? 0);
|
|
91
|
-
if (otherAdminUsersCount === 0) {
|
|
92
|
-
throw new UnprocessableContentError({ reason: `You can't remove the last admin user from the admin role` });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
// Only added or created new users
|
|
98
|
-
if (usersUpdated.length === 0 && usersRemoved.length === 0)
|
|
99
|
-
return;
|
|
100
|
-
// Active admin user(s) about to be created
|
|
101
|
-
if (usersCreated.some((user) => !('status' in user) || user.status === 'active'))
|
|
102
|
-
return;
|
|
103
|
-
const usersDeactivated = [...usersAdded, ...usersUpdated]
|
|
104
|
-
.filter((user) => 'status' in user && user.status !== 'active')
|
|
105
|
-
.map((user) => user.id);
|
|
106
|
-
const usersAddedNonDeactivated = usersAdded
|
|
107
|
-
.filter((user) => !usersDeactivated.includes(user.id))
|
|
108
|
-
.map((user) => user.id);
|
|
109
|
-
// Active user(s) about to become admin
|
|
110
|
-
if (usersAddedNonDeactivated.length > 0) {
|
|
111
|
-
const userCount = await this.knex
|
|
112
|
-
.count('*', { as: 'count' })
|
|
113
|
-
.from('directus_users')
|
|
114
|
-
.whereIn('id', usersAddedNonDeactivated)
|
|
115
|
-
.andWhere({ status: 'active' })
|
|
116
|
-
.first();
|
|
117
|
-
if (Number(userCount?.count ?? 0) > 0) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const otherAdminUsers = await this.knex
|
|
122
|
-
.count('*', { as: 'count' })
|
|
123
|
-
.from('directus_users')
|
|
124
|
-
.leftJoin('directus_roles', 'directus_users.role', 'directus_roles.id')
|
|
125
|
-
.whereNotIn('directus_users.id', [...usersDeactivated, ...usersRemoved])
|
|
126
|
-
.andWhere({ 'directus_roles.admin_access': true, status: 'active' })
|
|
127
|
-
.first();
|
|
128
|
-
const otherAdminUsersCount = Number(otherAdminUsers?.count ?? 0);
|
|
129
|
-
if (otherAdminUsersCount === 0) {
|
|
130
|
-
throw new UnprocessableContentError({ reason: `You can't remove the last admin user from the admin role` });
|
|
131
|
-
}
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
isIpAccessValid(value) {
|
|
135
|
-
if (value === undefined)
|
|
136
|
-
return false;
|
|
137
|
-
if (value === null)
|
|
138
|
-
return true;
|
|
139
|
-
if (Array.isArray(value) && value.length === 0)
|
|
140
|
-
return true;
|
|
141
|
-
for (const ip of value) {
|
|
142
|
-
if (typeof ip !== 'string' || ip.includes('*'))
|
|
143
|
-
return false;
|
|
144
|
-
try {
|
|
145
|
-
const match = getMatch(ip);
|
|
146
|
-
if (match.type == 'IPMask')
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
catch {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
assertValidIpAccess(partialItem) {
|
|
156
|
-
if ('ip_access' in partialItem && !this.isIpAccessValid(partialItem['ip_access'])) {
|
|
157
|
-
throw new InvalidPayloadError({
|
|
158
|
-
reason: 'IP Access contains an incorrect value. Valid values are: IP addresses, IP ranges and CIDR blocks',
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
getRoleAccessType(data) {
|
|
163
|
-
if ('admin_access' in data && data['admin_access'] === true) {
|
|
164
|
-
return 'admin';
|
|
165
|
-
}
|
|
166
|
-
else if (('app_access' in data && data['app_access'] === true) || 'app_access' in data === false) {
|
|
167
|
-
return 'app';
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
return 'api';
|
|
171
|
-
}
|
|
14
|
+
// No need to check user integrity in createOne, as the creation of a role itself does not influence the number of
|
|
15
|
+
// users, as the role of a user is actually updated in the UsersService on the user, which will make sure to
|
|
16
|
+
// initiate a user integrity check if necessary. Same goes for role nesting check as well as cache clearing.
|
|
17
|
+
async updateMany(keys, data, opts = {}) {
|
|
18
|
+
if ('parent' in data) {
|
|
19
|
+
// If the parent of a role changed we need to make a full integrity check.
|
|
20
|
+
// Anything related to policies will be checked in the AccessService, where the policies are attached to roles
|
|
21
|
+
opts.userIntegrityCheckFlags = UserIntegrityCheckFlag.All;
|
|
22
|
+
opts.onRequireUserIntegrityCheck?.(opts.userIntegrityCheckFlags);
|
|
23
|
+
await this.validateRoleNesting(keys, data['parent']);
|
|
24
|
+
}
|
|
25
|
+
const result = await super.updateMany(keys, data, opts);
|
|
26
|
+
// Only clear the permissions cache if the parent role has changed
|
|
27
|
+
// If anything policies related has changed, the cache will be cleared in the AccessService as well
|
|
28
|
+
if ('parent' in data) {
|
|
29
|
+
await this.clearCaches();
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
172
32
|
}
|
|
173
|
-
async
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const increasedCounts = {
|
|
177
|
-
admin: 0,
|
|
178
|
-
app: 0,
|
|
179
|
-
api: 0,
|
|
180
|
-
};
|
|
181
|
-
const existingIds = [];
|
|
182
|
-
if ('users' in data) {
|
|
183
|
-
const type = this.getRoleAccessType(data);
|
|
184
|
-
increasedCounts[type] += data['users'].length;
|
|
185
|
-
for (const user of data['users']) {
|
|
186
|
-
if (typeof user === 'string') {
|
|
187
|
-
existingIds.push(user);
|
|
188
|
-
}
|
|
189
|
-
else if (typeof user === 'object' && 'id' in user) {
|
|
190
|
-
existingIds.push(user['id']);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
await checkIncreasedUserLimits(this.knex, increasedCounts, existingIds);
|
|
195
|
-
}
|
|
196
|
-
return super.createOne(data, opts);
|
|
197
|
-
}
|
|
198
|
-
async createMany(data, opts) {
|
|
199
|
-
const needsUserLimitCheck = shouldCheckUserLimits();
|
|
200
|
-
const increasedCounts = {
|
|
201
|
-
admin: 0,
|
|
202
|
-
app: 0,
|
|
203
|
-
api: 0,
|
|
204
|
-
};
|
|
205
|
-
const existingIds = [];
|
|
206
|
-
for (const partialItem of data) {
|
|
207
|
-
this.assertValidIpAccess(partialItem);
|
|
208
|
-
if (needsUserLimitCheck && 'users' in partialItem) {
|
|
209
|
-
const type = this.getRoleAccessType(partialItem);
|
|
210
|
-
increasedCounts[type] += partialItem['users'].length;
|
|
211
|
-
for (const user of partialItem['users']) {
|
|
212
|
-
if (typeof user === 'string') {
|
|
213
|
-
existingIds.push(user);
|
|
214
|
-
}
|
|
215
|
-
else if (typeof user === 'object' && 'id' in user) {
|
|
216
|
-
existingIds.push(user['id']);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (needsUserLimitCheck) {
|
|
222
|
-
await checkIncreasedUserLimits(this.knex, increasedCounts, existingIds);
|
|
223
|
-
}
|
|
224
|
-
return super.createMany(data, opts);
|
|
225
|
-
}
|
|
226
|
-
async updateOne(key, data, opts) {
|
|
227
|
-
this.assertValidIpAccess(data);
|
|
228
|
-
try {
|
|
229
|
-
if ('users' in data) {
|
|
230
|
-
await this.checkForOtherAdminUsers(key, data['users']);
|
|
231
|
-
}
|
|
232
|
-
if (shouldCheckUserLimits()) {
|
|
233
|
-
const increasedCounts = {
|
|
234
|
-
admin: 0,
|
|
235
|
-
app: 0,
|
|
236
|
-
api: 0,
|
|
237
|
-
};
|
|
238
|
-
let increasedUsers = 0;
|
|
239
|
-
const existingIds = [];
|
|
240
|
-
let existingRole = await this.knex
|
|
241
|
-
.count('directus_users.id', { as: 'count' })
|
|
242
|
-
.select('directus_roles.admin_access', 'directus_roles.app_access')
|
|
243
|
-
.from('directus_users')
|
|
244
|
-
.where('directus_roles.id', '=', key)
|
|
245
|
-
.andWhere('directus_users.status', '=', 'active')
|
|
246
|
-
.leftJoin('directus_roles', 'directus_users.role', '=', 'directus_roles.id')
|
|
247
|
-
.groupBy('directus_roles.admin_access', 'directus_roles.app_access')
|
|
248
|
-
.first();
|
|
249
|
-
if (!existingRole) {
|
|
250
|
-
try {
|
|
251
|
-
const role = (await this.knex
|
|
252
|
-
.select('admin_access', 'app_access')
|
|
253
|
-
.from('directus_roles')
|
|
254
|
-
.where('id', '=', key)
|
|
255
|
-
.first()) ?? { admin_access: null, app_access: null };
|
|
256
|
-
existingRole = { count: 0, ...role };
|
|
257
|
-
}
|
|
258
|
-
catch {
|
|
259
|
-
existingRole = { count: 0, admin_access: null, app_access: null };
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if ('users' in data) {
|
|
263
|
-
const users = data['users'];
|
|
264
|
-
if (Array.isArray(users)) {
|
|
265
|
-
increasedUsers = users.length - Number(existingRole.count);
|
|
266
|
-
for (const user of users) {
|
|
267
|
-
if (typeof user === 'string') {
|
|
268
|
-
existingIds.push(user);
|
|
269
|
-
}
|
|
270
|
-
else if (typeof user === 'object' && 'id' in user) {
|
|
271
|
-
existingIds.push(user['id']);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
increasedUsers += users.create.length;
|
|
277
|
-
increasedUsers -= users.delete.length;
|
|
278
|
-
const userIds = [];
|
|
279
|
-
for (const user of users.update) {
|
|
280
|
-
if ('status' in user) {
|
|
281
|
-
// account for users being activated and deactivated
|
|
282
|
-
if (user['status'] === 'active') {
|
|
283
|
-
increasedUsers++;
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
increasedUsers--;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
userIds.push(user.id);
|
|
290
|
-
}
|
|
291
|
-
try {
|
|
292
|
-
const existingCounts = await getRoleCountsByUsers(this.knex, userIds);
|
|
293
|
-
if (existingRole.admin_access) {
|
|
294
|
-
increasedUsers += existingCounts.app + existingCounts.api;
|
|
295
|
-
}
|
|
296
|
-
else if (existingRole.app_access) {
|
|
297
|
-
increasedUsers += existingCounts.admin + existingCounts.api;
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
increasedUsers += existingCounts.admin + existingCounts.app;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
catch {
|
|
304
|
-
// ignore failed user call
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
let isAccessChanged = false;
|
|
309
|
-
let accessType = 'api';
|
|
310
|
-
if ('app_access' in data) {
|
|
311
|
-
if (data['app_access'] === true) {
|
|
312
|
-
accessType = 'app';
|
|
313
|
-
if (!existingRole.app_access)
|
|
314
|
-
isAccessChanged = true;
|
|
315
|
-
}
|
|
316
|
-
else if (existingRole.app_access) {
|
|
317
|
-
isAccessChanged = true;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
else if (existingRole.app_access) {
|
|
321
|
-
accessType = 'app';
|
|
322
|
-
}
|
|
323
|
-
if ('admin_access' in data) {
|
|
324
|
-
if (data['admin_access'] === true) {
|
|
325
|
-
accessType = 'admin';
|
|
326
|
-
if (!existingRole.admin_access)
|
|
327
|
-
isAccessChanged = true;
|
|
328
|
-
}
|
|
329
|
-
else if (existingRole.admin_access) {
|
|
330
|
-
isAccessChanged = true;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
else if (existingRole.admin_access) {
|
|
334
|
-
accessType = 'admin';
|
|
335
|
-
}
|
|
336
|
-
if (isAccessChanged) {
|
|
337
|
-
increasedCounts[accessType] += Number(existingRole.count);
|
|
338
|
-
}
|
|
339
|
-
increasedCounts[accessType] += increasedUsers;
|
|
340
|
-
await checkIncreasedUserLimits(this.knex, increasedCounts, existingIds);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
catch (err) {
|
|
344
|
-
(opts || (opts = {})).preMutationError = err;
|
|
345
|
-
}
|
|
346
|
-
return super.updateOne(key, data, opts);
|
|
347
|
-
}
|
|
348
|
-
async updateBatch(data, opts = {}) {
|
|
349
|
-
for (const partialItem of data) {
|
|
350
|
-
this.assertValidIpAccess(partialItem);
|
|
351
|
-
}
|
|
352
|
-
const primaryKeyField = this.schema.collections[this.collection].primary;
|
|
353
|
-
if (!opts.mutationTracker) {
|
|
354
|
-
opts.mutationTracker = this.createMutationTracker();
|
|
355
|
-
}
|
|
356
|
-
const keys = [];
|
|
357
|
-
try {
|
|
358
|
-
await transaction(this.knex, async (trx) => {
|
|
359
|
-
const service = new RolesService({
|
|
360
|
-
accountability: this.accountability,
|
|
361
|
-
knex: trx,
|
|
362
|
-
schema: this.schema,
|
|
363
|
-
});
|
|
364
|
-
for (const item of data) {
|
|
365
|
-
const combinedOpts = Object.assign({ autoPurgeCache: false }, opts);
|
|
366
|
-
keys.push(await service.updateOne(item[primaryKeyField], omit(item, primaryKeyField), combinedOpts));
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
finally {
|
|
371
|
-
if (shouldClearCache(this.cache, opts, this.collection)) {
|
|
372
|
-
await this.cache.clear();
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
return keys;
|
|
376
|
-
}
|
|
377
|
-
async updateMany(keys, data, opts) {
|
|
378
|
-
this.assertValidIpAccess(data);
|
|
379
|
-
try {
|
|
380
|
-
if ('admin_access' in data && data['admin_access'] === false) {
|
|
381
|
-
await this.checkForOtherAdminRoles(keys);
|
|
382
|
-
}
|
|
383
|
-
if (shouldCheckUserLimits() && ('admin_access' in data || 'app_access' in data)) {
|
|
384
|
-
const existingCounts = await getUserCountsByRoles(this.knex, keys);
|
|
385
|
-
const increasedCounts = {
|
|
386
|
-
admin: 0,
|
|
387
|
-
app: 0,
|
|
388
|
-
api: 0,
|
|
389
|
-
};
|
|
390
|
-
const type = this.getRoleAccessType(data);
|
|
391
|
-
for (const [existingType, existingCount] of Object.entries(existingCounts)) {
|
|
392
|
-
if (existingType === type)
|
|
393
|
-
continue;
|
|
394
|
-
increasedCounts[type] += existingCount;
|
|
395
|
-
}
|
|
396
|
-
await checkIncreasedUserLimits(this.knex, increasedCounts);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
catch (err) {
|
|
400
|
-
(opts || (opts = {})).preMutationError = err;
|
|
401
|
-
}
|
|
402
|
-
return super.updateMany(keys, data, opts);
|
|
403
|
-
}
|
|
404
|
-
async updateByQuery(query, data, opts) {
|
|
405
|
-
this.assertValidIpAccess(data);
|
|
406
|
-
return super.updateByQuery(query, data, opts);
|
|
407
|
-
}
|
|
408
|
-
async deleteMany(keys) {
|
|
409
|
-
const opts = {};
|
|
410
|
-
try {
|
|
411
|
-
await this.checkForOtherAdminRoles(keys);
|
|
412
|
-
}
|
|
413
|
-
catch (err) {
|
|
414
|
-
opts.preMutationError = err;
|
|
415
|
-
}
|
|
33
|
+
async deleteMany(keys, opts = {}) {
|
|
34
|
+
opts.userIntegrityCheckFlags = UserIntegrityCheckFlag.All;
|
|
35
|
+
opts.onRequireUserIntegrityCheck?.(opts.userIntegrityCheckFlags);
|
|
416
36
|
await transaction(this.knex, async (trx) => {
|
|
417
|
-
const
|
|
418
|
-
knex: trx,
|
|
419
|
-
accountability: this.accountability,
|
|
420
|
-
schema: this.schema,
|
|
421
|
-
});
|
|
422
|
-
const permissionsService = new PermissionsService({
|
|
37
|
+
const options = {
|
|
423
38
|
knex: trx,
|
|
424
39
|
accountability: this.accountability,
|
|
425
40
|
schema: this.schema,
|
|
426
|
-
}
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
const usersService = new UsersService({
|
|
433
|
-
knex: trx,
|
|
434
|
-
accountability: this.accountability,
|
|
435
|
-
schema: this.schema,
|
|
436
|
-
});
|
|
41
|
+
};
|
|
42
|
+
const itemsService = new ItemsService('directus_roles', options);
|
|
43
|
+
const rolesService = new RolesService(options);
|
|
44
|
+
const accessService = new AccessService(options);
|
|
45
|
+
const presetsService = new PresetsService(options);
|
|
46
|
+
const usersService = new UsersService(options);
|
|
437
47
|
// Delete permissions/presets for this role, suspend all remaining users in role
|
|
438
|
-
await
|
|
48
|
+
await accessService.deleteByQuery({
|
|
439
49
|
filter: { role: { _in: keys } },
|
|
440
50
|
}, { ...opts, bypassLimits: true });
|
|
441
51
|
await presetsService.deleteByQuery({
|
|
@@ -447,8 +57,31 @@ export class RolesService extends ItemsService {
|
|
|
447
57
|
status: 'suspended',
|
|
448
58
|
role: null,
|
|
449
59
|
}, { ...opts, bypassLimits: true });
|
|
60
|
+
// If the about to be deleted roles are the parent of other roles set those parents to null
|
|
61
|
+
// Use a newly created RolesService here that works within the current transaction
|
|
62
|
+
await rolesService.updateByQuery({
|
|
63
|
+
filter: { parent: { _in: keys } },
|
|
64
|
+
}, { parent: null });
|
|
450
65
|
await itemsService.deleteMany(keys, opts);
|
|
451
66
|
});
|
|
67
|
+
// Since nested roles could be updated, clear caches
|
|
68
|
+
await this.clearCaches();
|
|
452
69
|
return keys;
|
|
453
70
|
}
|
|
71
|
+
async validateRoleNesting(ids, parent) {
|
|
72
|
+
if (ids.includes(parent)) {
|
|
73
|
+
throw new InvalidPayloadError({ reason: 'A role cannot be a parent of itself' });
|
|
74
|
+
}
|
|
75
|
+
const roles = await fetchRolesTree(parent, this.knex);
|
|
76
|
+
if (ids.some((id) => roles.includes(id))) {
|
|
77
|
+
// The role tree up from the parent already includes this role, so it would create a circular reference
|
|
78
|
+
throw new InvalidPayloadError({ reason: 'A role cannot have a parent that is already a descendant of itself' });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async clearCaches(opts) {
|
|
82
|
+
await clearSystemCache({ autoPurgeCache: opts?.autoPurgeCache });
|
|
83
|
+
if (this.cache && opts?.autoPurgeCache !== false) {
|
|
84
|
+
await this.cache.clear();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
454
87
|
}
|
package/dist/services/server.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Readable } from 'node:stream';
|
|
|
6
6
|
import { performance } from 'perf_hooks';
|
|
7
7
|
import { getCache } from '../cache.js';
|
|
8
8
|
import getDatabase, { hasDatabaseConnection } from '../database/index.js';
|
|
9
|
-
import { useLogger } from '../logger.js';
|
|
9
|
+
import { useLogger } from '../logger/index.js';
|
|
10
10
|
import getMailer from '../mailer.js';
|
|
11
11
|
import { rateLimiterGlobal } from '../middleware/rate-limiter-global.js';
|
|
12
12
|
import { rateLimiter } from '../middleware/rate-limiter-ip.js';
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Item, PrimaryKey } from '@directus/types';
|
|
2
2
|
import type { AbstractServiceOptions, LoginResult, MutationOptions } from '../types/index.js';
|
|
3
|
-
import { AuthorizationService } from './authorization.js';
|
|
4
3
|
import { ItemsService } from './items.js';
|
|
5
4
|
export declare class SharesService extends ItemsService {
|
|
6
|
-
authorizationService: AuthorizationService;
|
|
7
5
|
constructor(options: AbstractServiceOptions);
|
|
8
6
|
createOne(data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey>;
|
|
9
7
|
login(payload: Record<string, any>, options?: Partial<{
|
package/dist/services/shares.js
CHANGED
|
@@ -2,30 +2,34 @@ import { useEnv } from '@directus/env';
|
|
|
2
2
|
import { ForbiddenError, InvalidCredentialsError } from '@directus/errors';
|
|
3
3
|
import argon2 from 'argon2';
|
|
4
4
|
import jwt from 'jsonwebtoken';
|
|
5
|
-
import { useLogger } from '../logger.js';
|
|
5
|
+
import { useLogger } from '../logger/index.js';
|
|
6
|
+
import { validateAccess } from '../permissions/modules/validate-access/validate-access.js';
|
|
6
7
|
import { getMilliseconds } from '../utils/get-milliseconds.js';
|
|
7
8
|
import { getSecret } from '../utils/get-secret.js';
|
|
8
9
|
import { md } from '../utils/md.js';
|
|
9
10
|
import { Url } from '../utils/url.js';
|
|
10
11
|
import { userName } from '../utils/user-name.js';
|
|
11
|
-
import { AuthorizationService } from './authorization.js';
|
|
12
12
|
import { ItemsService } from './items.js';
|
|
13
13
|
import { MailService } from './mail/index.js';
|
|
14
14
|
import { UsersService } from './users.js';
|
|
15
15
|
const env = useEnv();
|
|
16
16
|
const logger = useLogger();
|
|
17
17
|
export class SharesService extends ItemsService {
|
|
18
|
-
authorizationService;
|
|
19
18
|
constructor(options) {
|
|
20
19
|
super('directus_shares', options);
|
|
21
|
-
this.authorizationService = new AuthorizationService({
|
|
22
|
-
accountability: this.accountability,
|
|
23
|
-
knex: this.knex,
|
|
24
|
-
schema: this.schema,
|
|
25
|
-
});
|
|
26
20
|
}
|
|
27
21
|
async createOne(data, opts) {
|
|
28
|
-
|
|
22
|
+
if (this.accountability) {
|
|
23
|
+
await validateAccess({
|
|
24
|
+
accountability: this.accountability,
|
|
25
|
+
action: 'share',
|
|
26
|
+
collection: data['collection'],
|
|
27
|
+
primaryKeys: [data['item']],
|
|
28
|
+
}, {
|
|
29
|
+
schema: this.schema,
|
|
30
|
+
knex: this.knex,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
29
33
|
return super.createOne(data, opts);
|
|
30
34
|
}
|
|
31
35
|
async login(payload, options) {
|
|
@@ -9,7 +9,7 @@ export declare class SpecificationService {
|
|
|
9
9
|
schema: SchemaOverview;
|
|
10
10
|
oas: OASSpecsService;
|
|
11
11
|
graphql: GraphQLSpecsService;
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(options: AbstractServiceOptions);
|
|
13
13
|
}
|
|
14
14
|
interface SpecificationSubService {
|
|
15
15
|
generate: (_?: any) => Promise<any>;
|
|
@@ -18,7 +18,7 @@ declare class OASSpecsService implements SpecificationSubService {
|
|
|
18
18
|
accountability: Accountability | null;
|
|
19
19
|
knex: Knex;
|
|
20
20
|
schema: SchemaOverview;
|
|
21
|
-
constructor(
|
|
21
|
+
constructor(options: AbstractServiceOptions);
|
|
22
22
|
generate(host?: string): Promise<OpenAPIObject>;
|
|
23
23
|
private generateTags;
|
|
24
24
|
private generatePaths;
|