How do I use a Precondition with an Array?

Options

I'm trying to write some permissions into my application, simply put getting a list of users who are allowed to edit a record. I have a basic list of users stored in array who have access, and I want to enforce a precondition that says if the users_id trying to edit the record is in the array, then they can edit.

The problem I'm running into is that I don't see any array functions for validating data exists within a precondition, I'm only seeing basic mathematical operators.

Does anyone know how to go about achieving this?

Best Answer

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Answer ✓
    Options

    Almost @Patopt - remember, you don't want to evaluate if "true" is in your array but rather the user_id input. So you'll want to move the filter to the other side.

Answers

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Hi,

    Yes, the arrays don't have some of the operators available in queries.

    From the top of my head I can think of a solution like this:

    create an array with only one element which is the user_id then create another variable and use intersect filter on the newly created array and the one in which you want to check, if it's empty then your id is not in the second array and based on that condition you can create some further actions.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hi @Patopt - you will want to use the IN filter to say if your value is IN the array and set it equal to true/false. Some query operators move into filters outside of the query. IN is an example of this.

    WHERE

    input: user_id | IN | var: flow_editors == true
    

  • Patopt
    Patopt Member
    Options

    Something like this? Just tried and looks like precondition is not catching the condition, everything just goes through.

  • Patopt
    Patopt Member
    Options

    Thank you!

  • Ruan Carstens
    Ruan Carstens Member
    edited November 2023
    Options

    For anyone that wants to use preconditions with arrays and true doesn't, try replacing the true bool with null.