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

SF.net SVN: ledger-smb:[2636] trunk



Revision: 2636
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2636&view=rev
Author:   einhverfr
Date:     2009-06-09 21:13:19 +0000 (Tue, 09 Jun 2009)

Log Message:
-----------
user management now works, needs some documentation

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Admin.pm
    trunk/LedgerSMB.pm
    trunk/UI/Admin/edit_user.html
    trunk/UI/lib/elements.html
    trunk/scripts/admin.pl
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Person.sql
    trunk/sql/modules/admin.sql

Modified: trunk/LedgerSMB/DBObject/Admin.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Admin.pm	2009-06-09 16:02:26 UTC (rev 2635)
+++ trunk/LedgerSMB/DBObject/Admin.pm	2009-06-09 21:13:19 UTC (rev 2636)
@@ -22,6 +22,9 @@
     my $entity = LedgerSMB::DBObject::Employee->new(base=>$self, copy=>'none');
     
     $entity->set(name=>$self->{first_name}." ".$self->{last_name});
+    if (!defined $self->{first_name} or !defined $self->{last_name}){
+       return;
+    }
     $entity->save();
     
     $self->{entity_id} = $entity->{entity};
@@ -94,57 +97,61 @@
     my $self = shift @_;
     
     my $user = LedgerSMB::DBObject::User->new( base=>$self, copy=>'all' );
-    
-    my $roles = $self->exec_method( procname => "admin__all_roles" );
-    my $user_roles = $self->exec_method(procname => "admin__get_user_roles", args=>[ $user->{id} ] );
-    
+    $user->get();
+    $self->{modifying_user} = $user->{user}->{username};
+    my @roles = $self->exec_method( funcname => "admin__get_roles" );
+    my @user_roles = $self->exec_method(funcname => "admin__get_roles_for_user");
     my %active_roles;
