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

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



Revision: 2964
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2964&view=rev
Author:   einhverfr
Date:     2010-03-15 04:22:40 +0000 (Mon, 15 Mar 2010)

Log Message:
-----------
User management fixes

Modified Paths:
--------------
    trunk/LedgerSMB/Contact.pm
    trunk/LedgerSMB/DBObject/Admin.pm
    trunk/LedgerSMB/DBObject/Employee.pm
    trunk/LedgerSMB/DBObject/User.pm
    trunk/LedgerSMB/Location.pm
    trunk/UI/Admin/edit_user.html
    trunk/scripts/admin.pl
    trunk/sql/modules/Employee.sql
    trunk/sql/modules/Roles.sql
    trunk/sql/modules/admin.sql

Modified: trunk/LedgerSMB/Contact.pm
===================================================================
--- trunk/LedgerSMB/Contact.pm	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/LedgerSMB/Contact.pm	2010-03-15 04:22:40 UTC (rev 2964)
@@ -85,4 +85,4 @@
     return $results;
 }
 
-1;
\ No newline at end of file
+1;

Modified: trunk/LedgerSMB/DBObject/Admin.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Admin.pm	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/LedgerSMB/DBObject/Admin.pm	2010-03-15 04:22:40 UTC (rev 2964)
@@ -19,29 +19,9 @@
     
     my $self = shift @_;
     
-    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};
-    
-    
-    my ($user_id) = $self->exec_method( funcname => "admin__save_user" );
     $self->{user_id} = $user_id->{admin__save_user};
     
-    my $employee = LedgerSMB::DBObject::Employee->new( base=>$self, copy=>'list',
-        merge=>[
-            'salutation',
-            'first_name',
-            'last_name',
-            'employeenumber',
-            'country_id',
-        ]    
-    );
+    my $employee = LedgerSMB::DBObject::Employee->new( base=>$self);
     
     $employee->{entity_id} = $entity_id->{id};    
     $employee->save();
@@ -55,10 +35,10 @@
             'user_id',
         ]
     );
-    $user->get();
+    $user->{entity_id} = $employee->{entity_id};
+    $user->save();
     $self->{user} = $user;
     $self->{employee} = $employee;
-    $self->debug({file => '/tmp/user11'});
 
     if ($self->{password}){
        return;
@@ -75,7 +55,7 @@
             'companyname',            
         ]
     );
-    
+     
     $loc->save();
     $employee->set_location($loc->{id});
     $loc->(person=>$employee);
@@ -135,11 +115,8 @@
     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->{$reqrole} ) {
-            
             # do nothing.
             ;
         }
@@ -147,13 +124,13 @@
             
             # do remove function
             $status = $self->call_procedure(procname => "admin__remove_user_from_role",
-                args=>[ $self->{ modifying_user }, $role ] );
+                args=>[ $self->{modifying_user}, $role ] );
         }
         elsif ($self->{$reqrole} and !($active_roles{$role} )) {
             
             # do add function
             $status = $self->call_procedure(procname => "admin__add_user_to_role",
-               args=>[ $self->{ modifying_user }, $role ] 
+               args=>[ $self->{modifying_user}, $role ] 
             );
         }         
     }
@@ -274,7 +251,6 @@
     my $company = $self->{company};
     for my $role (@s_rows) {
         my $rolname = $role->{'rolname'};
-        $rolname =~ s/lsmb_${company}__//gi;
         push @rows, $rolname;
     }
     return ..hidden..;

Modified: trunk/LedgerSMB/DBObject/Employee.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Employee.pm	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/LedgerSMB/DBObject/Employee.pm	2010-03-15 04:22:40 UTC (rev 2964)
@@ -14,7 +14,7 @@
    my ($self) = @_;
    $self->set_entity_class();
    my ($ref) = $self->exec_method(funcname => 'person__save');
-   $self->{entity} = $ref->{'person__save'};
+   $self->{entity_id} = $ref->{'person__save'};
    $self->exec_method(funcname => 'employee__save');
    $self->{dbh}->commit;
 }

