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

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



Revision: 4910
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4910&view=rev
Author:   einhverfr
Date:     2012-06-18 10:19:16 +0000 (Mon, 18 Jun 2012)
Log Message:
-----------
better handling of new user creation during setup

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Admin.pm
    trunk/LedgerSMB/Scripts/setup.pm
    trunk/UI/setup/new_user.html

Modified: trunk/LedgerSMB/DBObject/Admin.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Admin.pm	2012-06-18 10:08:45 UTC (rev 4909)
+++ trunk/LedgerSMB/DBObject/Admin.pm	2012-06-18 10:19:16 UTC (rev 4910)
@@ -45,96 +45,6 @@
 # an error given that it is not inherited.  An error will be raised in a way
 # which is more developer-friendly.   --CT
 
-
-=item save_user
-
-Saves a user optionally with location and contact data.
-
-If the password or import hash values is set, will not save contact or address
-information.
-
-This API is not fully documented at this time because it is expected that it will
-be broken down into more manageable chunks in future versions.  Please do not 
-count on the behavior.
-
-=cut
-
-sub save_user {
-
-    # This really should be split out into multiple routines for saving
-    # addresses, contact info, and the like.  It's hard to follow and document
-    # a long function like this.  Oh well, to be part of the next version 
-    # refactoring.  --CT
-    
-    my $self = shift @_;
-
-    if ($self->{username} =~ /[A-Z]/){ 
-        # Caps interfere with Pg permissions --CT
-        $self->error($self->{_locale}->text('Caps not allowed in usernames.'));
-    }
-
-    # I deleted some assignments which didn't play well with strict mode
-    # and by my reading probably broke things. --CT
-    $self->{control_code} = $self->{employeenumber};
-    my $employee = LedgerSMB::DBObject::Entity::Person::Employee->new(%$self);
-    if (!$employee->{entity_id}){
-         $employee->save();
-    }
-    
-    my $user = LedgerSMB::DBObject::User->new(base=>$self, copy=>'list',
-        merge=>[
-            'username',
-            'password',
-            'is_a_user',
-            'user_id',
-            'import',
-        ]
-    );
-    $user->{entity_id} = $employee->{entity_id};
-    if ($user->save() == 8){ # Duplicate User exception --CT
-        $user->{dbh}->rollback;
-        return 8;
-    }
-    $self->{user} = $user;
-    $self->{employee} = $employee;
-
-    if ($self->{password} or $self->{import}){
-       return $self->{dbh}->commit;
-    }
-    # The location handling here is really brittle.....
-    # In the future, we need to have a coding standard that says that for
-    # objects, the parent is responsible for the child, and accept a data tree
-    # instead of a sort of ravioli architecture.  --CT.
-    my $loc = LedgerSMB::DBObject::Location->new(base=>$self, copy=>'list', 
-        merge=>[
-            'address1',
-            'address2',
-            'city',
-            'state',
-            'zipcode',
-            'country',
-            'companyname',            
-        ]
-    );
-     
-    $loc->{type} = 'person';
-    $loc->save();
-    $employee->set_location($loc->{id});
-    $loc->(person=>$employee);
-    my $workphone = LedgerSMB::Contact->new(base=>$self);
-    my $homephone = LedgerSMB::Contact->new(base=>$self);
-    my $email = LedgerSMB::Contact->new(base=>$self);
-    
-    $workphone->set(person=>$employee, class=>1, contact=>$self->{workphone});
-    $homephone->set(person=>$employee, class=>11, contact=>$self->{homephone});
-    $email->set(person=>$employee, class=>12, contact=>$self->{email});
-    $workphone->save();
-    $homephone->save();
-    $email->save();
-    $self->{dbh}->commit;
-    
-}
-
 =item delete_user($delete_role)
 
 Deletes a user specified by $self->{user_id}.

Modified: trunk/LedgerSMB/Scripts/setup.pm
===================================================================
--- trunk/LedgerSMB/Scripts/setup.pm	2012-06-18 10:08:45 UTC (rev 4909)
+++ trunk/LedgerSMB/Scripts/setup.pm	2012-06-18 10:19:16 UTC (rev 4910)
@@ -746,16 +746,20 @@
 =cut
 
 sub save_user {
-    use LedgerSMB::DBObject::Admin;
     my ($request) = @_;
+    use LedgerSMB::DBObject::Entity::Person::Employee;
+    use LedgerSMB::DBObject::Entity::User;
     my $creds = LedgerSMB::Auth::get_credentials();
     $request->{dbh} = DBI->connect("dbi:Pg:dbname=$request->{database}",
                                    $creds->{login},
                                    $creds->{password});
     $request->{dbh}->{AutoCommit} = 0;
     $LedgerSMB::App_State::DBH = $request->{dbh};
-    my $user = LedgerSMB::DBObject::Admin->new({base => $request});
-    if (8 == $user->save_user){ # Told not to import but user exists in db
+    my $emp = LedgerSMB::DBObject::Entity::Person::Employee->new(%$request);
+    $emp->save;
+    $request->{entity_id} = $emp->entity_id;
+    my $user = LedgerSMB::DBObject::Entity::User->new(%$request);
+    if (8 == $user->create){ # Told not to import but user exists in db
         $request->{notice} = $request->{_locale}->text(
                        'User already exists. Import?'
         );

Modified: trunk/UI/setup/new_user.html
===================================================================
--- trunk/UI/setup/new_user.html	2012-06-18 10:08:45 UTC (rev 4909)
+++ trunk/UI/setup/new_user.html	2012-06-18 10:19:16 UTC (rev 4910)
@@ -84,6 +84,24 @@
 } ?>
 </div>
 <div class="input_row">
+<?lsmb INCLUDE input element_data = {
+    name = 'dob'
+   class = 'date'
+    type = 'text'
+    size = '10'
+   label = text('Date of Birth') #'
+} ?>
+</div>
+<div class="input_row">
+<?lsmb INCLUDE input element_data = {
+    name = 'ssn'
+   class = 'tax_id'
+    type = 'text'
+    size = '15'
+   label = text('Tax ID/SSN') #'
+} ?>
+</div>
+<div class="input_row">
 <?lsmb  countries.unshift({});
 INCLUDE select element_data = {
           options = countries

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