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

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



Revision: 3452
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3452&view=rev
Author:   einhverfr
Date:     2011-07-06 13:40:30 +0000 (Wed, 06 Jul 2011)

Log Message:
-----------
Importing user work flow now works as discussed on list

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

Modified: trunk/LedgerSMB/DBObject/User.pm
===================================================================
--- trunk/LedgerSMB/DBObject/User.pm	2011-07-06 07:13:04 UTC (rev 3451)
+++ trunk/LedgerSMB/DBObject/User.pm	2011-07-06 13:40:30 UTC (rev 3452)
@@ -137,7 +137,7 @@
     if (!$ref) { # Unsuccessful
         if ($@ =~ /No password/){
               $self->error($self->{_locale}->text('Password required'));
-        } elsif ($@ eq 'Duplicate User'){
+        } elsif ($@ =~/Duplicate user/){
               $self->{dbh}->rollback;
               return 8;
         }

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2011-07-06 07:13:04 UTC (rev 3451)
+++ trunk/LedgerSMB.pm	2011-07-06 13:40:30 UTC (rev 3452)
@@ -756,7 +756,7 @@
         $query_rc = $sth->execute(@call_args);
         if (!$query_rc){
               if ($args{continue_on_error} and  #  only for plpgsql exceptions
-                              ($self->{dbh}->errstr =~ /^P/)){
+                              ($self->{dbh}->state =~ /^P/)){
                     $@ = $self->{dbh}->errstr;
               } else {
                     $self->dberror($self->{dbh}->errstr . ": " . $query);
@@ -764,8 +764,13 @@
         }
     } else {
         $query_rc = $sth->execute();
-        if (!$query_rc and !$args{continue_on_error}){
-              $self->dberror($self->{dbh}->errstr . ':' . $query);
+        if (!$query_rc){
+              if ($args{continue_on_error} and  #  only for plpgsql exceptions
+                              ($self->{dbh}->state =~ /^P/)){
+                    $@ = $self->{dbh}->errstr;
+              } else {
+                    $self->dberror($self->{dbh}->errstr . ": " . $query);
+              }
         }
     }
    

Modified: trunk/UI/Admin/edit_user.html
===================================================================
--- trunk/UI/Admin/edit_user.html	2011-07-06 07:13:04 UTC (rev 3451)
+++ trunk/UI/Admin/edit_user.html	2011-07-06 13:40:30 UTC (rev 3452)
@@ -2,35 +2,56 @@
 <?lsmb PROCESS 'elements.html' ?>
 <div id="modify_user">
 	<div class="listtop">
-            <?lsmb IF user.user.username ?>
-                Editing User <?lsmb user.user.username ?>
-            <?lsmb ELSE?>
-                New User
-            <?lsmb END?>
+            <?lsmb 
+               IF user.user.import;
+                       text('Importing User');
+                       action = 'save_user';
+                ELSIF user.user.username;
+                      text('Editing User');
+                      action = 'edit_user';
+                ELSE;
+                      text('New User');
+                      action = 'save_user';
+                END ?>
         </div>
     
     <form method="POST" action="admin.pl">
-        <input type="hidden" name="action" value="<?lsmb IF user.user.username?>edit_user<?lsmb ELSE?>save_user<?lsmb END?>"/>
+        <input type="hidden" name="action" value="<?lsmb action ?>"/>
         <table>
 
-            <?lsmb UNLESS user.user.username?>
+            <?lsmb IF user.user.username?>
             <tr>
                 <td><?lsmb text('Username') ?></td>
                 <td>
+                    <?lsmb user.user.username;
+                    INCLUDE input element_data = {
+                            name  = 'username'
+                            type  = 'hidden'
+                            value = user.user.username
+                    } ?>
+                </td>
+            </tr>
+            
+            <?lsmb ELSE ?>
+            <tr>
+                <td><?lsmb text('Username') ?></td>
+                <td>
                     <input type="text" name="username" value="<?lsmb user.user.username ?>"/>
                 </td>
             </tr>
             <?lsmb END?>
+            <?lsmb UNLESS user.user.import ?>
             <tr>
                 <td><?lsmb text('Password') ?></td>
                 <td>
                     <input type="password" name="password" value="<?lsmb user.user.password ?>"/>
                 </td>
             </tr>
+            <?lsmb END ?>
             <tr>
                 <td><?lsmb text('Import') ?></td>
                 <?lsmb 
-                  IF import;
+                  IF user.user.import;
                       importc1 = 'CHECKED';
                       importc0 = '';
                   ELSE;
@@ -101,7 +122,7 @@
         <button type="submit" value="save_user"><?lsmb text('Save User') ?>
         </button>
     </form>
-    <?lsmb IF user.user.username?>
+    <?lsmb IF user.user.username AND user.user.import != 1 ?>
         <form name="location" method="POST" action="admin.pl">
             <?lsmb IF location?>
             <input type="hidden" name="location_id" value="<?lsmb location.id?>"/>

Modified: trunk/scripts/admin.pl
===================================================================
--- trunk/scripts/admin.pl	2011-07-06 07:13:04 UTC (rev 3451)
+++ trunk/scripts/admin.pl	2011-07-06 13:40:30 UTC (rev 3452)
@@ -75,7 +75,27 @@
     my $entity = $admin->save_user();
     if ($entity == 8){ # Duplicate user
           $request->{import} = 1;
-          __edit_page($request);
+          $request->{reimport} = 1;
+          my $template = LedgerSMB::Template->new( 
+                  user => $request->{_user}, 
+              template => 'Admin/edit_user', 
+              language => $request->{_user}->{language}, 
+                format => 'HTML', 
+                   path=>'UI'
+          );
+          my $dcsetting = LedgerSMB::Setting->new(base=>$request, copy=>'base');
+          my $default_country = $dcsetting->get('default_country'); 
+          $template->render(
+            {
+                user=>{user => $request, employee => $request}, 
+                countries=>$admin->get_countries(),
+                salutations=>$admin->get_salutations(),
+                contact_classes=>$admin->get_contact_classes(),
+                default_country => $dcsetting->{value},
+                admin => $admin,
+                stylesheet => $request->{stylesheet},
+            }
+          );
           return;
     }
     my $groups = $admin->get_roles();

Modified: trunk/sql/modules/admin.sql
===================================================================
--- trunk/sql/modules/admin.sql	2011-07-06 07:13:04 UTC (rev 3451)
+++ trunk/sql/modules/admin.sql	2011-07-06 13:40:30 UTC (rev 3452)
@@ -335,7 +335,7 @@
        t_is_role := found;
        t_is_user := admin__is_user(in_username);
 
-       IF t_is_role and t_is_user is false and in_import is false THEN
+       IF t_is_role is true and t_is_user is false and in_import is false THEN
           RAISE EXCEPTION 'Duplicate user';
         END IF;
 
@@ -344,7 +344,8 @@
                      ' WITH ENCRYPTED PASSWORD ' || quote_literal (in_password)
                      || $e$ valid until $e$ || 
                       quote_literal(now() + '1 day'::interval);
-        elsif in_password IS NULL and t_is_role is false THEN
+        elsif in_import is false AND t_is_user is false 
+              AND in_password IS NULL THEN
                 RAISE EXCEPTION 'No password';
         elsif  t_is_role is false THEN
             -- create an actual user
@@ -435,7 +436,8 @@
 
 REVOKE EXECUTE ON FUNCTION  admin__create_group(TEXT) FROM PUBLIC;
 
-CREATE OR REPLACE FUNCTION admin__delete_user(in_username TEXT) returns INT as $$
+CREATE OR REPLACE FUNCTION admin__delete_user
+(in_username TEXT, in_drop_role bool) returns INT as $$
     
     DECLARE
         stmt text;
@@ -448,13 +450,18 @@
         
             raise exception 'User not found.';
         ELSIF FOUND THEN
-    
-            stmt := ' drop user ' || quote_ident(a_user.username);
-            execute stmt;
-            
+            IF in_drop_role IS TRUE then 
+                stmt := ' drop user ' || quote_ident(a_user.username);
+                execute stmt;
+            END IF;    
             -- also gets user_connection
+            delete from user_preference where id = (
+                   select id from users where entity_id = a_user.entity_id);
+            delete from users where entity_id = a_user.entity_id;
+            delete from person where entity_id = a_user.entity_id;
+            delete from entity_employee where entity_id = a_user.entity_id;
             delete from entity where id = a_user.entity_id;
-                                        
+            return 1;
         END IF;   
     END;
     
@@ -462,9 +469,11 @@
 
 REVOKE EXECUTE ON FUNCTION admin__delete_user(in_username TEXT) from public;
 
-comment on function admin__delete_user(text) is $$ 
+comment on function admin__delete_user(text, bool) is $$ 
     Drops the provided user, as well as deletes the user configuration data.
 It leaves the entity and person references.
+
+If in_drop_role is set, it drops the role too.
 $$;
 
 CREATE OR REPLACE FUNCTION admin__delete_group (in_group_name TEXT) returns bool as $$
@@ -527,12 +536,9 @@
 --$$ language plpgsql;
 
 create or replace function admin__is_user (in_user text) returns bool as $$
-    DECLARE
-        pg_user pg_roles;
-    
     BEGIN
     
-        select * into pg_user from pg_roles where rolname = in_user;
+        PERFORM * from users where username = in_user;
         RETURN found;     
     
     END;


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