Database connected and different filtering requirements

Hi,

I’m seeking advice on best practices for handling data retrieval when different filtering requirements apply based on the user’s role or permissions.

To illustrate, I’ve created a data model with two classes: “Projects” and “Project Participants.” The “Projects” class includes a filter to show only projects where the user is a participant:

Now, I’ve introduced a variable called “User is admin,” which is set to true for some users and false for others:

Here’s the root of the challenge: In this scenario I want administrators to see all projects, but the initial filtering still displays only those where the user is a participant.

I’ve experimented with “Client Filters,” where I can create a filter based on a variable or another class (see image below). However, to display all data for the admin, I need to check the “Read All Objects” option. This feels a bit unconventional, but I guess that’s what has to be done to be able to display all data for the admin::

image

This use case can also be related when data in classes for example has a property for a “Responsible Company”. Some users should only see data from their company, but a user from another company might want to see data from multiple companies (not particularly all).

Anyone have any thoughts regarding this?

Best regards,
Sondre

Hi!

Since there is not conditional filter for the (server-side) Filter setting of a database connected data source (challenge registered on that one), you may solve this for example the following way:

If you want 1 database connected data source, as you have above, holding either the participants projects or the project managers projects (depending on condition A or B) - you may add an “On app load” action that has reads data into a Runtime Only Datasource Projects (FILTER). The action may read object into that data source inside an IF statement (reading differently for condition A vs condition B).

Having this setup, your Projects data source would only need the filter Projects.ID exists in Projects (FILTER) (all).

Hi,

Thank you for your response. Your workaround was effective. I can now utilize a runtime-only data source to retain the appropriate rows based on a conditional filter. Additionally, the data source class can leverage the runtime class to filter the correct data.

Regards,
Sondre