directus/directus

Relationship Field on User Not Appearing or Saving to CURRENT_USER object

Open

#24.029 geöffnet am 12. Nov. 2024

Auf GitHub ansehen
 (5 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (25.193 Stars) (3.505 Forks)batch import
BugHelp WantedLow ReachMed ImpactStudio

Beschreibung

Describe the Bug

I have a tenant concept I'm using in directus with UUIDs. Each user has a tenant ID they are associated with. Some admin users have a "builder" tenant ID instead to help switch between tenants and build content for them.

On my directus users table I added 2 columns to represent this: tenant_id and builder_tenant_id. Both are UUIDs and foreign keys to my tenant table (primary key of this table is a UUID)

When I make a test admin user and go to its user page and save a builder tenant ID, the value does not appear in the dropdown, but I can verify it saved in the database. I have tried logging in again and refreshing the page and get the same results. Additionally, when I set the tenant Id the first time, any content I make throws an error that the tenant ID is missing until after I login a second time. The tenant ID is pulled from the user like this:

{
    "tenant_id": "$CURRENT_USER.builder_tenant_id"
}

I would expect that to work right away without me having to login again.

Further notes:

I did notice that the issue of the item not appearing only happens when I only set one of the tenant IDs on the user. If I set both at once, the values appear in the dropdowns even though both values are nullable.

To Reproduce

Make a tenant table that uses UUIDs

Add two columns to the directus users table: tenant_id and builder_tenant_id these are many to one back to Tenant

Make a new test user and give them app access

Login as that user and change just your builder tenant Id and save

Expected: The tenant Id shows up as the value in the dropdown and allows that user to create content

Actual: The value does not appear ever, and the user cannot create content until logging in again

Directus Version

11.2.1

Hosting Strategy

Self-Hosted (Docker Image)

Database

Postgres

Contributor Guide