diff options
Diffstat (limited to 'LedgerSMB')
-rw-r--r-- | LedgerSMB/Admin.pm | 179 | ||||
-rwxr-xr-x | LedgerSMB/Session/DB.pm | 48 |
2 files changed, 203 insertions, 24 deletions
diff --git a/LedgerSMB/Admin.pm b/LedgerSMB/Admin.pm new file mode 100644 index 00000000..8e6c5dfd --- /dev/null +++ b/LedgerSMB/Admin.pm @@ -0,0 +1,179 @@ +package LedgerSMB::DBObject::Admin; + +use base LedgerSMB::DBObject; + +use LedgerSMB::DBObject::Location; +use LedgerSMB::DBObject::Employee; +use LedgerSMB::DBObject::Contact; + +sub save_user { + + my $self = shift @_; + + my $entity_id = shift @{ $self->exec_method( procname => "save_user" ) }; + $self->merge($entity_id); + + my $employee = LedgerSMB::DBObject::Employee->new(base=>$self, copy=>'list', + merge=>[ + 'salutation', + 'first_name', + 'last_name', + 'employeenumber', + ] + ); + + $employee->{entity_id} = $entity_id->{id}; + $employee->save_employee(); + + my $loc = LedgerSMB::DBObject::Location->new(base=>$self, copy=>'list', + merge=>[ + 'address1', + 'address2', + 'city', + 'state', + 'zipcode', + 'country', + 'companyname', + ] + ); + $loc->save_location(); + $loc->join_to_person(person=>$employee); + + + my $contact = LedgerSMB::DBObject::Contact->new(base=>$self, copy=>'list', + merge=>[ + 'workphone', + 'homephone', + 'email', + ] + ); + + $contact->save_homephone(person=>$employee); + $contact->save_workphone(person=>$employee); + $contact->save_email(person=>$employee); + + my $roles = $self->exec_method( procname => "all_roles" ); + my $user_roles = $self->exec_method(procname => "get_user_roles", args=>[ $self->{ modifying_user } ] ); + + my %active_roles; + for my $role (@{$user_roles}) { + + # These are our user's roles. + + $active_roles{$role} = 1; + } + + my $status; + + for my $role ( @{ $roles } ) { + + # These roles are were ALL checked on the page, so they're the active ones. + + if ($active_roles{$role} && $self->{incoming_roles}->{$role}) { + + # do nothing. + } + elsif ($active_roles{$role} && !($self->{incoming_roles}->{$role} )) { + + # do remove function + $status = $self->exec_method(procname => "remove_user_from_role", + args=>[ $self->{ modifying_user }, $role ] + } + elsif ($self->{incoming_roles}->{$role} and !($active_roles{$role} )) { + + # do add function + $status = $self->exec_method(procname => "add_user_to_role", + args=>[ $self->{ modifying_user }, $role ] + ); + } + } +} + +sub save_group { + + my $self = shift @_; + + my $existant = shift @{ $self->exec_method (procname=> "is_group", args=>[$self->{modifying_group}]) }; + + my $group = shift @{ $self->exec_method (procname=> "save_group") }; + + # first we grab all roles + + my $roles = $self->exec_method( procname => "all_roles" ); + my $user_roles = $self->exec_method(procname => "get_user_roles", + args=>[ $self->{ group_name } ] + ); + + my %active_roles; + for my $role (@{$user_roles}) { + + # These are our user's roles. + + $active_roles{$role} = 1; + } + + my $status; + + for my $role ( @{ $roles } ) { + + # These roles are were ALL checked on the page, so they're the active ones. + + if ($active_roles{$role} && $self->{incoming_roles}->{$role}) { + + # we don't need to do anything. + } + elsif ($active_roles{$role} && !($self->{incoming_roles}->{$role} )) { + + # do remove function + $status = $self->exec_method( + procname => "remove_group_from_role", + args=>[ $self->{ modifying_user }, $role ] + ); + } + elsif ($self->{incoming_roles}->{$role} and !($active_roles{$role} )) { + + # do add function + $status = $self->exec_method( + procname => "add_group_to_role", + args=>[ $self->{ modifying_user }, $role ] + ); + } + } +} + + +sub delete_user { + + my $self = shift @_; + + my $status = shift @{ $self->exec_method(procname=>'delete_user', args=>[$self->{modifying_user}]) }; + + if ($status) { + + return 1; + } else { + + my $error = LedgerSMB::Error->new("Delete user failed."); + $error->set_status($status); + return $error; + } +} + +sub delete_group { + + my $self = shift @_; + + my $status = shift @{ $self->exec_method(procname=>'delete_group', args=>[$self->{groupname}])}; + + if ($status) { + + return 1; + } else { + + my $error = LedgerSMB::Error->new("Delete group failed."); + $error->set_status($status); + return $error; + } +} + +1;
\ No newline at end of file diff --git a/LedgerSMB/Session/DB.pm b/LedgerSMB/Session/DB.pm index f94f107f..e4884015 100755 --- a/LedgerSMB/Session/DB.pm +++ b/LedgerSMB/Session/DB.pm @@ -41,17 +41,17 @@ sub session_check { my $checkQuery = $dbh->prepare( "SELECT u.username, s.transaction_id - FROM session as s, users as u - WHERE s.session_id = ? - AND s.users_id = u.id - AND s.last_used > now() - ?::interval" + FROM session as s, users as u + WHERE s.session_id = ? + AND s.users_id = u.id + AND s.last_used > now() - ?::interval" ); my $updateAge = $dbh->prepare( "UPDATE session - SET last_used = now(), - transaction_id = ? - WHERE session_id = ?;" + SET last_used = now(), + transaction_id = ? + WHERE session_id = ?;" ); #must be an integer @@ -150,9 +150,9 @@ sub session_create { # TODO Change this to use %myconfig my $deleteExisting = $dbh->prepare( "DELETE - FROM session - WHERE session.users_id = (select id from users where username = ?) - AND age(last_used) > ?::interval" + FROM session + WHERE session.users_id = (select id from users where username = ?) + AND age(last_used) > ?::interval" ); my $seedRandom = $dbh->prepare("SELECT setseed(?);"); @@ -162,9 +162,9 @@ sub session_create { my $createNew = $dbh->prepare( "INSERT INTO session (session_id, users_id, token, transaction_id) - VALUES(?, (SELECT id - FROM users - WHERE username = ?), ?, ?);" + VALUES(?, (SELECT id + FROM users + WHERE username = ?), ?, ?);" ); # this is assuming that $form->{login} is safe, which might be a bad assumption @@ -217,9 +217,9 @@ sub session_destroy { my $dbh = ${LedgerSMB::Sysconfig::GLOBALDBH}; my $deleteExisting = $dbh->prepare( " - DELETE FROM session - WHERE users_id = (select id from users where username = ?) - " ); + DELETE FROM session + WHERE users_id = (select id from users where username = ?) + " ); $deleteExisting->execute($login) || $form->dberror( @@ -243,9 +243,9 @@ sub password_check { my $fetchPassword = $dbh->prepare( "SELECT u.username, uc.password, uc.crypted_password - FROM users as u, users_conf as uc - WHERE u.username = ? - AND u.id = uc.id;" + FROM users as u, users_conf as uc + WHERE u.username = ? + AND u.id = uc.id;" ); $fetchPassword->execute($username) @@ -269,11 +269,11 @@ sub password_check { #password was good, convert to md5 password and null crypted my $updatePassword = $dbh->prepare( "UPDATE users_conf - SET password = md5(?), - crypted_password = null - FROM users - WHERE users_conf.id = users.id - AND users.username = ?;" + SET password = md5(?), + crypted_password = null + FROM users + WHERE users_conf.id = users.id + AND users.username = ?;" ); $updatePassword->execute( $password, $username ) |