Author: spadkins
Date: Thu Oct  4 14:08:41 2007
New Revision: 10053

Modified:
   p5ee/trunk/App-Widget/lib/App/Widget/HierSelector.pm

Log:
do better checking for auth_name

Modified: p5ee/trunk/App-Widget/lib/App/Widget/HierSelector.pm
==============================================================================
--- p5ee/trunk/App-Widget/lib/App/Widget/HierSelector.pm        (original)
+++ p5ee/trunk/App-Widget/lib/App/Widget/HierSelector.pm        Thu Oct  4 
14:08:41 2007
@@ -117,6 +117,10 @@
     @nextnodeidx   = (1);    # check nodenumber "1" next
     @nextnodelevel = (1);    # index into the resulting table that the folder 
icon will go
 
+    my ($auth_key, $auth_name, $authorized);
+    my $context = $self->{context};
+    my $auth = $context->authorization();
+
     $nodenumberfound = "";
     while ($#nextnodebase > -1) {
         $nodebase  = pop(@nextnodebase);   # get info about next node to check
@@ -126,7 +130,21 @@
 
         if (defined $node->{$nodenumber}) {      # if the node exists...
 
-            if ($nodelevel > 1) {                # we have found the first 
node below the uppermost level
+            $auth_name = $node->{$nodenumber}{auth_name};
+            if (!$auth_name) {
+                $authorized = 1;
+            }
+            else {
+                if ($auth_name =~ m!^/!) {
+                    $auth_key = $auth_name;
+                }
+                else {
+                    $auth_key = "/App/SessionObject/$self->{name}/$auth_name";
+                }
+                $authorized = $auth->is_authorized($auth_key);
+            }
+
+            if ($nodelevel > 1 && $authorized) {  # we have found the first 
node below the uppermost level
                 $nodenumberfound = $nodenumber;
                 last;
             }
@@ -259,16 +277,23 @@
     my $node = $self->node_list(1);
     my $nodebase = $selected_nodenumber;
     my $nodeidx = 1;
-    my ($nodenumber);
+    my ($nodenumber, $first_auth_nodeidx);
     my $found = 0;
 
+    my ($auth_key, $auth_name, $authorized);
+    my $context = $self->{context};
+    my $auth = $context->authorization();
+
     while (!$found) {
         $nodenumber = "$nodebase.$nodeidx";
+
         if (!defined $node->{$nodenumber}) {
             if ($nodeidx == 1) {  # there are no leaves. $nodebase must be a 
leaf.
 
                 if ( $nodebase =~ /([0-9\.]+)\.[0-9]+$/ ) {
                     my $node_num = $1;
+                    # NOTE: SPA 2007-10-04 - I don't think this is completely 
correct
+                    # It will work for two-level selectors only, but not deeper
                     foreach my $key (keys %$node) {  $node->{$key}{open} = 0;  
} 
                     $node->{$node_num}{open} = 1;
                     $node->{$nodebase}{open} = 1;
@@ -278,17 +303,35 @@
                 $found = 1;
             }
             else {  # no "open" leaves on this branch
-                $node->{"$nodebase.1"}{open} = 1;
-                $self->set("selected", "$nodebase.1");
+                $node->{"$nodebase.$first_auth_nodeidx"}{open} = 1;
+                $self->set("selected", "$nodebase.$first_auth_nodeidx");
                 $found = 1;
             }
         }
-        elsif ($node->{$nodenumber}{open}) {
-            $nodebase = $nodenumber;
-            $nodeidx  = 1;
-        }
         else {
-            $nodeidx++;
+            $auth_name = $node->{$nodenumber}{auth_name};
+            if (!$auth_name) {
+                $authorized = 1;
+            }
+            else {
+                if ($auth_name =~ m!^/!) {
+                    $auth_key = $auth_name;
+                }
+                else {
+                    $auth_key = "/App/SessionObject/$self->{name}/$auth_name";
+                }
+                $authorized = $auth->is_authorized($auth_key);
+            }
+
+            if ($node->{$nodenumber}{open} && $authorized) {
+                $nodebase = $nodenumber;
+                $nodeidx  = 1;
+                $first_auth_nodeidx = undef;
+            }
+            else {
+                $first_auth_nodeidx = $nodeidx if (!defined 
$first_auth_nodeidx && $authorized);
+                $nodeidx++;
+            }
         }
     }
     &App::sub_exit() if ($App::trace);

Reply via email to