Modified: trunk/LedgerSMB/DBObject/User.pm
===================================================================
--- trunk/LedgerSMB/DBObject/User.pm	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/LedgerSMB/DBObject/User.pm	2010-03-15 04:22:40 UTC (rev 2964)
@@ -122,13 +122,11 @@
 sub save {
     
     my $self = shift @_;
-    
     my $user = $self->get();
     
     
     # doesn't check for the password - that's done in the sproc.
-    my ($ref) = $self->exec_method(funcname=>'admin__save_user', 
-        args=>[$user->{id}, $self->{username}, $self->{password}] ); 
+    my ($ref) = $self->exec_method(funcname=>'admin__save_user'); 
     ($self->{id}) = values %$ref;
     if (!$self->{id}) {
         
@@ -144,6 +142,9 @@
     if ($id){
         $self->{user_id} = $id;
     }
+    if (!defined $self->{user_id}){
+       return;
+    }
     my ($user) = $self->exec_method(
         funcname=>'admin__get_user',
         );
@@ -186,7 +187,6 @@
     for my $role (@roles) {
         my $rolname = $role->{'admin__get_roles_for_user'};
         my $company = $self->{company};
-        $rolname =~ s/lsmb_${company}__//gi;
         push @rolstore, $rolname; # Only one key=>value pair
     }
     $self->{roles} = ..hidden..;

Modified: trunk/LedgerSMB/Location.pm
===================================================================
--- trunk/LedgerSMB/Location.pm	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/LedgerSMB/Location.pm	2010-03-15 04:22:40 UTC (rev 2964)
@@ -82,4 +82,4 @@
       $self->exec_method( procname => 'location_list_all' );
 }
 
-1;
\ No newline at end of file
+1;

Modified: trunk/UI/Admin/edit_user.html
===================================================================
--- trunk/UI/Admin/edit_user.html	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/UI/Admin/edit_user.html	2010-03-15 04:22:40 UTC (rev 2964)
@@ -283,7 +283,7 @@
                           text = text('Save Groups') #'
                           class = "submit"
                           name = "action"
-                          value = "save_user"
+                          value = "save_roles"
                     } ?></td>
                 </tr>
             </table>

Modified: trunk/scripts/admin.pl
===================================================================
--- trunk/scripts/admin.pl	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/scripts/admin.pl	2010-03-15 04:22:40 UTC (rev 2964)
@@ -1,5 +1,6 @@
 #!/usr/bin/perl
 package LedgerSMB::Scripts::admin;
+use strict;
 
 require 'lsmb-request.pl';
 
@@ -17,17 +18,15 @@
     
     
     my ($request, $otd) = @_;
-    
     # otd stands for Other Template Data.
     my $dcsetting = LedgerSMB::Setting->new(base=>$request, copy=>'base');
     my $default_country = $dcsetting->get('default_country'); 
     my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'list', merge =>['user_id']);
+    my @all_roles = $admin->get_roles();
     my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'list', merge=>['user_id','company']);
     $user_obj->{company} = $request->{company};
     $user_obj->get($request->{user_id});
-
-    my @all_roles = $admin->get_roles();
-    
+    my $user = $request->{_user};
     my $template = LedgerSMB::Template->new( 
         user => $request->{_user}, 
         template => 'Admin/edit_user', 
@@ -45,9 +44,9 @@
                 salutations=>$admin->get_salutations(),
                 contact_classes=>$admin->get_contact_classes(),
                 locations=>$location->get_all($user_obj->{entity_id},"person"),
-                stylesheet => $request->{stylesheet},
                 default_country => $dcsetting->{value},
                 admin => $admin,
+                stylesheet => $request->{stylesheet},
             };
     
     for my $key (keys(%{$otd})) {
@@ -55,7 +54,7 @@
         $template_data->{$key} = $otd->{$key};
     }
     my $template = LedgerSMB::Template->new( 
-        user => $user, 
+        user => $request->{_user}, 
         template => 'Admin/edit_user', 
         language => $user->{language}, 
         format => 'HTML', 
@@ -70,13 +69,21 @@
     
     my $sal = $admin->get_salutations();
     
+    my $entity = $admin->save_user();
     my $groups = $admin->get_roles();
-    my $entity = $admin->save_user();
-    $admin->save_roles();
     $admin->{stylesheet} = $request->{stylesheet};
     __edit_page($admin);
 }
 
