Skip to content

HowToFilterData

iraichi edited this page Jun 25, 2015 · 9 revisions

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:

.....
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:

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

Clone this wiki locally