0

Currently working on Cube.JS and I'm building a cube within I want to restrict the data to an user based on his gender. So I end up with :

cube(`Data`, {
    sql: `select * from my_table where ${SECURITY_CONTEXT.user_gender.filter(user_gender)}`,
    ...

as explained here

But now I want to restrict the data to an user based on his gender AND his age, how should I proceed ? I was thinking about something like that...

cube(`Data`, {
    sql: `select * from my_table where ${SECURITY_CONTEXT.user_gender.user_age.filter(user_gender,user_age)}`, //????
    ...

...but it seems weird to put two "attributes" .user_gender.user_age.filter to the SECURITY_CONTEXT

I hope someone has already tried something like that. Thank you!

Parzival
  • 2,051
  • 4
  • 14
  • 32
Bilel
  • 3
  • 1

1 Answers1

1

You'll need to use SECURITY_CONTEXT twice:

cube(`Data`, {
    sql: `select * from my_table where ${SECURITY_CONTEXT.user_gender.filter(user_gender)} AND ${SECURITY_CONTEXT.user_age.filter(user_age)}`,
    ...
Hassan Khan
  • 766
  • 3
  • 9
  • 21
  • Ok thanks, but in `SECURITY_CONTEXT.part1.filter(part2)`, the part2 correspond to the sql column we want to filter and part1 to the name of the element passed in the token ? – Bilel Jun 08 '21 at 10:06