Forum Discussion
RLS using an if(switch)-statement and an or-statement
- 4 years ago
Hi, Anonymous
I think you don't understand enough about the nature of RLS. Since your main table doesn't have an email column, you can only get row and column data through relational matching. If it doesn't match, you can get nothing, not get all.
So what you have to do is to build a new role to separate those who can see the whole report from those who can see some of the reports.
Below is my sample:
Copy the user table and rename it to distinguish from and to, and then establish a relationship with the main table respectively.
Set rls roles in desktop.
Deploy permissions in the service.
Note that you need to create two groups to avoid conflicts, put users who see all reports in one group and add them to All roles. Put the users who can only see some of them in another group, and then add them to From and To roles, both roles must be added, otherwise they will not see all of they can see.
I have tested this method and it works fine.
Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.
Best Regards,
Community Support Team _ Janey
Thanks for your reply!
I have created a sample with some dummy data. In this sample you see the 'fact Quote' table, with some details. The second table 'RLS User' one can see the table which I duplicated in my example. In this table you can see which users are allowed to see which countries. So in this sample the users should see the following quotes:
- User 1: all quotes
- User 2: 1, 4, 5, 6, 7 and 10
- User 3: 2, 3, 4, 6 and 9
| QuoteID | Price | Lane | CountryFrom | CountryTo |
| 1 | 20 | GB-London---NL-Rotterdam | GB | NL |
| 2 | 10 | ES-Barcelona---FR-Paris | ES | FR |
| 3 | 50 | NL-Rotterdam---ES-Barcelona | NL | ES |
| 4 | 5 | GB-London---ES-Barcelona | GB | ES |
| 5 | 25 | IE-Dublin-GB-London | IE | GB |
| 6 | 30 | ES-Barcelona---IE-Dublin | ES | IE |
| 7 | 40 | NL-Rotterdam---GB-London | NL | GB |
| 8 | 40 | FR-Paris---NL-Rotterdam | FR | NL |
| 9 | 20 | ES-Barcelona---FR-Paris | ES | FR |
| 10 | 10 | IE-Dublin-GB-London | IE | GB |
| UserID | Country | |
| 2 | [email protected] | GB |
| 2 | [email protected] | IE |
| 3 | [email protected] | ES |
Hi, Anonymous
I think you don't understand enough about the nature of RLS. Since your main table doesn't have an email column, you can only get row and column data through relational matching. If it doesn't match, you can get nothing, not get all.
So what you have to do is to build a new role to separate those who can see the whole report from those who can see some of the reports.
Below is my sample:
Copy the user table and rename it to distinguish from and to, and then establish a relationship with the main table respectively.
Set rls roles in desktop.
Deploy permissions in the service.
Note that you need to create two groups to avoid conflicts, put users who see all reports in one group and add them to All roles. Put the users who can only see some of them in another group, and then add them to From and To roles, both roles must be added, otherwise they will not see all of they can see.
I have tested this method and it works fine.
Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.
Best Regards,
Community Support Team _ Janey