[Vtigercrm-developers] Record restriction based on reports_to field.
salim
salimcmd at gmail.com
Tue Apr 30 17:23:40 UTC 2013
Adam,
I made some changes in function. and it seems working nicly
1. function getReportingUsers($userId, &$acc) {
2. global $log;
3. $log->debug("Entering getReportingUsers(" . $userId . ") method
...");
4. global $adb;
5. $log->debug($acc);
6. $sql = "select id from vtiger_users where reports_to_id = ?";
7. $result = $adb->pquery($sql, array($userId));
8. $num_rows = $adb->num_rows($result);
9. if ($num_rows < 0)
10. return FALSE;
11. for ($i = 0; $i < $num_rows; $i++) {
12. $id = $adb->query_result($result, $i, 'id');
13. if (!in_array($id, $acc)) {
14. array_push($acc, $id);
15. getReportingUsers($id, $acc);
16. }
17. }
18. }
And
1. //Checking if the Record Owner is a reporting User
2. $userids = array();
3. getReportingUsers($current_user->id,$userids);
4. if(in_array($recOwnId, $userids)){
5. $permission='yes';
6. $log->debug("Exiting isPermitted method ...");
7. return $permission;
8. }
And the log http://pastebin.com/LwDmj8M5
Please let me know your opinion about this.
Thanks
--
Salim
On 30 April 2013 21:38, Adam Heinz <amh at metricwise.net> wrote:
> Users always find a way to get bad data into the system. ;) I have added
> a ton of referential integrity to our fork of vtiger and crap still makes
> it in periodically.
>
> Check out this tutorial [3] on tail recursion and accumulators. Basically
> you'll just accumulate an array of userids and use in_array to make sure
> that you don't process the same userid twice. PHP doesn't optimize for
> tail recursion, so I would recommend writing it as a loop inside a function.
>
> [3]
> http://siddhi.blogspot.com/2006/04/recursion-part-2-tail-recursion.html
>
>
> On Tue, Apr 30, 2013 at 11:40 AM, salim <salimcmd at gmail.com> wrote:
>
>> Adam,
>> You saying that make two users to report to each other, like *UserA
>> *---> *UserB* , *UserB ---> UserA*. Will it happen in real scenario?
>> If so this will happen http://pastebin.com/jrFmBnxS. It dropped in a
>> infinite loop. :P
>>
>> How you proposing accumulator in Recursive function.
>>
>> Thanks
>> --
>> Salim
>>
>>
>> On 30 April 2013 20:14, Adam Heinz <amh at metricwise.net> wrote:
>>
>>> Ooooooh, reverse that again, it could be cyclic, even though that would
>>> make so sense, the system does not enforce it. Definitely need the
>>> accumulator to avoid an infinite loop. Set two users to report to each
>>> other and see if it explodes. ;)
>>>
>>>
>>> On Tue, Apr 30, 2013 at 10:14 AM, Adam Heinz <amh at metricwise.net> wrote:
>>>
>>>> On Tue, Apr 30, 2013 at 10:12 AM, Adam Heinz <amh at metricwise.net>wrote:
>>>>
>>>>> You should add some sort of accumulator to getReportingUsers so that
>>>>> you don't recur for userids you have already checked.
>>>>>
>>>>
>>>> Scratch this comment, we're walking a directed acyclic graph;
>>>> redundancy is impossible.
>>>>
>>>
>>>
>>> _______________________________________________
>>> http://www.vtiger.com/
>>>
>>
>>
>>
>> --
>> Muhammed Abdul Salim
>>
>> _______________________________________________
>> http://www.vtiger.com/
>>
>
>
> _______________________________________________
> http://www.vtiger.com/
>
--
Muhammed Abdul Salim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20130430/4da4c745/attachment-0001.html>
More information about the vtigercrm-developers
mailing list