[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[3608] trunk
- Subject: SF.net SVN: ledger-smb:[3608] trunk
- From: ..hidden..
- Date: Sun, 31 Jul 2011 17:25:55 +0000
Revision: 3608
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3608&view=rev
Author: einhverfr
Date: 2011-07-31 17:25:55 +0000 (Sun, 31 Jul 2011)
Log Message:
-----------
Closing bug 3372882
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Employee.pm
trunk/LedgerSMB.pm
trunk/UI/Admin/edit_user.html
trunk/UI/Contact/contact.html
trunk/scripts/admin.pl
trunk/scripts/employee.pl
trunk/sql/modules/Employee.sql
trunk/sql/modules/Person.sql
Modified: trunk/LedgerSMB/DBObject/Employee.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Employee.pm 2011-07-31 01:49:47 UTC (rev 3607)
+++ trunk/LedgerSMB/DBObject/Employee.pm 2011-07-31 17:25:55 UTC (rev 3608)
@@ -184,6 +184,7 @@
$country_setting->{key} = 'default_country';
$country_setting->get;
$self->{default_country} = $country_setting->{value};
+ $self->get_user_info();
}
=item get
@@ -316,6 +317,28 @@
return $rv;
}
+=item get_user_info
+
+Attaches the user_id and username to the employee object.
+
+If the user does not have manage_users powers, this will simply return false
+
+=cut
+
+sub get_user_info {
+ my $self = shift @_;
+ if (!$self->is_allowed_role({allowed_roles => [
+ "lsmb_$self->{company}__users_manage"]
+ }
+ )){
+ return 0;
+ }
+ my ($ref) = $self->exec_method(funcname => 'employee__get_user');
+ $self->{user_id} = $ref->{id};
+ $self->{username} = $ref->{username};
+ return 1;
+}
+
=back
=head1 Copyright (C) 2007, The LedgerSMB core team.
Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm 2011-07-31 01:49:47 UTC (rev 3607)
+++ trunk/LedgerSMB.pm 2011-07-31 17:25:55 UTC (rev 3608)
@@ -75,8 +75,7 @@
=item is_allowed_role({allowed_roles => @role_names})
This function returns 1 if the user's roles include any of the roles in
..hidden.. Currently it returns 1 when this is not found as well but when
-role permissions are introduced, this will change to 0.
..hidden..
=item num_text_rows (string => $string, cols => $number, max => $number);
Modified: trunk/UI/Admin/edit_user.html
===================================================================
--- trunk/UI/Admin/edit_user.html 2011-07-31 01:49:47 UTC (rev 3607)
+++ trunk/UI/Admin/edit_user.html 2011-07-31 17:25:55 UTC (rev 3608)
@@ -17,6 +17,7 @@
<form method="POST" action="admin.pl">
<input type="hidden" name="action" value="<?lsmb action ?>"/>
+ <input type="hidden" name="entity_id" value="<?lsmb user.employee.entity_id ?>"/>
<table>
<?lsmb IF user.user.username?>
@@ -123,175 +124,6 @@
</button>
</form>
<?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?>"/>
- <?lsmb END?>
- <input type="hidden" name="action" value="save_location"/>
- <input type="hidden" name="user_id" value="<?lsmb user.user.id?>"/>
- <hr/>
- <table>
-
- <tr class="listtop">
- <td colspan="8">
- <?lsmb text('Location') ?>
- </td>
- </tr>
-
- <tr class="listheading">
- <td></td>
- <td>
- <?lsmb text('Address') ?>
- </td>
- <td>
- <?lsmb text('City') ?>
- </td>
- <td>
- <?lsmb text('State/Province') ?>
- </td>
- <td>
- <?lsmb text('Zip/Postal Code') ?>
- </td>
- <td>
- <?lsmb text('Country') ?>
- </td>
- </tr>
- <?lsmb row = 0 ?>
- <?lsmb FOR location IN user.locations ?>
- <?lsmb row = (row + 1) % 2; class = "row$row" ?>
- <tr class = "<?lsmb class ?>">
- <td>
- <a href="admin.pl?action=edit_location&id=<?lsmb location.id?>">Edit</a>
- <a href="admin.pl?action=delete_location&id=<?lsmb location.id?>">Delete</a>
- <td>
-
- <?lsmb location.line_one?>
- <?lsmb location.line_two?>
- <?lsmb location.line_three?>
- </a>
- </td>
- <td>
- <?lsmb location.city?>
- </td>
- <td>
- <?lsmb location.state?>
- </td>
- <td>
- <?lsmb location.zipcode?>
- </td>
- <td>
- <?lsmb location.country?>
- </td>
- </tr>
-
- <?lsmb END?>
-
- <!-- The editable one. -->
- <tr>
- <td></td>
- <td>
- <input type="text" name="address1" value="<?lsmb edit_location.line_one?>"/>
- <input type="text" name="address2" value="<?lsmb edit_location.line_two?>"/>
- <input type="text" name="address3" value="<?lsmb edit_location.line_three?>" />
- </td>
- <td valign="top">
- <input type="text" name="city" value="<?lsmb edit_location.city?>"/>
- </td>
- <td valign="top">
- <input type="text" name="state" value="<?lsmb edit_location.state?>"/>
- </td>
- <td valign="top">
- <input type="text" name="zipcode" value="<?lsmb edit_location.zipcode?>"/>
- </td>
- <td valign="top">
- <?lsmb IF edit_location.country;
- country_id = edit_location.country_id;
- ELSE;
- country_id = default_country;
- END; -?>
- <?lsmb PROCESS select element_data = {
- name = "country"
- options = countries
- default_values = [country_id]
- value_attr = "id"
- text_attr = "name"
- } ?>
- </td>
- </tr>
- <tr>
- <td>
- <?lsmb IF location?>
- <input type="submit" value="Edit Location">
- <input type="hidden" name="location_id" value="<?lsmb location.id?>"/>
- <input type="submit" value="Cancel" name="cancel"/>
- <?lsmb ELSE?>
- <input type="submit" value="Save Location">
- <?lsmb END?>
- </td>
- </tr>
- </form>
- </table>
-
-
- <hr/>
- <table>
- <form name="contacts" method="POST" action="admin.pl">
- <input type="hidden" name="action" value="save_contact"/>
- <input type="hidden" name="user_id" value="<?lsmb user.user.id?>"/>
- <tr class = "listtop">
- <td colspan="8"><?lsmb text('Contact Information') ?></td>
- </tr>
-
- <tr class="listheading">
- <td></td>
-
- <td>
- <?lsmb text('Contact Type') ?>
- </td>
- <td>
- <?lsmb text('Contact Info') ?>
- </td>
- </tr>
-
- <?lsmb FOR l_contact IN user.contacts?>
-
- <tr>
- <td>
- <a href="admin.pl?edit_contact&contact_id=<?lsmb l_contact.id?>&user_id=<?lsmb user.user.id?>">Edit</a>
- <a href="admin.pl?delete_contact&contact_id=<?lsmb l_contact.id?>&user_id=<?lsmb user.user.id?>">Delete</a>
- </td>
- <td><?lsmb l_contact.class?></td>
- <td><?lsmb l_contact.contact?></td>
- </tr>
- <?lsmb END?>
- <tr>
- <td></td>
- <td>
- <?lsmb PROCESS select element_data = {
- name = "contact_class"
- options = contact_classes
- default_values = [contact.contact_class_id]
- value_attr = "id"
- text_attr = "name"
- } ?>
- </td>
- <td>
- <input type="textarea" name="contact" value="<?lsmb contact.contact?>"/>
- </td>
- </tr>
- <tr>
- <td>
- <?lsmb IF contact?>
- <input type="submit" value="Edit Contact">
- <input type="hidden" name="contact_id" value="<?lsmb contact.id?>"/>
- <input type="submit" value="Cancel" name="cancel"/>
- <?lsmb ELSE?>
- <input type="submit" value="Save Contact">
- <?lsmb END?>
- </td>
- </tr>
- </form>
- </table> <hr />
<form name="groups" method="POST" action="admin.pl">
<?lsmb PROCESS input element_data = {
type="hidden"
Modified: trunk/UI/Contact/contact.html
===================================================================
--- trunk/UI/Contact/contact.html 2011-07-31 01:49:47 UTC (rev 3607)
+++ trunk/UI/Contact/contact.html 2011-07-31 17:25:55 UTC (rev 3608)
@@ -8,7 +8,10 @@
]
?>
<?lsmb PROCESS 'elements.html' ?>
-<?lsmb IF (! target_div); ?>
+<?lsmb
+# Adding the action requirement to the conditional because otherwise it still
+# breaks. --CT
+IF (!(action == 'edit' and target_div)); ?>
<?lsmb IF (!entity_id and account_class != 3);
target_div = 'company_div';
ELSIF ((!entity_id or action == 'save') and entity_class == 3);
@@ -210,6 +213,20 @@
name = 'action'
value = "save"
} ?>
+<?lsmb
+IF manage_users and entity_id;
+ IF user_id ?>
+ <a href="admin.pl?action=edit_user&user_id=<?lsmb user_id ?>"
+ >[<?lsmb text('Edit User') ?>]</a><?lsmb
+ ELSE ?>
+ <a href="admin.pl?action=new_user&first_name=<?lsmb tt_url(first_name)
+ ?>&last_name=<?lsmb tt_url(last_name)
+ ?>&employeenumber=<?lsmb tt_url(employeenumber)
+ ?>&country_id=<?lsmb tt_url(country_id)
+ ?>&entity_id=<?lsmb tt_url(entity_id) ?>"
+ >[<?lsmb text('Add User') ?>]</a><?lsmb
+ END;
+END ?>
</div>
</form>
</div>
@@ -693,6 +710,12 @@
<th class="actions"><?lsmb text('Actions') ?></th>
</tr>
<?lsmb FOREACH loc = locations ?>
+ <?lsmb IF location_id == loc.id;
+ FOREACH key = loc.keys();
+ $key = loc.$key;
+ END;
+ END;
+ ?>
<tr <?lsmb IF location_id == loc.id ?> class="active" <?lsmb END ?>>
<td class="type"><?lsmb loc.class ?></td>
<td class="line_one"><?lsmb loc.line_one ?></td>
@@ -741,7 +764,7 @@
</div>
<div>
<?lsmb PROCESS input element_data = {
- label = " "
+ label = ":"
name = "line_two"
class = "addl-address"
value = line_two
@@ -751,7 +774,7 @@
</div>
<div>
<?lsmb PROCESS input element_data = {
- label = " "
+ label = ":"
name = "line_three"
class = "addl-address"
value = line_three
Modified: trunk/scripts/admin.pl
===================================================================
--- trunk/scripts/admin.pl 2011-07-31 01:49:47 UTC (rev 3607)
+++ trunk/scripts/admin.pl 2011-07-31 17:25:55 UTC (rev 3608)
@@ -23,7 +23,6 @@
use LedgerSMB::Template;
use LedgerSMB::DBObject::Admin;
use LedgerSMB::DBObject::User;
-use LedgerSMB::DBObject::Location;
use Data::Dumper;
use LedgerSMB::Setting;
use LedgerSMB::Log;
@@ -57,7 +56,6 @@
format => 'HTML',
path=>'UI'
);
- my $location = LedgerSMB::DBObject::Location->new(base=>$request);
my $template_data =
{
user=>$user_obj,
@@ -65,8 +63,6 @@
countries=>$admin->get_countries(),
user_roles=>$user_obj->{roles},
salutations=>$admin->get_salutations(),
- contact_classes=>$admin->get_contact_classes(),
- locations=>$user->{employee}->{locations},
default_country => $dcsetting->{value},
admin => $admin,
stylesheet => $request->{stylesheet},
@@ -188,6 +184,7 @@
roles=>$groups,
countries=>$admin->get_countries(),
stylesheet => $request->{stylesheet},
+ user => { user => $request, employee => $request },
}
);
}
@@ -292,79 +289,6 @@
}
}
-=item save_location
-
-Saves location information and returns to the edit user screen.
-
-=cut
-
-sub save_location {
-
- my $request = shift @_;
- my $user = $request->{_user};
-
- # Only ever a post, but check anyway
- if ($request->type eq "POST") {
-
- if ($request->{cancel}) {
-
- # If we have a cancel request, we just go back to edit_page.
- return __edit_page($request);
- }
-
- if ($request->{cancel}) {
-
- # If we have a cancel request, we just go back to edit_page.
- return __edit_page($request);
- }
-
- my $u_id = $request->{user_id}; # this is an entity_id
- my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
- my $location = LedgerSMB::DBObject::Location->new(base=>$request, copy=>'all');
- $user_obj->get($request->{user_id});
- # So there's a pile of stuff we need.
- # lineone
- # linetwo
- # linethree
- # city
- # state
- # zipcode
- # country
- # u_id isn't an entity_it, though.
- $location->{user_id} = $user_obj->{user}->{entity_id};
- my $id = $location->save("person");
- # Done and done.
-
- __edit_page($request,{location=>$location});
- }
-}
-
-=item delete_location
-
-Deletes a location and returns to edit user screen
-
-=cut
-
-sub delete_location {
-
- my $request = shift @_;
-
- # Having delete come over GET perhaps isn't the best technique.
-
- if ($request->type eq "GET") {
-
- my $l_id = $request->{location_id};
- my $u_id = $request->{user_id};
- my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
- my $location = LedgerSMB::DBObject::Location->new(base=>$request, copy=>"location_id");
-
- $location->delete("person",$l_id,$user_obj->{user}->{entity_id});
- # Boom. Done.
- # Now, just call the main edit user page.
- __edit_page($request);
- }
-}
-
=item search_users
Displays search criteria screen
Modified: trunk/scripts/employee.pl
===================================================================
--- trunk/scripts/employee.pl 2011-07-31 01:49:47 UTC (rev 3607)
+++ trunk/scripts/employee.pl 2011-07-31 17:25:55 UTC (rev 3608)
@@ -118,6 +118,19 @@
_render_main_screen( $employee);
}
+=item save_contact_new($request)
+
+Saves contact info as a new line as per save_contact above.
+
+=cut
+
+sub save_contact_new{
+ my ($request) = @_;
+ delete $request->{old_contact};
+ delete $request->{old_contact_class};
+ save_contact($request);
+}
+
=item delete_location
Deletes the selected contact info record
@@ -336,7 +349,13 @@
$employee->{creditlimit} = "$employee->{creditlimit}";
$employee->{discount} = "$employee->{discount}";
$employee->{script} = "employee.pl";
-
+ if ($employee->is_allowed_role({allowed_roles => [
+ "lsmb_$employee->{company}__users_manage"]
+ }
+ )){
+ $employee->{manage_users} = 1;
+ }
+ $employee->debug({file => '/tmp/emp'});
my $template = LedgerSMB::Template->new(
user => $employee->{_user},
template => 'contact',
Modified: trunk/sql/modules/Employee.sql
===================================================================
--- trunk/sql/modules/Employee.sql 2011-07-31 01:49:47 UTC (rev 3607)
+++ trunk/sql/modules/Employee.sql 2011-07-31 17:25:55 UTC (rev 3608)
@@ -47,6 +47,13 @@
in_employee_number text) IS
$$ Saves an employeerecord with the specified information.$$;
+CREATE OR REPLACE FUNCTION employee__get_user(in_entity_id int)
+RETURNS SETOF users AS
+$$SELECT * FROM users WHERE entity_id = $1;$$ language sql;
+
+COMMENT ON FUNCTION employee__get_user(in_entity_id int) IS
+$$ Returns username, user_id, etc. information if the employee is a user.$$;
+
create view employees as
select
s.salutation,
Modified: trunk/sql/modules/Person.sql
===================================================================
--- trunk/sql/modules/Person.sql 2011-07-31 01:49:47 UTC (rev 3607)
+++ trunk/sql/modules/Person.sql 2011-07-31 17:25:55 UTC (rev 3608)
@@ -217,7 +217,7 @@
$$
BEGIN
-DELETE FROM eca_to_location
+DELETE FROM person_to_location
WHERE person_id = in_person_id AND location_id = in_location_id
AND location_class = in_location_class;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.