rejetto forum

error with macro 'member of'

Mars · 8 · 6275

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
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|.}
« Last Edit: April 03, 2009, 09:50:57 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
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);
« Last Edit: April 05, 2009, 07:58:08 PM by rejetto »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
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);


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
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?


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
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


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
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


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
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 ;)
« Last Edit: April 12, 2009, 03:18:59 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile