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

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



Revision: 2587
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2587&view=rev
Author:   einhverfr
Date:     2009-05-06 18:41:38 +0000 (Wed, 06 May 2009)

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

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

Modified: trunk/LedgerSMB/DBObject/Admin.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Admin.pm	2009-05-05 17:15:13 UTC (rev 2586)
+++ trunk/LedgerSMB/DBObject/Admin.pm	2009-05-06 18:41:38 UTC (rev 2587)
@@ -5,7 +5,7 @@
 use LedgerSMB::Location;
 use LedgerSMB::DBObject::Employee;
 use LedgerSMB::Contact;
-use LedgerSMB::Entity;
+use LedgerSMB::DBObject::Employee;
 
 #[18:00:31] <aurynn> I'd like to split them employee/user and roles/prefs
 #[18:00:44] <aurynn> edit/create employee and add user features if needed.
@@ -19,24 +19,17 @@
     
     my $self = shift @_;
     
-    my $entity = LedgerSMB::DBObject::Entity->new(base=>$self, copy=>'none');
+    my $entity = LedgerSMB::DBObject::Employee->new(base=>$self, copy=>'none');
     
     $entity->set(name=>$self->{first_name}." ".$self->{last_name});
     $entity->save();
     
-    $self->{entity_id} = $entity->{id};
+    $self->{entity_id} = $entity->{entity};
     
     
-    my $user_id = shift @{ $self->exec_method( procname => "admin__save_user" ) };
+    my $user_id = shift @{ $self->exec_method( funcname => "admin__save_user" ) };
     $self->merge($user_id);
     
