When a new organisation was created through the API and subsequently activated, users created from contactpersonen associated with that organisation were being added to the 'Default Organisation' instead of the organisation specified in the contactpersoon data.
The issue had two main causes:
-
Missing Organisation Entity: When an organisation object was created in the voorzieningen register (via OpenRegister objects), a corresponding organisation entity was not automatically created in OpenRegister's
oc_openregister_organisationsdatabase table. -
Active Organisation Context: When a user was created from a contactpersoon, the system would try to add the user to an organisation entity, but if that entity didn't exist, the user would end up in the logged-in admin's organisation (usually the Default Organisation).
- Admin creates a new organisation 'test93' via POST to
/api/apps/openconnector/api/endpoint/register - Organisation object is created in voorzieningen register with UUID
a7604b7e-4b8c-46d5-870b-0018ddd5890a - Organisation includes a contactpersoon with email
test92@test.nl - Admin activates the organisation by changing status to 'Actief'
- User is created from contactpersoon
- BUG: User ends up in 'Default Organisation' instead of 'test93'
The fix adds logic to ensure that:
- When adding a user to an organisation entity, the system first checks if the organisation entity exists
- If the entity doesn't exist, it is created from the organisation object data
- The user is then added to the correct organisation entity
- The user's active organisation is set to the contactpersoon's organisation
File: softwarecatalog/lib/Service/SoftwareCatalogue/ContactPersonHandler.php
- Added check for organisation entity existence
- If entity doesn't exist, calls new
ensureOrganizationEntity()method - Improved error handling and logging
This new private method:
- Fetches the organisation object from OpenRegister by UUID
- Extracts organisation name and description
- Creates the organisation entity using
OrganisationService->createOrganisationWithUuid() - Ensures the UUID matches between object and entity
- Returns the created organisation entity
- Now also sets the user's active organisation in OpenRegister config
- This ensures users are automatically logged into the correct organisation
- Stores both in 'core' namespace (for OpenConnector) and 'openregister' namespace (for active org)
- Access to a development environment with:
- Nextcloud with OpenRegister and SoftwareCatalog apps installed
- Docker containers running (nextcloud and database)
- Admin access to Nextcloud
# Create a new organisation with a contactpersoon
curl -X POST \
'http://nextcloud.local/index.php/apps/openconnector/api/endpoint/register' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-d '{
"naam": "Test Organisation XYZ",
"website": "www.testxyz.nl",
"type": "Leverancier",
"status": "Concept",
"contactpersonen": [
{
"voornaam": "Test",
"achternaam": "User",
"e-mailadres": "testuser@testxyz.nl",
"telefoonnummer": "0612345678"
}
]
}'Save the organisation UUID from the response (in @self.id or id field).
# List organisations in concept status
curl -X GET \
'http://nextcloud.local/index.php/apps/openregister/api/objects/1/7?status=Concept&_extend[]=@self.schema&_extend[]=contactpersonen' \
-H 'Authorization: Basic YWRtaW46YWRtaW4='Verify the organisation appears with its contactpersoon.
# Update organisation status to Actief
curl -X PUT \
'http://nextcloud.local/index.php/apps/openregister/api/objects/1/7/<ORGANISATION_UUID>' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-d '{
"status": "Actief"
}'- Login to Nextcloud as admin
- Go to Users settings
- Find the newly created user (testuser@testxyz.nl)
- Verify the user exists
# Check user's organisation in database
docker exec -it <database-container> mysql -u nextcloud -pnextcloud nextcloud -e \
"SELECT u.uid, o.uuid, o.name
FROM oc_openregister_organisations o
JOIN JSON_TABLE(o.users, '$[*]' COLUMNS (user_id VARCHAR(255) PATH '$')) ut
ON FIND_IN_SET(ut.user_id, REPLACE(REPLACE(o.users, '[', ''), ']', ''))
WHERE ut.user_id = 'testuser@testxyz.nl';"Expected Result: User should be in 'Test Organisation XYZ', not 'Default Organisation'
# Check user config
docker exec -u 33 <nextcloud-container> php occ config:user:get testuser@testxyz.nl openregister active_organisationExpected Result: Should return the UUID of 'Test Organisation XYZ'
- Login as the newly created user
- Go to OpenRegister app
- Check which organisation is active (should be 'Test Organisation XYZ')
- Verify user can only see data from their organisation
# Check container logs for organisation entity creation
docker logs <nextcloud-container> | grep "ContactPersonHandler: Creating organization entity"
# Should see logs like:
# ContactPersonHandler: Organization entity not found, creating it
# ContactPersonHandler: Creating organization entity from object data
# ContactPersonHandler: Successfully created organization entity
# ContactPersonHandler: Successfully added user to organization entity- Organisation Entity Created: When user is created, if organisation entity doesn't exist, it is automatically created
- Correct Organisation Assignment: User is added to the contactpersoon's organisation, not admin's organisation
- Active Organisation Set: User's active organisation is set to the correct organisation
- User Login: When user logs in, they are automatically in the correct organisation context
If issues occur, the changes can be reverted by restoring the previous version of:
softwarecatalog/lib/Service/SoftwareCatalogue/ContactPersonHandler.php
- Positive: Users are now correctly assigned to their organisations
- Performance: Minimal impact; organisation entity creation only happens once per organisation
- Backward Compatibility: Existing users are not affected; only new user creation is changed
softwarecatalog/lib/Service/SoftwareCatalogue/ContactPersonHandler.php- Main fixopenregister/lib/Service/OrganisationService.php- Used for entity creationopenregister/lib/Db/OrganisationMapper.php- Database operations
- Consider automatically creating organisation entities when organisation objects are created
- Add migration script to create missing organisation entities for existing organisations
- Add validation to prevent organisations without entities
- Date: 2025-10-14
- Version: 1.0.0
- Issue: Users created from contactpersonen added to wrong organisation
- Related: OpenRegister multi-tenancy system
- Related: SoftwareCatalog organisation management