From 9af6ae6be1019ea656a101dfe7b66709f82f68ca Mon Sep 17 00:00:00 2001 From: aurynn_cmd Date: Wed, 17 Oct 2007 23:16:35 +0000 Subject: Serious updates to the Admin controller; Creation of a User controller/object - I would like to use this to save/load roles, as well. Creation of Person stored procs, Entity stored procs. Serious updates to the employee stored procs. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1778 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/DBObject/Admin.pm | 53 ++++++++++++++++++++++++++++++++++++++------- LedgerSMB/DBObject/User.pm | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 LedgerSMB/DBObject/User.pm (limited to 'LedgerSMB/DBObject') diff --git a/LedgerSMB/DBObject/Admin.pm b/LedgerSMB/DBObject/Admin.pm index e09e1214..51620c47 100644 --- a/LedgerSMB/DBObject/Admin.pm +++ b/LedgerSMB/DBObject/Admin.pm @@ -6,24 +6,39 @@ use LedgerSMB::Location; use LedgerSMB::DBObject::Employee; use LedgerSMB::Contact; -sub save_user { +#[18:00:31] I'd like to split them employee/user and roles/prefs +#[18:00:44] edit/create employee and add user features if needed. + +sub save { + + $self->error("Cannot save an Adminstrator object."); +} + +sub save_employee { 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', + 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=>[ + '', + 'first_name', + 'last_name', 'employeenumber', ] ); $employee->{entity_id} = $entity_id->{id}; - $employee->save_employee(); + $employee->save(); my $loc = LedgerSMB::DBObject::Location->new(base=>$self, copy=>'list', merge=>[ @@ -36,10 +51,11 @@ sub save_user { 'companyname', ] ); - $loc->save_location(); - $loc->join_to_person(person=>$employee); - + $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); @@ -51,8 +67,28 @@ sub save_user { $homephone->save(); $email->save(); - my $roles = $self->exec_method( procname => "all_roles" ); - my $user_roles = $self->exec_method(procname => "get_user_roles", args=>[ $self->{ modifying_user } ] ); + # now, check for user-specific stuff. Is this person a user or not? + + my $user = LedgerSMB::DBObject::User->new(base=>$self, copy=>'list', + merge=>[ + 'username', + 'password', + 'is_a_user' + ] + ); + + $user->get(); + $user->save(); +} + +sub save_roles { + + my $self = shift @_; + + my $user = LedgerSMB::DBObject::User->new(base=>$self, copy=>'all'); + + my $roles = $self->exec_method( procname => "admin_all_roles" ); + my $user_roles = $self->exec_method(procname => "admin_get_user_roles", args=>[ $self->{ username } ] ); my %active_roles; for my $role (@{$user_roles}) { @@ -86,6 +122,7 @@ sub save_user { ); } } + } sub save_group { diff --git a/LedgerSMB/DBObject/User.pm b/LedgerSMB/DBObject/User.pm new file mode 100644 index 00000000..62ae4e0b --- /dev/null +++ b/LedgerSMB/DBObject/User.pm @@ -0,0 +1,52 @@ +package LedgerSMB::DBObject::User; + +use base qw/LedgerSMB::DBObject/; + +sub save { + + my $self = shift @_; + + my $user = $self->get(); + + if ($user->{id} && $self->{is_a_user}) { + + # doesn't check for the password - that's done in the sproc. + $self->{id} = @{ $self->exec_method(procname=>'admin_save_user', + args=>[$user->{id}, $self->{username}, $self->{password}] ) }[0]; + else { + + return 0; + } + } + elsif ($user && !$self->{is_a_user}) { + + # there WAS a user, and we've decided we want that user to go away now. + + $self->{id} = $user->{id}; + return $self->remove(); + + } + return 1; +} + +sub get { + + my $self = shift @_; + + my ($user_id, $username) = @{ $self->exec_method(procname=>'admin_get_user', + args=>[$self->{id}])}; + + return {id=>$user_id, username=>$username}; +} + +sub remove { + + my $self = shift; + + my $code = $self->exec_method(procname=>"admin_delete_user", args=>[$self->{id}, $self->{username}]); + $self->{id} = undef; # never existed.. + + return $code->[0]; +} + +1; \ No newline at end of file -- cgit v1.2.3