rejetto forum
Software => HFS ~ HTTP File Server => Programmers corner => Topic started 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.
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':
<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
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|.}
-
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.
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);
-
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.
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);
-
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?
-
is it possible to change to..?
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
-
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
-
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 ;)
-
ah, yes, i will