Implementing conditional logic in search box based on user roles

Hello Bubble community,

I’m working on a feature where I need to implement conditional logic for a search box based on the user’s role. Specifically, I want to make sure that the search results are filtered so that teachers can only see students associated with them and not students associated with other teachers. However, since the reusable that contains the search box is also used on the admin dashboard, I still want to allow admins to see all students using the same search box. Is there a way to achieve this? Like a condition that would change the list of users it searches for based on user role?

Here’s the context of my question:

  • The search box is currently set up for teachers only. This prevents students who are associated with other teachers from showing up in the search results. This search box is only visible if the user is a teacher.
  • I’ve duplicated the search box as a workaround to allow admins to search all users. This search box is only visible if the user is an admin.
  • We cannot use privacy rules because we need teachers other than the student’s current teachers to be able to see the student’s information (e.g. previous comments made by other teachers) as long as those teachers belong to the same educational organization.
  • On the User data type, there’s a role field, which is an option set, and a teachers field, which is a list of users.

I’ve included screenshots below to illustrate the setup.

For admins:

For teachers:

Based on this setup, is there a way to implement conditionals directly in the search box (or any other part of the platform) to update the list of users being searched to achieve the desired filtering based on the user’s role?

Any guidance or suggestions would be greatly appreciated!

Thanks in advance for your help!

Have a hidden group in a popup or something.

Call it var - teacher constraint.

Add a conditional to that group such that when the current user is a teacher, the data source is Current User.

Make the search constraint teachers contains var - teacher constraint’s User and check Ignore empty constraints.

Now, the constraint will not be applied when admin (because the teacher contains constraint will be empty) but will be when the user is a teacher (as var - teacher constraint becomes not empty through a conditional).

Thanks @georgecollier for the clever workaround! To help others understand, I’ve summarized the steps below and included screenshots for visual guidance:

  1. Create a Hidden Group: Set up a hidden group within a popup named var - teacher constraint (in my case, <D> teacherSearchConstraint).
  2. Add Conditional: Configure the group to have a conditional that assigns Current User as the data source when the user is a teacher.
  3. Search Constraint: Apply a search constraint where teachers contains var - teacher constraint’s User and enable Ignore empty constraints.
1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.