rejetto forum

Software => HFS ~ HTTP File Server => Programmers corner => Topic started by: Mars on April 03, 2009, 09:26:56 PM

Title: error with macro 'member of'
Post by: Mars on April 03, 2009, 09:26:56 PM
I ask me a question about the macro 'to member of'. When a user's name is given in parameter, the macro return a result not empty if it is up to one of the groups that we wish to test.

It seems in the sources that if the account does not exist, then the name of the on-line user is taken and can give a bad  result.

Quote
  s:=par(1, 'user');
  if s > '' then
    a:=getAccount(s);
  if (a = NIL) and assigned(md.cd) then
    a:=md.cd.account;

I make a mistake certainly, but in my opinion if a name is then supplied the current user should not interfere. To convince itself, it is enough to associate its own account to an existing group 'group1' and to use the macro following one with the unexisting account 'taratata':

Quote
<body>
{.if|{.member of|group1|taratata.}|<hr>yep<hr>.}

The obtained result is a magnificent 'YEP', what is not in accordance with the reality of the made test.

The code adequate would rather be the one this
Quote
   procedure memberOf();
  var
    a: Paccount;
    s: string;
  begin
  a:=NIL;
  s:=par(1, 'user');
  if s > '' then a:=getAccount(s)
    else if (pars.count<2) and  assigned(md.cd) then a:=md.cd.account;  result:='';
  if a = NIL then exit;
  trueIf(findEnabledLinkedAccount(a, split(';',par(0,'group'))) <> NIL);
  end; // memberOf


current user by using
{.member of|group1.}     and not by  {.member of|group1|.}
Title: Re: error with macro 'member of'
Post by: rejetto on April 05, 2009, 07:56:37 PM
you are right.
thanks for reporting.

i think to use this code in next build.
let me know if you see any flaw in it.
Code: [Select]
 result:='';
  s:=par(1, 'user');
  if s > '' then
    a:=getAccount(s)
  else if assigned(md.cd) then
    a:=md.cd.account
  else
    exit;
  trueIf(findEnabledLinkedAccount(a, split(';',par(0,'group'))) <> NIL);
Title: Re: error with macro 'member of'
Post by: Mars on April 05, 2009, 08:16:37 PM
current user only by using macro
{.member of|group1.}       only one parameter

 and not with  {.member of|group=group1|user=.}   

 two parameters -->> never the logged account, i think it is better.

Quote
result:='';
  s:=par(1, 'user');
  if s > '' then
    a:=getAccount(s)
  else if (pars.count<2) and assigned(md.cd) then
    a:=md.cd.account
  else
    exit;
  trueIf(findEnabledLinkedAccount(a, split(';',par(0,'group'))) <> NIL);
Title: Re: error with macro 'member of'
Post by: rejetto on April 05, 2009, 08:30:49 PM
why should we care about the "user=" case?
it may happen if you use "user=%user%" with anonymous access.
in such case it will go for md.cd.account, with will be empty as well.
isn't that ok?
Title: Re: error with macro 'member of'
Post by: Mars on April 08, 2009, 01:44:51 AM
is it possible to change to..?
Quote

  procedure memberOf();   // mod by mars
  var
    a: Paccount;
    s: string;
  begin
 result:='';
  s:=par(1, 'user');
  if s > '' then
    a:=getAccount(s)
  else if assigned(md.cd) then
    a:=md.cd.account
  else
    exit;
  a:=findEnabledLinkedAccount(a, split(';',par(0,'group')));
  if a<>NIL then result:=a.user;
 // trueIf(findEnabledLinkedAccount(a, split(';',par(0,'group'))) <> NIL);
  end; // memberOf


two accounts as group : gruppo and asd -->>  gruppo.link='asd'
 but error : {.member of|asd|gruppo.}  return empty result
Title: Re: error with macro 'member of'
Post by: rejetto on April 08, 2009, 04:02:14 PM
i guess this is the best way to solve this problem
    a:=getAccount(s, TRUE)


i don't understand why you suggest the other change
Title: macro 'member of' extended (ACCEPTED BY THE BOSS)
Post by: Mars on April 11, 2009, 10:55:25 PM
Quote
i don't understand why you suggest the other change

Even if it means obtaining a true or false result, why not obtaining the linked group  first one?
It is just a proposition, not a necessity ;)
Title: Re: error with macro 'member of'
Post by: rejetto on April 12, 2009, 12:31:55 PM
ah, yes, i will