[freeside-commits] freeside/httemplate/edit part_pkg.cgi, 1.101, 1.102 cust_main.cgi, 1.94, 1.95

Ivan,,, ivan at wavetail.420.am
Sat Feb 7 18:05:27 PST 2009


Update of /home/cvs/cvsroot/freeside/httemplate/edit
In directory wavetail.420.am:/tmp/cvs-serv1782/httemplate/edit

Modified Files:
	part_pkg.cgi cust_main.cgi 
Log Message:
further work on agents editing own packages: allow them to see (but not edit) global packages for their type, RT#1331

Index: cust_main.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/cust_main.cgi,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -d -r1.94 -r1.95
--- cust_main.cgi	24 Jan 2009 21:49:04 -0000	1.94
+++ cust_main.cgi	8 Feb 2009 02:05:25 -0000	1.95
@@ -568,22 +568,33 @@
 %
 %  #false laziness, copied from FS::cust_pkg::order
 %  my $pkgpart;
+%  my $agentnum = '';
 %  my @agents = $FS::CurrentUser::CurrentUser->agents;
 %  if ( scalar(@agents) == 1 ) {
 %    # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
 %    $pkgpart = $agents[0]->pkgpart_hashref;
+%    $agentnum = $agents[0]->agentnum;
 %  } else {
 %    #can't know (agent not chosen), so, allow all
+%    $agentnum = 'all';
 %    my %typenum;
 %    foreach my $agent ( @agents ) {
 %      next if $typenum{$agent->typenum}++;
-%      #fixed in 5.004_05 #$pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
-%      foreach ( keys %{ $agent->pkgpart_hashref } ) { $pkgpart->{$_}++; } #5.004_04 workaround
+%      $pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
 %    }
 %  }
 %  #eslaf
 %
-%  my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
+%  my @part_pkg = grep { $_->svcpart('svc_acct')
+%                        && ( $pkgpart->{ $_->pkgpart } 
+%                             || $agentnum eq 'all'
+%                             || ( $agentnum ne 'all'
+%                                  && $agentnum
+%                                  && $_->agentnum
+%                                  && $_->agentnum == $agentnum
+%                                )
+%                           )
+%                      }
 %    qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
 %
 %  if ( @part_pkg ) {

Index: part_pkg.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/part_pkg.cgi,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- part_pkg.cgi	25 Jan 2009 23:58:24 -0000	1.101
+++ part_pkg.cgi	8 Feb 2009 02:05:25 -0000	1.102
@@ -1,12 +1,16 @@
 <% include( 'elements/edit.html',
-              'post_url'    => popurl(1).'process/part_pkg.cgi',
-              'name'        => "Package definition",
-              'table'       => 'part_pkg',
-              #'viewall_dir' => 'browse',
-              'viewall_url' => $p.'browse/part_pkg.cgi',
-              'html_init'   => include('/elements/init_overlib.html').
-                               $freq_changed,
-              'html_bottom' => $html_bottom,
+              'post_url'         => popurl(1).'process/part_pkg.cgi',
+              'name'             => "Package definition",
+              'table'            => 'part_pkg',
+
+              'agent_virt'       => 1,
+              'agent_null_right' => $edit_global,
+
+              #'viewall_dir'      => 'browse',
+              'viewall_url'      => $p.'browse/part_pkg.cgi',
+              'html_init'        => include('/elements/init_overlib.html').
+                                    $freq_changed,
+              'html_bottom'      => $html_bottom,
 
               'begin_callback'       => $begin_callback,
               'end_callback'         => $end_callback,
@@ -32,7 +36,7 @@
                             'disabled'         => 'Disable new orders',
                             'pay_weight'       => 'Payment weight',
                             'credit_weight'    => 'Credit weight',
-                            'agentnum'         => '',
+                            'agentnum'         => 'Agent',
                             'setup_fee'        => 'Setup fee',
                             'recur_fee'        => 'Recurring fee',
                             'bill_dst_pkgpart' => 'Include line item(s) from package',
@@ -57,6 +61,11 @@
                                 maxlength => 50,
                               },
                               {field=>'comment',  type=>'text', size=>40 }, #32
+                              { field         => 'agentnum',
+                                type          => 'select-agent',
+                                disable_empty => ! $acl_edit_global,
+                                empty_label   => '(global)',
+                              },
                               {field=>'classnum', type=>'select-pkg_class' },
                               {field=>'disabled', type=>$disabled_type, value=>'Y'},
 
@@ -125,8 +134,9 @@
 
                             { type => 'columnnext' },
 
-                              { field=>'agent_type',
-                                type => 'select-agent_types',
+                              { field    => 'agent_type',
+                                type     => 'select-agent_types',
+                                disabled => ! $acl_edit_global,
                                 curr_value_callback => sub {
                                   my($cgi, $object, $field) = @_;
                                   #in the other callbacks..?  hmm.
@@ -175,19 +185,22 @@
 
 my $curuser = $FS::CurrentUser::CurrentUser;
 
-my $edit_right = $curuser->access_right('Edit package definitions')
-              || $curuser->access_right('Edit global package definitions');
+my $edit_global = 'Edit global package definitions';
+my $acl_edit        = $curuser->access_right('Edit package definitions');
+my $acl_edit_global = $curuser->access_right($edit_global);
+
+my $acl_edit_either = $acl_edit || $acl_edit_global;
 
 my $begin_callback = sub {
   my( $cgi, $fields, $opt ) = @_;
   die "access denied"
-    unless $edit_right
+    unless $acl_edit_either
         || ( $cgi->param('pkgnum')
              && $curuser->access_right('Customize customer package')
            );
 };
 
-my $disabled_type = $edit_right ? 'checkbox' : 'hidden';
+my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
 
 my $conf = new FS::Conf;
 my $taxproducts = $conf->exists('enable_taxproducts');



More information about the freeside-commits mailing list