fix(db): through scope in eager loading & fix(acl): filter reset issue (#3636)

* fix(database): through scope in eager loading

* chore: update

* fix: role users filter

* chore: update
This commit is contained in:
YANG QIA 2024-03-07 13:38:17 +08:00 committed by GitHub
parent 30b4ed77a1
commit 263ee28c72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 139 additions and 15 deletions

View File

@ -14,3 +14,4 @@ AssociationField.AddNewer = Action.Container;
AssociationField.Selector = Action.Container;
AssociationField.Viewer = Action.Container;
AssociationField.InternalSelect = InternalPicker;
AssociationField.ReadPretty = ReadPretty;

View File

@ -1,5 +1,5 @@
import lodash from 'lodash';
import { Association, HasOne, Includeable, Model, ModelStatic, Op, Transaction } from 'sequelize';
import { Association, HasOne, HasOneOptions, Includeable, Model, ModelStatic, Op, Transaction } from 'sequelize';
import Database from '../database';
import { appendChildCollectionNameAfterRepositoryFind } from '../listeners/append-child-collection-name-after-repository-find';
import { OptionsParser } from '../options-parser';
@ -337,11 +337,15 @@ export class EagerLoadingTree {
if (associationType == 'BelongsToMany') {
const foreignKeyValues = node.parent.instances.map((instance) => instance.get(association.sourceKey));
const pivotAssoc = new HasOne(association.target, association.through.model, {
const hasOneOptions: HasOneOptions = {
as: '_pivot_',
foreignKey: association.otherKey,
sourceKey: association.targetKey,
});
};
if (association.through.scope) {
hasOneOptions.scope = association.through.scope;
}
const pivotAssoc = new HasOne(association.target, association.through.model, hasOneOptions);
instances = await node.model.findAll({
transaction,

View File

@ -30,6 +30,7 @@ export const PasswordField: React.FC = () => {
}}
value={field.value}
onChange={(e: any) => field.setValue(e.target.value)}
autoComplete="off"
/>
</Col>
<Col span={4}>

View File

@ -1,4 +1,4 @@
import React, { useContext, useRef } from 'react';
import React, { useContext, useEffect, useMemo, useRef } from 'react';
import { App } from 'antd';
import {
CollectionProvider_deprecated,
@ -13,7 +13,7 @@ import {
} from '@nocobase/client';
import { RolesManagerContext } from '@nocobase/plugin-acl/client';
import { useUsersTranslation } from './locale';
import { roleUsersSchema, userCollection } from './schemas/users';
import { getRoleUsersSchema, userCollection } from './schemas/users';
import { useFilterActionProps } from './hooks';
const useRemoveUser = () => {
@ -83,9 +83,12 @@ export const RoleUsersManager: React.FC = () => {
},
{
ready: !!role,
refreshDeps: [role],
},
);
useEffect(() => {
service.run();
}, [role]);
const selectedRoleUsers = useRef([]);
const handleSelectRoleUsers = (_: number[], rows: any[]) => {
selectedRoleUsers.current = rows;
@ -106,11 +109,13 @@ export const RoleUsersManager: React.FC = () => {
};
};
const schema = useMemo(() => getRoleUsersSchema(), [role]);
return (
<ResourceActionContext.Provider value={{ ...service }}>
<CollectionProvider_deprecated collection={userCollection}>
<SchemaComponent
schema={roleUsersSchema}
schema={schema}
components={{ RoleUsersProvider }}
scope={{
useBulkRemoveUsers,

View File

@ -1,6 +1,7 @@
import { ISchema } from '@formily/react';
import { useActionContext, useCollectionRecord, useRecord, useRequest } from '@nocobase/client';
import { useEffect } from 'react';
import { uid } from '@formily/shared';
export const userCollection = {
name: 'users',
@ -475,7 +476,7 @@ export const usersSchema: ISchema = {
},
};
export const roleUsersSchema: ISchema = {
export const getRoleUsersSchema = (): ISchema => ({
type: 'void',
properties: {
actions: {
@ -487,7 +488,7 @@ export const roleUsersSchema: ISchema = {
},
},
properties: {
filter: {
[uid()]: {
type: 'void',
title: '{{ t("Filter") }}',
'x-action': 'filter',
@ -724,4 +725,4 @@ export const roleUsersSchema: ISchema = {
},
},
},
};
});

122
yarn.lock
View File

@ -4251,6 +4251,11 @@
dependencies:
eslint-scope "5.1.1"
"@nocobase/plugin-workflow-test@>= 0.19.0-alpha.3":
version "0.19.0-alpha.9"
resolved "https://registry.npmjs.org/@nocobase/plugin-workflow-test/-/plugin-workflow-test-0.19.0-alpha.9.tgz#c074e8b3389f4d856bcbdba6c34756b386973f2b"
integrity sha512-jiNdq7hZzlivXv73rMdM+zZtxShsILcX+Fx0kOmopamXvTPCbAfjtMoqUndwpHGkhGomGzWfIwvuSXa3D0NRCA==
"@node-saml/node-saml@^4.0.2":
version "4.0.5"
resolved "https://registry.npmmirror.com/@node-saml/node-saml/-/node-saml-4.0.5.tgz#039e387095b54639b06df62b1b4a6d8941c6d907"
@ -4507,6 +4512,15 @@
dependencies:
"@opentelemetry/semantic-conventions" "1.19.0"
"@opentelemetry/exporter-prometheus@^0.46.0":
version "0.46.0"
resolved "https://registry.npmjs.org/@opentelemetry/exporter-prometheus/-/exporter-prometheus-0.46.0.tgz#c411a1e8a5266f9f3ddc44a088a538c3c1ee4830"
integrity sha512-AXcoCHG31K2PLGizlJJWcfQqZsGfUZkT7ik6C8VJu7U2Cenk0Xhvd3rO+vVNSSjP1+LHkP4MQtqEXpIZttw5cw==
dependencies:
"@opentelemetry/core" "1.19.0"
"@opentelemetry/resources" "1.19.0"
"@opentelemetry/sdk-metrics" "1.19.0"
"@opentelemetry/instrumentation@^0.46.0":
version "0.46.0"
resolved "https://registry.npmjs.org/@opentelemetry/instrumentation/-/instrumentation-0.46.0.tgz#a8a252306f82e2eace489312798592a14eb9830e"
@ -4540,7 +4554,7 @@
"@opentelemetry/core" "1.19.0"
"@opentelemetry/semantic-conventions" "1.19.0"
"@opentelemetry/sdk-metrics@^1.19.0":
"@opentelemetry/sdk-metrics@1.19.0", "@opentelemetry/sdk-metrics@^1.19.0":
version "1.19.0"
resolved "https://registry.npmjs.org/@opentelemetry/sdk-metrics/-/sdk-metrics-1.19.0.tgz#fe8029af29402563eb8dba75a85fc02006ea92c4"
integrity sha512-FiMii40zr0Fmys4F1i8gmuCvbinBnBsDeGBr4FQemOf0iPCLytYQm5AZJ/nn4xSc71IgKBQwTFQRAGJI7JvZ4Q==
@ -6430,6 +6444,15 @@
dependencies:
"@types/express" "*"
"@types/pg@^8.10.9":
version "8.11.2"
resolved "https://registry.npmjs.org/@types/pg/-/pg-8.11.2.tgz#e5c306601d2e0cc54c0801cc61a41761c8a95c92"
integrity sha512-G2Mjygf2jFMU/9hCaTYxJrwdObdcnuQde1gndooZSOHsNSaCehAuwc7EIuSA34Do8Jx2yZ19KtvW8P0j4EuUXw==
dependencies:
"@types/node" "*"
pg-protocol "*"
pg-types "^4.0.1"
"@types/picomatch@*":
version "2.3.3"
resolved "https://registry.npmmirror.com/@types/picomatch/-/picomatch-2.3.3.tgz#be60498568c19e989e43fb39aa84be1ed3655e92"
@ -8569,7 +8592,7 @@ bessel@^1.0.2:
resolved "https://registry.npmmirror.com/bessel/-/bessel-1.0.2.tgz#828812291e0b62e94959cdea43fac186e8a7202d"
integrity sha512-Al3nHGQGqDYqqinXhQzmwmcRToe/3WyBv4N8aZc5Pef8xw2neZlR9VPi84Sa23JtgWcucu18HxVZrnI0fn2etw==
big-integer@^1.6.44:
big-integer@^1.6.44, big-integer@^1.6.48:
version "1.6.52"
resolved "https://registry.npmmirror.com/big-integer/-/big-integer-1.6.52.tgz#60a887f3047614a8e1bffe5d7173490a97dc8c85"
integrity sha512-QxD8cf2eVqJOOz63z6JIN9BzvVs/dlySa5HGSBH5xtR8dPteIRQnBxxKqkNTiT6jbDTF6jAfrd4oMcND9RGbQg==
@ -15916,6 +15939,11 @@ jest-worker@^29.7.0:
merge-stream "^2.0.0"
supports-color "^8.0.0"
jmespath@^0.16.0:
version "0.16.0"
resolved "https://registry.npmjs.org/jmespath/-/jmespath-0.16.0.tgz#b15b0a85dfd4d930d43e69ed605943c802785076"
integrity sha512-9FzQjJ7MATs1tSpnco1K6ayiYE3figslrXA72G2HQ/n76RzvYlofyi5QM+iX4YRs/pu3yzxlVQSST23+dMDknw==
jose@^4.15.1:
version "4.15.4"
resolved "https://registry.npmmirror.com/jose/-/jose-4.15.4.tgz#02a9a763803e3872cf55f29ecef0dfdcc218cc03"
@ -16105,6 +16133,11 @@ json5@^2.1.2, json5@^2.2.2, json5@^2.2.3:
resolved "https://registry.npmmirror.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==
jsonata@^2.0.3:
version "2.0.4"
resolved "https://registry.npmjs.org/jsonata/-/jsonata-2.0.4.tgz#d8575d4c7695a2086162a2baebce0f0ee4e84fdb"
integrity sha512-vfavX4/G/yrYxE+UrmT/oUJ3ph7KqUrb0R7b0LVRcntQwxw+Z5kA1pNUIQzX5hF04Oe1eKxyoIPsmXtc2LgJTQ==
jsonc-parser@^3.2.0:
version "3.2.0"
resolved "https://registry.npmmirror.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76"
@ -16138,6 +16171,11 @@ jsonparse@^1.2.0, jsonparse@^1.3.1:
resolved "https://registry.npmmirror.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280"
integrity sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==
jsonpath-plus@^7.2.0:
version "7.2.0"
resolved "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-7.2.0.tgz#7ad94e147b3ed42f7939c315d2b9ce490c5a3899"
integrity sha512-zBfiUPM5nD0YZSBT/o/fbCUlCcepMIdP0CJZxM1+KgA4f2T206f6VAg9e7mX35+KlMaIc5qXW34f3BnwJ3w+RA==
jsonwebtoken@^8.5.1:
version "8.5.1"
resolved "https://registry.npmmirror.com/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d"
@ -18570,6 +18608,13 @@ node-releases@^2.0.14:
resolved "https://registry.npmmirror.com/node-releases/-/node-releases-2.0.14.tgz#2ffb053bceb8b2be8495ece1ab6ce600c4461b0b"
integrity sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==
node-sql-parser@^4.11.0:
version "4.18.0"
resolved "https://registry.npmjs.org/node-sql-parser/-/node-sql-parser-4.18.0.tgz#516b6e633c55c5abbba1ca588ab372db81ae9318"
integrity sha512-2YEOR5qlI1zUFbGMLKNfsrR5JUvFg9LxIRVE+xJe962pfVLH0rnItqLzv96XVs1Y1UIR8FxsXAuvX/lYAWZ2BQ==
dependencies:
big-integer "^1.6.48"
node-xlsx@^0.16.1:
version "0.16.2"
resolved "https://registry.npmmirror.com/node-xlsx/-/node-xlsx-0.16.2.tgz#40f580187eae0e032cac96e958e97cb6ceca09f6"
@ -19033,7 +19078,7 @@ object.values@^1.1.6, object.values@^1.1.7:
define-properties "^1.2.0"
es-abstract "^1.22.1"
obuf@^1.0.0, obuf@^1.1.2:
obuf@^1.0.0, obuf@^1.1.2, obuf@~1.1.2:
version "1.1.2"
resolved "https://registry.npmmirror.com/obuf/-/obuf-1.1.2.tgz#09bea3343d41859ebd446292d11c9d4db619084e"
integrity sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==
@ -19862,12 +19907,17 @@ pg-int8@1.0.1:
resolved "https://registry.npmmirror.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"
integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==
pg-numeric@1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/pg-numeric/-/pg-numeric-1.0.2.tgz#816d9a44026086ae8ae74839acd6a09b0636aa3a"
integrity sha512-BM/Thnrw5jm2kKLE5uJkXqqExRUY/toLHda65XgFTBTFYZyopbKjBe29Ii3RbkvlsMoFwD+tHeGaCjjv0gHlyw==
pg-pool@^3.6.1:
version "3.6.1"
resolved "https://registry.npmmirror.com/pg-pool/-/pg-pool-3.6.1.tgz#5a902eda79a8d7e3c928b77abf776b3cb7d351f7"
integrity sha512-jizsIzhkIitxCGfPRzJn1ZdcosIt3pz9Sh3V01fm1vZnbnCMgmGl5wvGGdNN2EL9Rmb0EcFoCkixH4Pu+sP9Og==
pg-protocol@^1.6.0:
pg-protocol@*, pg-protocol@^1.6.0:
version "1.6.0"
resolved "https://registry.npmmirror.com/pg-protocol/-/pg-protocol-1.6.0.tgz#4c91613c0315349363af2084608db843502f8833"
integrity sha512-M+PDm637OY5WM307051+bsDia5Xej6d9IR4GwJse1qA1DIhiKlksvrneZOYQq42OM+spubpcNYEo2FcKQrDk+Q==
@ -19883,7 +19933,20 @@ pg-types@^2.1.0:
postgres-date "~1.0.4"
postgres-interval "^1.1.0"
pg@^8.7.3:
pg-types@^4.0.1:
version "4.0.2"
resolved "https://registry.npmjs.org/pg-types/-/pg-types-4.0.2.tgz#399209a57c326f162461faa870145bb0f918b76d"
integrity sha512-cRL3JpS3lKMGsKaWndugWQoLOCoP+Cic8oseVcbr0qhPzYD5DWXK+RZ9LY9wxRf7RQia4SCwQlXk0q6FCPrVng==
dependencies:
pg-int8 "1.0.1"
pg-numeric "1.0.2"
postgres-array "~3.0.1"
postgres-bytea "~3.0.0"
postgres-date "~2.1.0"
postgres-interval "^3.0.0"
postgres-range "^1.1.1"
pg@^8.11.3, pg@^8.7.3:
version "8.11.3"
resolved "https://registry.npmmirror.com/pg/-/pg-8.11.3.tgz#d7db6e3fe268fcedd65b8e4599cda0b8b4bf76cb"
integrity sha512-+9iuvG8QfaaUrrph+kpF24cXkH1YOOUeArRNYIxq1viYHZagBxrTno7cecY1Fa44tJeZvaoG+Djpkc3JwehN5g==
@ -20481,16 +20544,33 @@ postgres-array@~2.0.0:
resolved "https://registry.npmmirror.com/postgres-array/-/postgres-array-2.0.0.tgz#48f8fce054fbc69671999329b8834b772652d82e"
integrity sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==
postgres-array@~3.0.1:
version "3.0.2"
resolved "https://registry.npmjs.org/postgres-array/-/postgres-array-3.0.2.tgz#68d6182cb0f7f152a7e60dc6a6889ed74b0a5f98"
integrity sha512-6faShkdFugNQCLwucjPcY5ARoW1SlbnrZjmGl0IrrqewpvxvhSLHimCVzqeuULCbG0fQv7Dtk1yDbG3xv7Veog==
postgres-bytea@~1.0.0:
version "1.0.0"
resolved "https://registry.npmmirror.com/postgres-bytea/-/postgres-bytea-1.0.0.tgz#027b533c0aa890e26d172d47cf9ccecc521acd35"
integrity sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==
postgres-bytea@~3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-3.0.0.tgz#9048dc461ac7ba70a6a42d109221619ecd1cb089"
integrity sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==
dependencies:
obuf "~1.1.2"
postgres-date@~1.0.4:
version "1.0.7"
resolved "https://registry.npmmirror.com/postgres-date/-/postgres-date-1.0.7.tgz#51bc086006005e5061c591cee727f2531bf641a8"
integrity sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==
postgres-date@~2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/postgres-date/-/postgres-date-2.1.0.tgz#b85d3c1fb6fb3c6c8db1e9942a13a3bf625189d0"
integrity sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==
postgres-interval@^1.1.0:
version "1.2.0"
resolved "https://registry.npmmirror.com/postgres-interval/-/postgres-interval-1.2.0.tgz#b460c82cb1587507788819a06aa0fffdb3544695"
@ -20498,6 +20578,16 @@ postgres-interval@^1.1.0:
dependencies:
xtend "^4.0.0"
postgres-interval@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/postgres-interval/-/postgres-interval-3.0.0.tgz#baf7a8b3ebab19b7f38f07566c7aab0962f0c86a"
integrity sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==
postgres-range@^1.1.1:
version "1.1.4"
resolved "https://registry.npmjs.org/postgres-range/-/postgres-range-1.1.4.tgz#a59c5f9520909bcec5e63e8cf913a92e4c952863"
integrity sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==
prelude-ls@^1.2.1:
version "1.2.1"
resolved "https://registry.npmmirror.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
@ -22766,6 +22856,28 @@ sequelize@^6.26.0:
validator "^13.9.0"
wkx "^0.5.0"
sequelize@^6.35.0:
version "6.37.1"
resolved "https://registry.npmjs.org/sequelize/-/sequelize-6.37.1.tgz#9380fe0a3b5ff17638d3fce30c3cf3a2396c2343"
integrity sha512-vIKKzQ9dGp2aBOxQRD1FmUYViuQiKXSJ8yah8TsaBx4U3BokJt+Y2A0qz2C4pj08uX59qpWxRqSLEfRmVOEgQw==
dependencies:
"@types/debug" "^4.1.8"
"@types/validator" "^13.7.17"
debug "^4.3.4"
dottie "^2.0.6"
inflection "^1.13.4"
lodash "^4.17.21"
moment "^2.29.4"
moment-timezone "^0.5.43"
pg-connection-string "^2.6.1"
retry-as-promised "^7.0.4"
semver "^7.5.4"
sequelize-pool "^7.1.0"
toposort-class "^1.0.1"
uuid "^8.3.2"
validator "^13.9.0"
wkx "^0.5.0"
serve-handler@6.1.3:
version "6.1.3"
resolved "https://registry.npmmirror.com/serve-handler/-/serve-handler-6.1.3.tgz#1bf8c5ae138712af55c758477533b9117f6435e8"