beginning of agent-virtualization of packages
authorivan <ivan>
Mon, 24 Sep 2007 00:56:50 +0000 (00:56 +0000)
committerivan <ivan>
Mon, 24 Sep 2007 00:56:50 +0000 (00:56 +0000)
FS/FS/AccessRight.pm
FS/FS/Schema.pm
FS/FS/part_event.pm
FS/FS/part_pkg.pm
httemplate/browse/part_pkg.cgi

index 4071e97..5ab6809 100644 (file)
@@ -223,6 +223,9 @@ tie my %rights, 'Tie::IxHash',
   'Configuration rights' => [
     'Edit advertising sources',
     { rightname=>'Edit global advertising sources', global=>1 },
+
+    'Edit package definitions',
+    { rightname=>'Edit global package definitions', global=>1 },
   
     'Edit billing events',
     { rightname=>'Edit global billing events', global=>1 },
index aebe5de..1ddaca0 100644 (file)
@@ -862,10 +862,12 @@ sub tables_hashref {
         'classnum',      'int',     'NULL', '', '', '', 
         'pay_weight',    'real',    'NULL', '', '', '',
         'credit_weight', 'real',    'NULL', '', '', '',
+        'agentnum',      'int',     'NULL', '', '', '', 
+
       ],
       'primary_key' => 'pkgpart',
       'unique' => [],
-      'index' => [ [ 'promo_code' ], [ 'disabled' ] ],
+      'index' => [ [ 'promo_code' ], [ 'disabled' ], [ 'agentnum' ], ],
     },
 
 #    'part_title' => {
@@ -900,7 +902,7 @@ sub tables_hashref {
       ],
       'primary_key' => 'refnum',
       'unique' => [],
-      'index' => [ ['disabled'] ],
+      'index' => [ ['disabled'], ['agentnum'], ],
     },
 
     'part_svc' => {
index 09104cd..d0ab65e 100644 (file)
@@ -138,6 +138,7 @@ sub check {
     || $self->ut_number('weight')
     || $self->ut_alpha('action')
     || $self->ut_enum('disabled', [ '', 'Y' ] )
+    || $self->ut_agentnum_acl('agentnum', 'Edit global billing events')
   ;
   return $error if $error;
 
index fad7af2..84502b7 100644 (file)
@@ -13,6 +13,7 @@ use FS::agent_type;
 use FS::type_pkgs;
 use FS::part_pkg_option;
 use FS::pkg_class;
+use FS::agent;
 
 @ISA = qw( FS::m2m_Common FS::Record ); # FS::option_Common ); # this can use option_Common
                                                 # when all the plandata bs is
@@ -85,6 +86,8 @@ inherits from FS::Record.  The following fields are currently supported:
 
 =item credit_weight - Weight (relative to other package definitions) that controls credit application to specific line items.
 
+=item agentnum - Optional agentnum (see L<FS::agent>)
+
 =back
 
 =head1 METHODS
@@ -449,6 +452,7 @@ sub check {
     || $self->ut_enum('disabled', [ '', 'Y' ] )
     || $self->ut_floatn('pay_weight')
     || $self->ut_floatn('credit_weight')
+    || $self->ut_agentnum_acl('agentnum', 'Edit global package definitions')
     || $self->SUPER::check
   ;
   return $error if $error;
@@ -501,6 +505,17 @@ sub classname {
     : '';
 }
 
+=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 } );
+}
+
 =item pkg_svc
 
 Returns all FS::pkg_svc objects (see L<FS::pkg_svc>) for this package
index 0b83fc0..40f6b3d 100755 (executable)
@@ -5,6 +5,9 @@
                  'name'               => 'package definitions',
                  'disableable'        => 1,
                  'disabled_statuspos' => 3,
+                 'agent_virt'         => 1,
+                 'agent_null_right'   => 'Edit global package definitions',
+                 'agent_pos'          => 4,
                  'query'              => { 'select'    => $select,
                                            'table'     => 'part_pkg',
                                            'hashref'   => {},
@@ -20,7 +23,8 @@
 <%init>
 
 die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+  unless $FS::CurrentUser::CurrentUser->access_right('Edit package definitions')
+      || $FS::CurrentUser::CurrentUser->access_right('Edit global package definitions');
 
 my $select = '*';
 my $orderby = 'pkgpart';
@@ -220,6 +224,9 @@ $align .= 'lrl'; #rr';
 
 # --------
 
-my $count_query = 'SELECT COUNT(*) FROM part_pkg';
+my $count_query = 'SELECT COUNT(*) FROM part_pkg WHERE '.
+                    $FS::CurrentUser::CurrentUser->agentnums_sql(
+                      'null_right' => 'Edit global package definitions',
+                    );
 
 </%init>