[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [2206] trunk/LedgerSMB.pm



Revision: 2206
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2206&view=rev
Author:   einhverfr
Date:     2008-07-10 11:57:13 -0700 (Thu, 10 Jul 2008)

Log Message:
-----------
Role lookups now working in the application code

Modified Paths:
--------------
    trunk/LedgerSMB.pm

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2008-07-10 18:35:15 UTC (rev 2205)
+++ trunk/LedgerSMB.pm	2008-07-10 18:57:13 UTC (rev 2206)
@@ -57,7 +57,7 @@
 This function returns 1 if the run mode is what is specified.  Otherwise
 returns 0.
 
-=item is_allowed_role(allowed_roles => @role_names)
+=item is_allowed_role({allowed_roles => @role_names})
 
 This function returns 1 if the user's roles include any of the roles in
 @role_names.  Currently it returns 1 when this is not found as well but when 
@@ -589,15 +589,15 @@
 
 # Keeping this here due to common requirements
 sub is_allowed_role {
-    my $self = shift @_;
-    my %args = @_;
-    my @roles = @{$args{allowed_roles}};
+    my ($self, $args) = @_;
+    my @roles = @{$args->{allowed_roles}};
     for my $role (@roles){
-        if (scalar(grep /^$role$/, $self->{_roles})){
+        my @roleset = grep m/^$role$/, @{$self->{_roles}};
+        if (scalar @roleset){
             return 1;
         }
     }
-    return 1; # TODO change to 0 when the role system is implmented
+    return 0; # TODO change to 0 when the role system is implmented
 }
 
 # This should probably be moved to User too...
@@ -723,6 +723,16 @@
         push @{ $self->{custom_db_fields}{ $ref->{extends} } },
           $ref->{field_def};
     }
+
+    # Adding role list to self 
+    $self->{_roles} = [];
+    $query = "select rolname from pg_roles 
+               where pg_has_role(SESSION_USER, 'USAGE')";
+    $sth = $dbh->prepare($query);
+    $sth->execute();
+    while (my @roles = $sth->fetchrow_array){
+        push @{$self->{_roles}}, $roles[0];
+    }
 }
 
 # Deprecated, only here for old code


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.