+sub save_roles {
+    my ($request, $admin) = @_;
+    my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
+    $admin->{stylesheet} = $request->{stylesheet};
+    $admin->save_roles();
+    __edit_page($admin);
+}
+
+
 sub new_user {
     
     # uses the same page as create_user, only pre-populated.
@@ -87,6 +94,7 @@
     my $sal = $admin->get_salutations();
     
     my $groups = $admin->get_roles();
+    my $user = $request->{_user};
     
     $logger->debug("scripts/admin.pl new_user: \$user = " . Data::Dumper::Dumper($user));
     
@@ -121,6 +129,7 @@
     my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
     
     my $all_roles = $admin->role_list();
+    my $user = $request->{_user};
     
     my $template = LedgerSMB::Template->new( 
         user => $user, 
@@ -154,6 +163,7 @@
     
     my ($request) = @_;
     my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
+    my $user = $request->{_user};
     
     my $all_roles = $admin->get_roles();
     my $template = LedgerSMB::Template->new( 
@@ -180,6 +190,7 @@
 sub delete_group {
     
     my ($request) = @_;
+    my $user = $request->{_user};
     
     my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
     
@@ -201,6 +212,7 @@
 sub delete_user {
     
     my ($request) = @_;
+    my $user = $request->{_user};
     
     my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'all');
     
@@ -222,6 +234,7 @@
 sub new_group {
     
     my ($request) = @_;
+    my $user = $request->{_user};
     
     my $template = LedgerSMB::Template->new( user=>$user, 
         template=>'Admin/new_group', language=>$user->{language},
@@ -243,6 +256,7 @@
 sub main {
     
     my ($request) = @_;
+    my $user = $request->{_user};
     
     my $template;
     
@@ -312,6 +326,7 @@
 sub save_location {
     
     my $request = shift @_;
+    my $user = $request->{_user};
     
     # Only ever a post, but check anyway
     if ($request->type eq "POST") {
@@ -407,7 +422,7 @@
     );
     my $columns;
     @$columns = qw(id username first_name last_name ssn dob edit);
-    $column_headers = {
+    my $column_headers = {
         id         => $request->{_locale}->text('ID'),
         username   => $request->{_locale}->text('Username'),
         first_name => $request->{_locale}->text('First Name'),
@@ -451,7 +466,7 @@
     );
     my $columns;
     @$columns = qw(id username last_used locks_active drop);
-    $column_headers = {
+    my $column_headers = {
         id         => $request->{_locale}->text('ID'),
         username   => $request->{_locale}->text('Username'),
         last_used => $request->{_locale}->text('Last Used'),

Modified: trunk/sql/modules/Employee.sql
===================================================================
--- trunk/sql/modules/Employee.sql	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/sql/modules/Employee.sql	2010-03-15 04:22:40 UTC (rev 2964)
@@ -15,9 +15,7 @@
 		role = in_role,
 		ssn = in_ssn,
 		manager_id = in_manager_id,
-		employeenumber = in_employee_number,
-		person_id = (select id FROM person 
-			WHERE entity_id = in_entity_id)
+		employeenumber = in_employee_number
 	WHERE entity_id = in_entity_id;
 
 	out_id = in_entity_id;
@@ -25,13 +23,12 @@
 	IF NOT FOUND THEN
 		INSERT INTO entity_employee 
 			(startdate, enddate, dob, role, ssn, manager_id, 
-				employeenumber, entity_id, person_id)
+				employeenumber, entity_id)
 		VALUES
 			(coalesce(in_start_date, now()::date), in_end_date, 
                                 in_dob, in_role, in_ssn,
-				in_manager_id, in_employee_number, in_entity_id,
-				(SELECT id FROM person 
-				WHERE entity_id = in_entity_id));
+				in_manager_id, in_employee_number, 
+                                in_entity_id);
 		RETURN in_entity_id;
 	END IF;
 END;

Modified: trunk/sql/modules/Roles.sql
===================================================================
--- trunk/sql/modules/Roles.sql	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/sql/modules/Roles.sql	2010-03-15 04:22:40 UTC (rev 2964)
@@ -1428,7 +1428,8 @@
 
 CREATE ROLE "lsmb_<?lsmb dbname ?>__users_manage"
 WITH INHERIT NOLOGIN
-IN ROLE "lsmb_<?lsmb dbname ?>__contact_read";
+IN ROLE "lsmb_<?lsmb dbname ?>__contact_edit",
+"lsmb_<?lsmb dbname ?>__contact_create";
 
 GRANT SELECT ON role_view TO "lsmb_<?lsmb dbname ?>__users_manage";
 GRANT EXECUTE ON FUNCTION  admin__add_user_to_role(TEXT, TEXT) 

Modified: trunk/sql/modules/admin.sql
===================================================================
--- trunk/sql/modules/admin.sql	2010-03-15 00:15:45 UTC (rev 2963)
+++ trunk/sql/modules/admin.sql	2010-03-15 04:22:40 UTC (rev 2964)
@@ -224,10 +224,6 @@
     BEGIN
         
         select * into a_user from users where id = in_user_id;
-        IF NOT FOUND THEN
-            RAISE EXCEPTION 'cannot find user %', in_user_id;
-        END IF;
-        
         return next a_user;
         return;
     
@@ -549,8 +545,7 @@
 BEGIN
     t_dbname := current_database();
     FOR v_rol in 
-        SELECT 
-            *
+        SELECT *
         from 
             pg_roles
         where 


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