Axaptapedia is now maintained by AgileCadence For more information please click here.

Record Level Security

From Axaptapedia
Jump to: navigation, search

This is a modification to SysQueryRun.new to use RLS on depended tables. (by OIP from AxForum) <xpp> public void new(anytype _p1) {

   // custom RLS, OIP, 05.09.06 -->
   int                     i,j,k;
   QueryBuildRange         r;
   QueryBuilddatasource    ds;
   QueryBuilddatasource    childDS;
   QueryBuilddatasource    intDS;
   QueryBuilddatasource    restrictDS;
   Query                   q;
   SysRecordLevelSecurity  RLSTable;
   Query                   restriction;
   userGroupId             groupId;
   userGroupList           groupList;
   // custom RLS, OIP, 05.09.06 <--
   if (_p1)
   {
       super (_p1);
       if (this.args() &&
           !this.args().caller() &&
           typeOf(_p1) == Types::Class &&
           !SysdictClass::isEqualOrSuperClass(classidget(_p1), classNum(Query)))
       {
           this.args().caller(_p1);
       }
       // custom RLS, OIP, 05.09.06 -->
       q = this.query();
       for(i=1; i<= q.dataSourceCount(); i++)
       {
           ds = q.dataSourceNo(i);
           while select RLSTable
               where RLSTable.tabId         == ds.table() &&
                        RLSTable.companyId == curext()
               join groupList
               where   groupList.groupId == RLSTable.groupId &&
                       groupList.userId  == curUserId()
           {
               if(RLSTable.restriction != conNull() &&
                  sysQuery::isPackedOk(RLSTable.restriction))
               {
                   restriction = new QueryRun(RLSTable.restriction).query();
                   if(restriction.dataSourceCount()>1)
                   {
                       for(j=2;j<= restriction.dataSourceCount();j++)
                       {
                           restrictDS = restriction.dataSourceNo(j);
                           intDS = restrictDS.parentDataSource();
                           if (!SysQuery::tableOccurrence(q, restrictDS.table(), q.dataSourceCount()))
                           {
                               childDS = q.dataSourceTable(intDS.table()).addDataSource(restrictDS.table());
                               childDS.relations(true);
                               childDS.joinMode(JoinMode::ExistsJoin);
                               childDS.fetchMode(QueryFetchMode::One2One);
                           }
                           else
                           {
                               childDS = q.dataSourceTable(restrictDS.table());
                           }
                           for(k=1;k<=restrictDS.rangeCount();k++)
                           {
                               r = childDs.addRange(restrictDS.range(k).field());
                               r.value(restrictDS.range(k).value());
                               r.status(RangeStatus::Hidden);
                           }
                       }
                   }
               }
           }
       }
       this.origQueryPack(q.pack(false));
   }
   // custom RLS, OIP, 05.09.06 <--
   loadLastUsedQuery   = true;
   saveQueryPrUser     = true;
   allowSave           = true;
   allowAddRange       = QueryAllowAdd::AllFields;
   allowAddSorting     = QueryAllowAdd::AllFields;
   showSorting         = true;

} </xpp>