Compare commits

...

4 Commits

Author SHA1 Message Date
Jarrod Flesch
fa3439e89e Revert "fix: allow initialState replacement without losing focus"
This reverts commit 967b071caa.
2025-01-30 15:39:57 -05:00
Jarrod Flesch
d847da9ed4 feat: allow users to opt out of default tenant access control merge 2025-01-30 08:39:22 -05:00
Jarrod Flesch
967b071caa fix: allow initialState replacement without losing focus 2025-01-28 09:50:28 -05:00
Jarrod Flesch
30a501ccd6 fix: set initialValues alongside values during onSuccess 2025-01-27 09:58:58 -05:00
4 changed files with 34 additions and 11 deletions

View File

@@ -25,6 +25,18 @@ This plugin sets up multi-tenancy for your application from within your [Admin P
- Adds a `tenant` field to each specified collection
- Adds a tenant selector to the admin panel, allowing you to switch between tenants
- Filters list view results by selected tenant
- Filters relationship fields by selected tenant
- Ability to create "global" like collections, 1 doc per tenant
- Automatically assign a tenant to new documents
<Banner type="error">
**Warning**
By default this plugin cleans up documents when a tenant is deleted. You should ensure you have
strong access control on your tenants collection to prevent deletions by unauthorized users.
You can disabled this behavior by setting `cleanupAfterTenantDelete` to `false` in the plugin options.
</Banner>
## Installation
@@ -40,7 +52,7 @@ The plugin accepts an object with the following properties:
```ts
type MultiTenantPluginConfig<ConfigTypes = unknown> = {
/**
/**
* After a tenant is deleted, the plugin will attempt to clean up related documents
* - removing documents with the tenant ID
* - removing the tenant from users
@@ -144,8 +156,12 @@ type MultiTenantPluginConfig<ConfigTypes = unknown> = {
* Useful for super-admin type users
*/
userHasAccessToAllTenants?: (
user: ConfigTypes extends { user } ? ConfigTypes['user'] : User,
user: ConfigTypes extends { user: unknown } ? ConfigTypes['user'] : User,
) => boolean
/**
* Opt out of adding access constraints to the tenants collection
*/
useTenantsCollectionAccess?: boolean
}
```

View File

@@ -116,15 +116,17 @@ export const multiTenantPlugin =
if (collection.slug === tenantsCollectionSlug) {
tenantCollection = collection
/**
* Add access control constraint to tenants collection
* - constrains access a users assigned tenants
*/
addCollectionAccess({
collection,
fieldName: 'id',
userHasAccessToAllTenants,
})
if (pluginConfig.useTenantsCollectionAccess !== false) {
/**
* Add access control constraint to tenants collection
* - constrains access a users assigned tenants
*/
addCollectionAccess({
collection,
fieldName: 'id',
userHasAccessToAllTenants,
})
}
if (pluginConfig.cleanupAfterTenantDelete !== false) {
/**

View File

@@ -107,6 +107,10 @@ export type MultiTenantPluginConfig<ConfigTypes = unknown> = {
userHasAccessToAllTenants?: (
user: ConfigTypes extends { user: unknown } ? ConfigTypes['user'] : User,
) => boolean
/**
* Opt out of adding access constraints to the tenants collection
*/
useTenantsCollectionAccess?: boolean
}
export type Tenant<IDType = number | string> = {

View File

@@ -33,6 +33,7 @@ export const mergeServerFormState = ({
if (acceptValues) {
serverPropsToAccept.push('value')
serverPropsToAccept.push('initialValue')
}
let changed = false