Skip to content

HowToFilterData

Carlo Barazzetta edited this page Jan 27, 2017 · 1 revision

How to filter data in a view according to connected user###

The feature is implemented by the DefaultFilter node at model or view level.

For example, suppose that in your config.yaml file the login ReadUserCommandText is implemented as in the following:

.....
  ReadUserCommandText: |
    select
      A.ID AS USER_NAME, a.PASSWD AS PASSWORD_HASH, 
      a.SYSYEM as SYSTEM, E.ID AS EMPLOYEEID, E.DX AS EMPLOYEEDX
      from APPUSER A 
      LEFT JOIN employee E ON E.APPUSERCLASS = 'TISUser' AND E.APPUSERID = A.ID

Suppose in a model or view you want to show only records of current user.

just write in the model or in the view the following code (implemented for a view):

.....
MainTable:
.....
  DefaultFilter: |
    (EMPLOYEEID in (select ID FROM EMPLOYEE where APPUSERID = '%Auth:USER_NAME%'))

where %Auth:USER_NAME% is a macro expanded by Kitto

a more complex example: you want to show all records in case current user is a system user. Just use the %Auth:SYSTEM% macro as in the following:

.....
MainTable:
.....
  DefaultFilter: |
 ('%Auth:SYSTEM%' = 1 or 
  (EMPLOYEEID in (select ID FROM EMPLOYEE where APPUSERID = '%Auth:USER_NAME%')))
Clone this wiki locally