Hello,
I am writing a SAAS application for my business clients. This application manages several organizations and each user is associated with only one organization.
Fig. ER Diagram
All entities that are created afterwards (e.g. machines, components, etc.) are associated at the time of their creation to the same organization as the one to which the current user belongs.
Fig. SecurityService injection in main application DB Service
Fig. Machine creation with association with the current user's organization in main application DB Service
This makes it possible to display only the entities that belong to the organization to which the current user belongs. This is essential for an application that will manage dozens of different organizations. It works very well when reading, for example to display a grid of machines.
Fig. Machine are filtered by current user's organization in main application DB Service
However, it does not work when I try to export data with the Export button of a DataGrid.
Fig. The return value of 'mach' is null in ExportController when we try to export machines
The reason is that when I call the 'GetMachines' method for example, which in turn calls the 'OnMachineRead' method, the user found by 'security.user' is not the current user. But rather a user named Anonymous. This causes the 'OnMachineRead' method to return no machines, since it has no idea what organization the user Anonymous belongs to.
Do you have any idea why the current user is available when reading a table for display but not available for data export?
Thanks