Skip to content

Commit a422a0d

Browse files
fix: scopes preferences queries and mutations by user (#7534)
Fixes #7530 Properly scopes preferences queries/mutations by user.
1 parent edaeb1e commit a422a0d

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

packages/next/src/views/List/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,23 @@ export const ListView: React.FC<AdminViewProps> = async ({
5757
req,
5858
user,
5959
where: {
60-
key: {
61-
equals: preferenceKey,
62-
},
60+
and: [
61+
{
62+
key: {
63+
equals: preferenceKey,
64+
},
65+
},
66+
{
67+
'user.relationTo': {
68+
equals: user.collection,
69+
},
70+
},
71+
{
72+
'user.value': {
73+
equals: user?.id,
74+
},
75+
},
76+
],
6377
},
6478
})
6579
?.then((res) => res?.docs?.[0]?.value)) as ListPreferences

packages/ui/src/utilities/buildFormState.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,23 @@ export const buildFormState = async ({ req }: { req: PayloadRequest }): Promise<
115115
depth: 0,
116116
limit: 1,
117117
where: {
118-
key: {
119-
equals: preferencesKey,
120-
},
118+
and: [
119+
{
120+
key: {
121+
equals: preferencesKey,
122+
},
123+
},
124+
{
125+
'user.relationTo': {
126+
equals: req.user.collection,
127+
},
128+
},
129+
{
130+
'user.value': {
131+
equals: req.user.id,
132+
},
133+
},
134+
],
121135
},
122136
})) as unknown as { docs: { value: DocumentPreferences }[] }
123137

test/auth/int.spec.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,21 @@ describe('Auth', () => {
367367
collection: 'payload-preferences',
368368
depth: 0,
369369
where: {
370-
key: { equals: key },
370+
and: [
371+
{
372+
key: { equals: key },
373+
},
374+
{
375+
'user.relationTo': {
376+
equals: 'users',
377+
},
378+
},
379+
{
380+
'user.value': {
381+
equals: loggedInUser.id,
382+
},
383+
},
384+
],
371385
},
372386
})
373387

@@ -390,7 +404,21 @@ describe('Auth', () => {
390404
collection: 'payload-preferences',
391405
depth: 0,
392406
where: {
393-
key: { equals: key },
407+
and: [
408+
{
409+
key: { equals: key },
410+
},
411+
{
412+
'user.relationTo': {
413+
equals: 'users',
414+
},
415+
},
416+
{
417+
'user.value': {
418+
equals: loggedInUser.id,
419+
},
420+
},
421+
],
394422
},
395423
})
396424

0 commit comments

Comments
 (0)