-    for my $role (@{ $user_roles }) {
+    for my $role (@user_roles) {
        
        # These are our user's roles.
+       print STDERR "Have $role->{rolname}\n";
         
-       $active_roles{$role} = 1;
+       $active_roles{"$role->{rolname}"} = 1;
     }
     
     my $status;
     
-    for my $role ( @{ $roles } ) {
-        
+    for my $r ( @roles) {
+        my $role = $r->{rolname};
+        my $reqrole = $role;
+        $reqrole =~ s/^lsmb_$self->{company}__//;
         # These roles are were ALL checked on the page, so they're the active ones.
         
-        if ( $active_roles{$role} && $self->{$role} ) {
+        if ( $active_roles{$role} && $self->{$reqrole} ) {
             
             # do nothing.
             ;
         }
-        elsif ($active_roles{$role} && !($self->{$role} )) {
+        elsif ($active_roles{$role} && !($self->{$reqrole} )) {
             
             # do remove function
-            $status = $self->exec_method(procname => "admin__remove_user_from_role",
+            $status = $self->call_procedure(procname => "admin__remove_user_from_role",
                 args=>[ $self->{ modifying_user }, $role ] );
         }
-        elsif ($self->{incoming_roles}->{$role} and !($active_roles{$role} )) {
+        elsif ($self->{$reqrole} and !($active_roles{$role} )) {
             
             # do add function
-            $status = $self->exec_method(procname => "admin__add_user_to_role",
+            $status = $self->call_procedure(procname => "admin__add_user_to_role",
                args=>[ $self->{ modifying_user }, $role ] 
             );
         }         
     }
+    $self->{dbh}->commit;
 }
 
 sub save_group {
     
      my $self = shift @_;
      
-     my $existant = shift @{ $self->exec_method (procname=> "is_group", args=>[$self->{modifying_group}]) };
+     my $existant = shift @{ $self->call_procedure (procname=> "is_group", args=>[$self->{modifying_group}]) };
      
-     my $group = shift @{ $self->exec_method (procname=> "save_group") };
+     my $group = shift @{ $self->exec_method (funcname=> "save_group") };
      
      # first we grab all roles
      
-     my $roles = $self->exec_method( procname => "admin__all_roles" );
-     my $user_roles = $self->exec_method(procname => "admin__get_user_roles", 
+     my $roles = $self->call_procedure( procname => "admin__all_roles" );
+     my $user_roles = $self->call_procedure(procname => "admin__get_user_roles", 
         args=>[ $self->{ group_name } ] 
     );
 
@@ -242,12 +249,11 @@
 sub get_roles {
     
     my $self = shift @_;
-#    print STDERR "attempting to get roles";
     my @s_rows = $self->call_procedure(procname=>'admin__get_roles');
     my @rows;
+    my $company = $self->{company};
     for my $role (@s_rows) {
-        my $rolname = $role->{'admin__get_roles'};
-        my $company = $self->{company};
+        my $rolname = $role->{'rolname'};
         $rolname =~ s/lsmb_${company}__//gi;
         push @rows, $rolname;
     }

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2009-06-09 16:02:26 UTC (rev 2635)
+++ trunk/LedgerSMB.pm	2009-06-09 21:13:19 UTC (rev 2636)
@@ -696,7 +696,7 @@
         
         print qq|Content-Type: text/html; charset=utf-8\n\n|;
         print "<head></head>";
-
+        $self->{msg} =~ s/\n/<br \/>\n/;
         print
           qq|<body><h2 class="error">Error!</h2> <p><b>$self->{msg}</b></body>|;
 
@@ -804,23 +804,24 @@
     }
 }
 
-# Deprecated, only here for old code
 sub dberror{
    my $self = shift @_;
    my $state_error = {
+        '42883' => $self->{_locale}->text('Internal Database Error'),
+	'42501' => $self->{_locale}->text('Access Denied'),
 	'42401' => $self->{_locale}->text('Access Denied'),
-	'42501' => $self->{_locale}->text('Access Denied'),
 	'22008' => $self->{_locale}->text('Invalid date/time entered'),
 	'22012' => $self->{_locale}->text('Division by 0 error'),
 	'22004' => $self->{_locale}->text('Required input not provided'),
-	'P0001' => $self->{_locale}->text('Error from Function:') . " " .
+	'23502' => $self->{_locale}->text('Required input not provided'),
+	'P0001' => $self->{_locale}->text('Error from Function:') . "\n" .
                     $self->{dbh}->errstr,
-	'23502' => $self->{_locale}->text('Required input not provided'),
    };
    print STDERR "Logging SQL State ".$self->{dbh}->state.", error ".
            $self->{dbh}->err . ", string " .$self->{dbh}->errstr . "\n";
-   if (scalar grep /^$self->{dbh}->state$/, keys %$state_error){
+   if (defined $state_error->{$self->{dbh}->state}){
        $self->error($state_error->{$self->{dbh}->state});
+       exit;
    }
    $self->error($self->{dbh}->state . ":" . $self->{dbh}->errstr);
 }

Modified: trunk/UI/Admin/edit_user.html
===================================================================
--- trunk/UI/Admin/edit_user.html	2009-06-09 16:02:26 UTC (rev 2635)
+++ trunk/UI/Admin/edit_user.html	2009-06-09 21:13:19 UTC (rev 2636)
@@ -229,9 +229,13 @@
                 </td>
             </tr>
             </form>
-        </table>
+        </table> 
         <form name="groups" method="POST" action="admin.pl">
-            <input type="hidden" name="action" value="save_groups"/>
+            <?lsmb PROCESS input element_data = {
+               type="hidden"
+               name="user_id"
+               value= user.user.id 
+           } ?>
             <table>
                 <!-- Groups section -->
                 <tr>
@@ -241,13 +245,17 @@
                 <tr>
                 <?lsmb END?>
                     <td>
-                        <input type="checkbox" name="<?lsmb loop.index?>" value="1" 
-                            <?lsmb FOREACH rolname IN user.roles ?>
-                                <?lsmb IF role == rolname?>
-                                    checked
-                                <?lsmb END?>
-                            <?lsmb END?> />
-                        <?lsmb role?>
+                        <?lsmb rolcheck = undef; 
+                           IF user.roles.grep(role).size;
+                              rolcheck = "checked";
+                           END ?>
+                        <?lsmb PROCESS input element_data = {
+                               type = "checkbox"
+                               label = role
+                               value = 1
+                               name = role
+                               checked = rolcheck
+                         }, label_pos = 1 ?>
                     </td>
                 <?lsmb END?>
                 </tr>
@@ -255,8 +263,12 @@
         
             <table>
                 <tr>
-                    <td><button value="groups">Save Groups</button></td>
-                    <td><button name="method" value="cancel">Cancel</td>
+                    <td><?lsmb PROCESS button element_data = {
+                          text = text('Save Groups') #'
+                          class = "submit"
+                          name = "action"
+                          value = "save_user"
+                    } ?></td>
                 </tr>
             </table>
         </form>   

Modified: trunk/UI/lib/elements.html
===================================================================
--- trunk/UI/lib/elements.html	2009-06-09 16:02:26 UTC (rev 2635)
+++ trunk/UI/lib/elements.html	2009-06-09 21:13:19 UTC (rev 2636)
@@ -40,6 +40,7 @@
 
 <?lsmb # INPUT ELEMENT ?>
 <?lsmb BLOCK input ?>
+  <?lsmb IF label_pos != 1 and label_pos != -1; label_pos = -1; END ?>
   <?lsmb IF element_data  # Only process element if one exists. ?>
   	<?lsmb
 	    input_defaults = {}  # Some inputs have no defaults, so make sure everything is empty to start with.
@@ -74,8 +75,13 @@
 	  <?lsmb PROCESS custom_attributes  # Process custom attributes.
 	    custom_attribute_data=element_data.attributes 
 	  ?>
+          <?lsmb IF label_pos == -1 ?>
 	  <?lsmb PROCESS auto_label  # Process element label. ?>
+          <?lsmb END ?>
 	  <input<?lsmb all_attributes ?><?lsmb all_custom_attributes ?> />
+          <?lsmb IF label_pos == 1 ?>
+	  <?lsmb PROCESS auto_label  # Process element label. ?>
+          <?lsmb END ?>
   <?lsmb END ?>
 <?lsmb END ?>
 

Modified: trunk/scripts/admin.pl
===================================================================
--- trunk/scripts/admin.pl	2009-06-09 16:02:26 UTC (rev 2635)
+++ trunk/scripts/admin.pl	2009-06-09 21:13:19 UTC (rev 2636)
@@ -41,9 +41,6 @@
                 contact_classes=>$admin->get_contact_classes(),
                 locations=>$location->get_all($user_obj->{entity_id},"person"),
             };
-    open (FOO,">/tmp/dump.txt");
-    print STDERR Dumper($template_data->{contact_classes});
-    print FOO Dumper($template_data);
     
     for my $key (keys(%{$otd})) {
         
@@ -67,6 +64,7 @@
     
     my $groups = $admin->get_roles();
     my $entity = $admin->save_user();
+    $admin->save_roles();
     __edit_page($admin);
 }
 
@@ -128,23 +126,10 @@
                 contact_classes=>$admin->get_contact_classes(),
                 locations=>$location->get_all($user_obj->{entity_id},"person"),
             };
-    open (FOO,">/tmp/dump.txt");
-    print STDERR Dumper($template_data->{contact_classes});
-    print FOO Dumper($template_data);
-    if ($request->type() eq 'POST') {
-        
-        $admin->save_user();
-        $admin->save_roles();
-        $template->render($template_data);
+    if ($request->{location_id}) {
+        $template_data->{location} = $location->get($request->{location_id});
     }
-    else {
-#        print STDERR Dumper($user);
-#        print STDERR Dumper(@all_roles);
-        if ($request->{location_id}) {
-            $template_data->{location} = $location->get($request->{location_id});
-        }
-        $template->render($template_data);
-    }
+    $template->render($template_data);
 }
 
 sub edit_group {
@@ -361,9 +346,7 @@
         # zipcode
         # country
         # u_id isn't an entity_it, though.
-        print STDERR "Attempting to save location...\n";
         $location->{user_id} = $user_obj->{user}->{entity_id};
-        print STDERR $location->{user_id}."\n";
         my $id = $location->save("person");
         # Done and done.
         

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2009-06-09 16:02:26 UTC (rev 2635)
+++ trunk/sql/Pg-database.sql	2009-06-09 21:13:19 UTC (rev 2636)
@@ -289,6 +289,7 @@
   person_id integer not null references person(id) ON DELETE CASCADE,
   contact_class_id integer references contact_class(id) not null,
   contact text check(contact ~ '[[:alnum:]_]') not null,
+  description text,
   PRIMARY KEY (person_id,contact_class_id,contact));
   
 COMMENT ON TABLE person_to_contact IS $$ To keep track of the relationship between multiple contact methods and a single individual $$;

Modified: trunk/sql/modules/Person.sql
===================================================================
--- trunk/sql/modules/Person.sql	2009-06-09 16:02:26 UTC (rev 2635)
+++ trunk/sql/modules/Person.sql	2009-06-09 21:13:19 UTC (rev 2636)
@@ -112,7 +112,7 @@
 DECLARE out_row RECORD;
 BEGIN
 	FOR out_row IN 
-		SELECT cc.class, cc.id, c.contact
+		SELECT cc.class, cc.id, c.description, c.contact
 		FROM person_to_contact c
 		JOIN contact_class cc ON (c.contact_class_id = cc.id)
 		JOIN person p ON (c.person_id = p.id)

Modified: trunk/sql/modules/admin.sql
===================================================================
--- trunk/sql/modules/admin.sql	2009-06-09 16:02:26 UTC (rev 2635)
+++ trunk/sql/modules/admin.sql	2009-06-09 21:13:19 UTC (rev 2636)
@@ -10,7 +10,7 @@
 
 create table lsmb_roles (
     
-    user_id integer not null references users,
+    user_id integer not null references users(id),
     role text not null
     
 );
@@ -39,7 +39,8 @@
         stmt := 'GRANT '|| quote_ident(in_role) ||' to '|| quote_ident(in_username);
         
         EXECUTE stmt;
-        insert into lsmb_roles (user_id, role) values (in_username, in_role);
+        insert into lsmb_roles (user_id, role) 
+        SELECT id, in_role from users where username = in_username;
         return 1;
     END;
     


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