-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugin-multi-tenant): selected tenant could become incorrect when…
… navigating out of doc (#10723) ### What? When switching tenants from within a document and then navigating back out to the list view, the tenant would not be set correctly. ### Why? This was because we handle the tenant selector selection differently when viewing a document. ### How? Now when you navigate out, the page will refresh the cookie. Also adds test suite config that shows how the dom can be used to manipulate styles per tenant.
- Loading branch information
1 parent
c1b912d
commit e6d0260
Showing
14 changed files
with
145 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
test/plugin-multi-tenant/collections/Users/filterOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { FilterOptions, Where } from 'payload' | ||
|
||
import { getTenantFromCookie } from '@payloadcms/plugin-multi-tenant/utilities' | ||
|
||
export const userFilterOptions: FilterOptions = ({ req }) => { | ||
const selectedTenant = getTenantFromCookie(req.headers, req.payload.db.defaultIDType) | ||
if (!selectedTenant) { | ||
return false | ||
} | ||
|
||
return { | ||
or: [ | ||
{ | ||
'tenants.tenant': { | ||
equals: selectedTenant, | ||
}, | ||
}, | ||
{ | ||
roles: { | ||
in: ['admin'], | ||
}, | ||
}, | ||
], | ||
} as Where | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { CollectionConfig } from 'payload' | ||
|
||
import { usersSlug } from '../../shared.js' | ||
|
||
export const Users: CollectionConfig = { | ||
slug: usersSlug, | ||
auth: true, | ||
admin: { | ||
useAsTitle: 'email', | ||
}, | ||
access: { | ||
read: () => true, | ||
}, | ||
fields: [ | ||
// Email added by default | ||
// Add more fields as needed | ||
{ | ||
type: 'select', | ||
name: 'roles', | ||
hasMany: true, | ||
options: [ | ||
{ | ||
label: 'Admin', | ||
value: 'admin', | ||
}, | ||
{ | ||
label: 'User', | ||
value: 'user', | ||
}, | ||
], | ||
saveToJWT: true, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import './styles.css' | ||
|
||
export function Icon() { | ||
return <div id="tenant-icon" /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#tenant-icon { | ||
border-radius: 100%; | ||
height: 18px; | ||
width: 18px; | ||
} | ||
|
||
[data-selected-tenant-title="Blue Dog"] #tenant-icon { | ||
background-color: var(--theme-success-300); | ||
} | ||
|
||
[data-selected-tenant-title="Steel Cat"] #tenant-icon { | ||
background-color: var(--theme-warning-300); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import './styles.css' | ||
|
||
export function Logo() { | ||
return <div id="tenant-logo" /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#tenant-logo { | ||
border-radius: 100%; | ||
height: 18px; | ||
width: 18px; | ||
} | ||
|
||
[data-selected-tenant-title="Blue Dog"] #tenant-logo { | ||
background-color: var(--theme-success-300); | ||
} | ||
|
||
[data-selected-tenant-title="Steel Cat"] #tenant-logo { | ||
background-color: var(--theme-warning-300); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters