<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-2022-JP"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Helvetica, Arial, sans-serif">I also discovered </font>DBIx::Class::Tree::AdjacencyList<br>
Using this module I can define my parent_id in my Users.pm schema like:<br>
<pre> __PACKAGE__->parent_column('parent_id');</pre>
<br>
And then I can get all children of one user like:<br>
<br>
my $user_id = 7;<br>
my $thisuser = $c->model('MyDB::Users')->find({ user_id=>
$user_id });<br>
my $children = $thisuser->children();<br>
<br>
But this gives me only a list of children one level under $thisuser and
it's the same<br>
as executing only:<br>
<br>
my $children = $c->model('MyDB::Users')->find({ parent_id=>
$user_id });<br>
<br>
So it's no big deal.. Still this module is OK because it maintains
consistency of the<br>
tree when you delete one branch for example, but I still haven't found
the solution I<br>
need - listing all children in all levels under one parent as well as
checking if <br>
a single user is a (grand)parent who can edit a certain user...<br>
<br>
When listing all children it would also be necessary if I could specify
order (e.g. order by username)<br>
and also limit and offset for pagination on website...<br>
<br>
<br>
<br>
jakac wrote:
<blockquote cite="mid:4846413C.4070602@iprom.si" type="cite">
<meta content="text/html;charset=ISO-2022-JP"
http-equiv="Content-Type">
<font face="Helvetica, Arial, sans-serif">Hi,<br>
<br>
Ok, I understand the concept of walking through this DB::User model but
another <br>
question is - where should I put this function and how should I call it
from my controllers?<br>
Until now I only used basic integrated functions that are integrated in
catalyst & its plugins<br>
so I am not familiar with all the concepts behind catalyst custom
models.<br>
<br>
Thanx!<br>
</font><br>
<a moz-do-not-send="true" class="moz-txt-link-abbreviated"
href="mailto:sindharta_tanuwijaya@yahoo.co.jp">sindharta_tanuwijaya@yahoo.co.jp</a>
wrote:
<blockquote
cite="mid:20080604015253.87812.qmail@web3115.mail.kcd.yahoo.co.jp"
type="cite">Hi,<br>
<br>
Haven't tried it yet, but I think the code in Catalyst should look like:<br>
<br>
my $edited =
$c->model('DB::User')->find({id=>$target_user_id});<br>
my $ancestor =
$c->model('DB::User')->find({id=>$edited->{parent_id}});<br>
my $found = 0;<br>
while ($found==false && $ancestor) {<br>
if ($ancestor == $c.user.user_id)<br>
$found= true;<br>
$ancestor =
$c->model('DB::User')->find({id=>$edited->{parent_id}});<br>
}<br>
return $found;<br>
<br>
You can push the ancestors into a list if you want to have a list of
users who can edit $target_user_id. But I am not really sure if you can
make a top-to-bottom approach with this one. (I assume top-to-bottom
means searching from all ancestors instead of the user that you want to
edit)<br>
<br>
Sindharta<br>
<br>
<br>
<b>jakac <a moz-do-not-send="true" class="moz-txt-link-rfc2396E"
href="mailto:jakac@iprom.si"><jakac@iprom.si></a></b> wrote:
<blockquote class="replbq"
style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">
<meta content="text/html;charset=ISO-2022-JP"
http-equiv="Content-Type">
<title></title>
<font face="Helvetica, Arial, sans-serif"><br>
Yes this seems fine but how to code this in Catalyst? :) <br>
And another thing - if I want to list users that certain this_user can
edit,<br>
I would need to go through the whole list and check for each user if <br>
"this_user" is one of the (grand)parents. <br>
<br>
Your approach is bottom-to-top and I now I am also looking for
top-to-bottom...<br>
I think I can manage to write one of these functions by myself if
someone<br>
would just give me an example how to write one of these.. <br>
</font><br>
<a moz-do-not-send="true" class="moz-txt-link-abbreviated"
href="mailto:sindharta_tanuwijaya@yahoo.co.jp">sindharta_tanuwijaya@yahoo.co.jp</a>
wrote:
<blockquote
cite="mid:20080603021257.79691.qmail@web3105.mail.kcd.yahoo.co.jp"
type="cite">Hi, <br>
<br>
Maybe an algorithmic approach ?<br>
<br>
--<br>
ancestor = edited.parent;<br>
found = false;<br>
while (found==false and ancestor!=null) {<br>
if (ancestor == current_user)<br>
found= true;<br>
ancestor = ancestor.parent<br>
}<br>
return found;<br>
--<br>
<br>
I came from C++ background rather than Perl, so I am sorry if it looks
more like C++ but I hope you got the idea. Not that there's a bit of
recursive going on there.<br>
<br>
Sindharta<br>
<br>
<b>jakac <a moz-do-not-send="true"
class="moz-txt-link-rfc2396E" href="mailto:jakac@iprom.si"><jakac@iprom.si></a></b>
wrote:
<blockquote class="replbq"
style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">
<font face="Helvetica, Arial, sans-serif">Hello!<br>
<br>
I need a help on building a model for user that has a permission to
edit <br>
other users that were created by this user or any of his children,
grandchildren etc.<br>
(difficult sentence, I know)<br>
<br>
To make this a little more understandable here's my database table:<br>
<br>
- user_id <br>
- username<br>
- password<br>
- various other data such as fname, lname, address etc.<br>
- parent_id<br>
<br>
Column "parent_id" has a value of "user_id" that created one user.
There is also<br>
a "superadministrator" with parent_id '0' that can edit everybody.<br>
<br>
Now I would like to build a model that I can use in my controllers like:<br>
<br>
if ( user_id is child,grandchild,gradgrandchild.... of logged in
$c->user ) {<br>
# has permisson to edit <br>
} else {<br>
# doesn't have a permission to edit<br>
}<br>
<br>
Example:<br>
- superadmin<br>
|__- foo<br>
|__- bar<br>
|____- john<br>
|______- doe<br>
<br>
In this example:<br>
- superadmin can edit anybody,<br>
- bar can edit john & doe<br>
- john can edit only doe<br>
- foo can't edit anybody since he has no children<br>
And there can be unlimited levels of users... <br>
<br>
There is no problem with permission to edit first child since I can
just compare<br>
logged in user's ID with edited user's parent_id but when edited user
is grandchild,<br>
grandgrandchild, (grand * n) child of $c->user then I need some kind
of model<br>
to return true/false value.<br>
<br>
I've never done that and I am also new to Catalyst so any help would be
appreciated.<br>
Thank you!<br>
<br>
<br>
JakaC.</font> _______________________________________________<br>
List: <a moz-do-not-send="true" class="moz-txt-link-abbreviated"
href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
Listinfo: <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br>
Searchable archive: <a moz-do-not-send="true"
class="moz-txt-link-freetext"
href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br>
Dev site: <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a><br>
</blockquote>
<br>
<div
style="line-height: 0pt; width: 0pt; height: 5px; clear: both;"> </div>
<div> </div>
<hr size="1"><a moz-do-not-send="true"
href="http://pr.mail.yahoo.co.jp/toolbar/" target="new">Power up the
Internet with Yahoo! Toolbar.</a><br>
<pre wrap=""><hr size="4" width="90%">
_______________________________________________
List: <a moz-do-not-send="true" class="moz-txt-link-abbreviated"
href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a>
Listinfo: <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a>
Searchable archive: <a moz-do-not-send="true"
class="moz-txt-link-freetext"
href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a>
Dev site: <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a>
</pre>
</blockquote>
_______________________________________________<br>
List: <a moz-do-not-send="true" class="moz-txt-link-abbreviated"
href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
Listinfo: <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br>
Searchable archive:
<a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br>
Dev site: <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a><br>
</blockquote>
<br>
<div style="line-height: 0pt; width: 0pt; height: 5px; clear: both;"> </div>
<p> </p>
<hr size="1"><a moz-do-not-send="true"
href="http://pr.mail.yahoo.co.jp/toolbar/" target="new">Power up the
Internet with Yahoo! Toolbar.</a><br>
<pre wrap=""><hr size="4" width="90%">
_______________________________________________
List: <a moz-do-not-send="true" class="moz-txt-link-abbreviated"
href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a>
Listinfo: <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a>
Searchable archive: <a moz-do-not-send="true"
class="moz-txt-link-freetext"
href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a>
Dev site: <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a>
</pre>
</blockquote>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
List: <a class="moz-txt-link-abbreviated" href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a>
Listinfo: <a class="moz-txt-link-freetext" href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a>
Searchable archive: <a class="moz-txt-link-freetext" href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a>
Dev site: <a class="moz-txt-link-freetext" href="http://dev.catalyst.perl.org/">http://dev.catalyst.perl.org/</a>
</pre>
</blockquote>
</body>
</html>