diff options
-rw-r--r-- | FS/FS/AccessRight.pm | 3 | ||||
-rw-r--r-- | FS/FS/Schema.pm | 3 | ||||
-rw-r--r-- | FS/FS/inventory_item.pm | 16 | ||||
-rw-r--r-- | httemplate/browse/inventory_class.html | 20 | ||||
-rw-r--r-- | httemplate/elements/menu.html | 5 | ||||
-rw-r--r-- | httemplate/misc/inventory_item-import.html | 6 | ||||
-rw-r--r-- | httemplate/search/elements/search.html | 5 | ||||
-rw-r--r-- | httemplate/search/inventory_item.html | 17 |
8 files changed, 61 insertions, 14 deletions
diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index 01b9b5819..08d31d263 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -284,6 +284,9 @@ tie my %rights, 'Tie::IxHash', 'Edit billing events', { rightname=>'Edit global billing events', global=>1 }, + + 'Edit inventory', + { rightname=>'Edit global inventory', global=>1 }, { rightname=>'Dialup configuration' }, { rightname=>'Dialup global configuration', global=>1 }, diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 07e5b309b..ab80a08ba 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2593,12 +2593,13 @@ sub tables_hashref { 'columns' => [ 'itemnum', 'serial', '', '', '', '', 'classnum', 'int', '', '', '', '', + 'agentnum', 'int', 'NULL', '', '', '', 'item', 'varchar', '', $char_d, '', '', 'svcnum', 'int', 'NULL', '', '', '', ], 'primary_key' => 'itemnum', 'unique' => [ [ 'classnum', 'item' ] ], - 'index' => [ [ 'classnum' ], [ 'svcnum' ] ], + 'index' => [ [ 'classnum' ], [ 'agentnum' ], [ 'svcnum' ] ], }, 'inventory_class' => { diff --git a/FS/FS/inventory_item.pm b/FS/FS/inventory_item.pm index 3bba1cdda..39a0dff4b 100644 --- a/FS/FS/inventory_item.pm +++ b/FS/FS/inventory_item.pm @@ -106,6 +106,9 @@ sub check { my $error = $self->ut_numbern('itemnum') || $self->ut_foreign_key('classnum', 'inventory_class', 'classnum' ) + #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' ) + || $self->ut_agentnum_acl('agentnum', ['Configuration', + 'Edit global inventory'] ) || $self->ut_text('item') || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum' ) ; @@ -127,6 +130,17 @@ sub cust_svc { qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } ); } +=item agent + +Returns the associated agent for this event, if any, as an FS::agent object. + +=cut + +sub agent { + my $self = shift; + qsearchs('agent', { 'agentnum' => $self->agentnum } ); +} + =back =head1 SUBROUTINES @@ -142,7 +156,7 @@ sub process_batch_import { my $opt = { 'table' => 'inventory_item', #'params' => [ 'itembatch', 'classnum', ], - 'params' => [ 'classnum', ], + 'params' => [ 'classnum', 'agentnum', ], 'formats' => { 'default' => [ 'item' ] }, 'default_csv' => 1, }; diff --git a/httemplate/browse/inventory_class.html b/httemplate/browse/inventory_class.html index 8ce131ac2..4ad72a2ea 100644 --- a/httemplate/browse/inventory_class.html +++ b/httemplate/browse/inventory_class.html @@ -1,9 +1,7 @@ <% include( 'elements/browse.html', 'title' => 'Inventory Classes', 'name' => 'inventory classes', - 'menubar' => [ 'Add a new inventory class' => - $p.'edit/inventory_class.html', - ], + 'menubar' => $menubar, 'query' => { 'table' => 'inventory_class', }, 'count_query' => 'SELECT COUNT(*) FROM inventory_class', 'header' => [ '#', 'Inventory class', 'Inventory' ], @@ -66,8 +64,12 @@ %> <%init> +my $curuser = $FS::CurrentUser::CurrentUser; + die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Edit inventory') + || $curuser->access_right('Edit global inventory') + || $curuser->access_right('Configuration'); tie my %labels, 'Tie::IxHash', 'num_avail' => 'Available', # <FONT SIZE="-1"><A HREF="eventually">(upload batch)</A></FONT>', @@ -88,6 +90,14 @@ my %inv_action_link = ( ], ); -my $link = [ "${p}edit/inventory_class.html?", 'classnum' ]; +my $menubar = $curuser->access_right('Configuration') + ? [ 'Add a new inventory class' => + $p.'edit/inventory_class.html', + ] + : []; + +my $link = $curuser->access_right('Configuration') + ? [ "${p}edit/inventory_class.html?", 'classnum' ] + : ''; </%init> diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index 8b4a06885..fc5498f84 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -469,8 +469,11 @@ $config_misc{'Advertising sources'} = [ $fsurl.'browse/part_referral.html', 'Whe if ( $curuser->access_right('Configuration') ) { $config_misc{'Virtual fields'} = [ $fsurl.'browse/part_virtual_field.cgi', 'Locally defined fields', ]; $config_misc{'Message catalog'} = [ $fsurl.'browse/msgcat.cgi', 'Change error messages and other customizable labels' ]; - $config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_class.html', 'Setup inventory classes and stock inventory' ]; } +$config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_class.html', 'Setup inventory classes and stock inventory' ] + if $curuser->access_right('Edit inventory') + || $curuser->access_right('Edit global inventory') + || $curuser->access_right('Configuration'); tie my %config_menu, 'Tie::IxHash'; if ( $curuser->access_right('Configuration' ) ) { diff --git a/httemplate/misc/inventory_item-import.html b/httemplate/misc/inventory_item-import.html index c7edac609..990c14ffc 100644 --- a/httemplate/misc/inventory_item-import.html +++ b/httemplate/misc/inventory_item-import.html @@ -7,8 +7,8 @@ Import a file containing <% PL($inventory_class->classname) %>, one per line. 'name' => 'InventoryItemImportForm', 'action' => 'process/inventory_item-import.html', 'num_files' => 1, - #'fields' => [ 'format', 'itembatch', 'classnum', ], - 'fields' => [ 'format', 'classnum', ], + #'fields' => [ 'format', 'itembatch', 'classnum', 'agentnum' ], + 'fields' => [ 'format', 'classnum', 'agentnum', ], 'message' => 'Inventory import successful', #XXX redirect via $itembatch? or just back to class browse? #'url' => $p."search/phone_avail.html?availbatch=$availbatch", @@ -24,6 +24,8 @@ Import a file containing <% PL($inventory_class->classname) %>, one per line. %# <INPUT TYPE="hidden" NAME="itembatch" VALUE="<% $itembatch %>"> + <% include('/elements/tr-select-agent.html') %> + <% include( '/elements/file-upload.html', 'field' => 'file', 'label' => 'Filename', diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 0dc417052..636885edc 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -121,6 +121,7 @@ Example: #handling agent virtualization 'agent_virt' => 1, # set true if this search should be # agent-virtualized + 'agent_null' => 1, # set true to view global records always 'agent_null_right' => 'Access Right', # optional right to view global # records 'agent_null_right_link' => 'Access Right' # optional right to link to @@ -235,7 +236,9 @@ if ( $opt{'agent_virt'} ) { || $opt{'agent_null_right'} ); my $agentnums_sql = $curuser->agentnums_sql( - 'null_right' => $opt{'agent_null_right'} + 'null' => $opt{'agent_null'}, + 'null_right' => $opt{'agent_null_right'}, + 'table' => $opt{'query'}{'table'}, ); $opt{'query'}{'extra_sql'} .= diff --git a/httemplate/search/inventory_item.html b/httemplate/search/inventory_item.html index 55fef9432..80810caf9 100644 --- a/httemplate/search/inventory_item.html +++ b/httemplate/search/inventory_item.html @@ -1,8 +1,11 @@ <% include( 'elements/search.html', 'title' => $title, - #less lame to use Lingua:: something to pluralize - 'name' => $inventory_class->classname. 's', + 'menubar' => [ 'View inventory classes' => + $p.'browse/inventory_class.html', + ], + + 'name' => PL($inventory_class->classname), 'query' => { 'table' => 'inventory_item', @@ -19,6 +22,10 @@ 'count_query' => $count_query, + 'agent_virt' => 1, + 'agent_null' => 1, + 'agent_pos' => 2, + 'header' => [ '#', $inventory_class->classname, @@ -74,8 +81,12 @@ %> <%init> +my $curuser = $FS::CurrentUser::CurrentUser; + die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + unless $curuser->access_right('Edit inventory') + || $curuser->access_right('Edit global inventory') + || $curuser->access_right('Configuration'); my $classnum = $cgi->param('classnum'); $classnum =~ /^(\d+)$/ or errorpage("illegal classnum $classnum"); |