-    my $person = LedgerSMB::DBObject::Person->new( base=>$self, copy=>'list',     
-        merge=>[
-            'salutation',
-            'first_name',
-            'last_name',
-        ]
-    );
     my $employee = LedgerSMB::DBObject::Employee->new( base=>$self, copy=>'list',
         merge=>[
             'salutation',
@@ -48,7 +41,11 @@
     
     $employee->{entity_id} = $entity_id->{id};    
     $employee->save();
-        
+
+    if ($self->{password}){
+       return;
+    }
+ 
     my $loc = LedgerSMB::DBObject::Location->new(base=>$self, copy=>'list', 
         merge=>[
             'address1',
@@ -271,4 +268,4 @@
     my $code = $sth->execute();
     return $sth->fetchall_arrayref({});
 }
-1;
\ No newline at end of file
+1;

Modified: trunk/LedgerSMB/DBObject/Employee.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Employee.pm	2009-05-05 17:15:13 UTC (rev 2586)
+++ trunk/LedgerSMB/DBObject/Employee.pm	2009-05-06 18:41:38 UTC (rev 2587)
@@ -13,7 +13,8 @@
 sub save {
    my ($self) = @_;
    $self->set_entity_class();
-   $self->{entity_id} = $self->exec_method(funcname => 'person_save');
+   my ($ref) = $self->exec_method(funcname => 'person__save');
+   $self->{entity} = $ref->{'person__save'};
    $self->exec_method(funcname => 'employee__save');
    $self->{dbh}->commit;
 }

Modified: trunk/UI/Admin/edit_user.html
===================================================================
--- trunk/UI/Admin/edit_user.html	2009-05-05 17:15:13 UTC (rev 2586)
+++ trunk/UI/Admin/edit_user.html	2009-05-06 18:41:38 UTC (rev 2587)
@@ -17,12 +17,18 @@
 
             <?lsmb UNLESS user.user.username?>
             <tr>
-                <td>Username</td>
+                <td><?lsmb text('Username') ?></td>
                 <td>
-                    <input type="textarea" name="username" value="<?lsmb user.user.username?>"/>
+                    <input type="password" name="username" value="<?lsmb user.user.username ?>"/>
                 </td>
             </tr>
             <?lsmb END?>
+            <tr>
+                <td><?lsmb text('Password') ?></td>
+                <td>
+                    <input type="text" name="password" value="<?lsmb user.user.password ?>"/>
+                </td>
+            </tr>
             
             <tr>
                 <td>
@@ -35,26 +41,27 @@
             </tr>
             
             <tr>
-                <td>First Name</td>
+                <td><?lsmb ('First Name') ?></td>
                 <td>
-                    <input type="textarea" name="first_name" value="<?lsmb user.employee.first_name?>"/>
+                    <input type="text" name="first_name" value="<?lsmb user.employee.first_name?>"/>
                 </td>
             </tr>
             
             <tr>
-                <td>Last Name</td>
+                <td><?lsmb text('Last Name') ?></td>
                 <td>
                     <input type="textarea" name="last_name" value="<?lsmb user.employee.last_name?>"/>
                 </td>
             </tr>
             <tr>
-                <td>Employee #</td>
+                <td><?lsmb text('Employee No.') ?></td>
                 <td>
                     <input type="textarea" name="employeenumber" value="<?lsmb user.employee.employeenumber?>"/>
                 </td>
             </tr>
         </table>
-        <input type="submit" value="Save User" />
+        <button type="submit" value="save_user"><?lsmb text('Save User') ?>
+        </button>
     </form>
     <?lsmb IF user.user.username?>
         <form name="location" method="POST" action="admin.pl">

Modified: trunk/scripts/admin.pl
===================================================================
--- trunk/scripts/admin.pl	2009-05-05 17:15:13 UTC (rev 2586)
+++ trunk/scripts/admin.pl	2009-05-06 18:41:38 UTC (rev 2587)
@@ -74,7 +74,7 @@
         
         # do the save stuff
         
-        my $entity = $admin->save_new_user();
+        my $entity = $admin->save_user();
         
         my $template = LedgerSMB::Template->new( user => $user, 
     	template => 'Admin/edit_user', language => $user->{ language }, 

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2009-05-05 17:15:13 UTC (rev 2586)
+++ trunk/sql/Pg-database.sql	2009-05-06 18:41:38 UTC (rev 2587)
@@ -573,7 +573,7 @@
 -- 
 -- The view below is broken.  Disabling for now.
 CREATE VIEW employee AS
- SELECT s.salutation, p.first_name, p.last_name, ee.person_id, ee.entity_id, ee.startdate, ee.enddate, ee."role", ee.ssn, ee.sales, ee.manager_id, ee.employeenumber, ee.dob
+ SELECT s.salutation, p.first_name, p.last_name, ee.entity_id, ee.startdate, ee.enddate, ee."role", ee.ssn, ee.sales, ee.manager_id, ee.employeenumber, ee.dob
    FROM person p
    JOIN entity_employee ee USING (entity_id)
    LEFT JOIN salutation s ON p.salutation_id = s.id;

Modified: trunk/sql/modules/Employee.sql
===================================================================
--- trunk/sql/modules/Employee.sql	2009-05-05 17:15:13 UTC (rev 2586)
+++ trunk/sql/modules/Employee.sql	2009-05-06 18:41:38 UTC (rev 2587)
@@ -1,9 +1,8 @@
 -- VERSION 1.3.0
-BEGIN;
 
 
 CREATE OR REPLACE FUNCTION employee__save(
-    in_person int, in_entity int, in_startdate date, in_enddate date,
+    in_entity int, in_startdate date, in_enddate date,
 	in_role text, in_sales boolean, in_dob date, 
     in_managerid integer, in_employeenumber text
 )
@@ -13,30 +12,37 @@
         e_ent entity_employee;
         e entity;
         p person;
+        t_startdate date;
     BEGIN
-        select * into e from entity where id = in_entity and entity_class = 3;
+        IF in_startdate IS NULL THEN
+             t_startdate := now()::date;
+        ELSE
+             t_startdate := in_startdate;
+        END IF;
+
+        select * into e from entity where id = in_entity;
         
         IF NOT FOUND THEN
             RAISE EXCEPTION 'No entity found for ID %', in_entity;
         END IF;
         
-        select * into p from person where id = in_person;
+        select * into p from person where entity_id = in_entity;
         
         IF NOT FOUND THEN
-            RAISE EXCEPTION 'No person found for ID %', in_perso;
+            RAISE EXCEPTION 'No person found for ID %', in_entity;
         END IF;
         
         -- Okay, we're good. Check to see if we update or insert.
         
-        select * into e_ent from entity_employee where person_id = in_person 
-            and entity_id = in_entity;
+        select * into e_ent from entity_employee where 
+            entity_id = in_entity;
             
         IF NOT FOUND THEN
             -- insert.
             
-            INSERT INTO entity_employee (person_id, entity_id, startdate, 
+            INSERT INTO entity_employee (entity_id, startdate, 
                 enddate, role, sales, manager_id, employeenumber, dob)
-            VALUES (in_person, in_entity, in_startdate, in_enddate, in_role, 
+            VALUES (in_entity, t_startdate, in_enddate, in_role, 
                 in_sales, in_managerid, in_employeenumber, in_dob);
             
             return in_entity;
@@ -46,7 +52,7 @@
             
             UPDATE entity_employee
             SET
-                startdate = in_startdate,
+                startdate = t_startdate,
                 enddate = in_enddate,
                 role = in_role,
                 sales = in_sales,
@@ -54,9 +60,7 @@
                 employeenumber = in_employeenumber,
                 dob = in_dob
             WHERE
-                entity_id = in_entity
-            AND
-                person_id = in_person;
+                entity_id = in_entity;
                 
             return in_entity;
         END IF;
@@ -177,5 +181,3 @@
     
 $$ language 'sql';
 
-COMMIT;
-

Modified: trunk/sql/modules/Person.sql
===================================================================
--- trunk/sql/modules/Person.sql	2009-05-05 17:15:13 UTC (rev 2586)
+++ trunk/sql/modules/Person.sql	2009-05-06 18:41:38 UTC (rev 2587)
@@ -44,6 +44,7 @@
         
         INSERT INTO person (salutation_id, first_name, last_name, entity_id)
 	VALUES (in_salutation_id, in_first_name, in_last_name, e_id);
+
         RETURN e_id;
     
     END IF;

Modified: trunk/sql/modules/admin.sql
===================================================================
--- trunk/sql/modules/admin.sql	2009-05-05 17:15:13 UTC (rev 2586)
+++ trunk/sql/modules/admin.sql	2009-05-06 18:41:38 UTC (rev 2587)
@@ -353,7 +353,7 @@
             
             execute 'CREATE USER ' || quote_ident( in_username ) || 
                      ' WITH ENCRYPTED PASSWORD ' || quote_literal (in_password)
-                     || $e$ valid until now() + '1 day'::interval $e$;
+                     || $e$ valid until $e$ || quote_literal(now() + '1 day'::interval);
             
             return v_user_id ;
 


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