Add "View customers of all agents" access rights, RT#7010
authorivan <ivan>
Thu, 17 Jun 2010 02:08:53 +0000 (02:08 +0000)
committerivan <ivan>
Thu, 17 Jun 2010 02:08:53 +0000 (02:08 +0000)
FS/FS/AccessRight.pm
FS/FS/access_user.pm
httemplate/browse/part_event.html
httemplate/browse/part_pkg.cgi
httemplate/edit/process/elements/process.html
httemplate/edit/prospect_main.html
httemplate/view/cust_main/misc.html
httemplate/view/prospect_main.html
httemplate/view/svc_acct/tr.html [deleted file]

index 08d31d2..1e1b9ea 100644 (file)
@@ -115,6 +115,7 @@ tie my %rights, 'Tie::IxHash',
     { rightname=>'Delete customer', desc=>"Enable customer deletions. Be very careful! Deleting a customer will remove all traces that this customer ever existed! It should probably only be used when auditing a legacy database. Normally, you cancel all of a customer's packages if they cancel service." }, #aka. deletecustomers
     'Bill customer now', #NEW
     'Bulk send customer notices', #NEW
+    { rightname=>'View customers of all agents', global=>1 },
   ],
   
   ###
@@ -249,6 +250,8 @@ tie my %rights, 'Tie::IxHash',
     'Billing event reports',
     'Receivables report',
     'Financial reports',
+
+    #{ rightname => 'List customers of all agents', global=>1 },
   ],
   
   ###
@@ -294,6 +297,9 @@ tie my %rights, 'Tie::IxHash',
     { rightname=>'Broadband configuration' },
     { rightname=>'Broadband global configuration', global=>1 },
 
+    #{ rightname=>'Edit employees', global=>1, },
+    #{ rightname=>'Edit employee groupss', global=>1, },
+
     { rightname=>'Configuration', global=>1 }, #most of the rest of the configuraiton is not agent-virtualized
 
     { rightname=>'Configuration download', }, #description of how it affects
index 1bf6e93..25aa8af 100644 (file)
@@ -1,20 +1,16 @@
 package FS::access_user;
 
 use strict;
-use vars qw( @ISA $DEBUG $me $conf $htpasswd_file );
+use base qw( FS::m2m_Common FS::option_Common ); 
+use vars qw( $DEBUG $me $conf $htpasswd_file );
 use FS::UID;
 use FS::Conf;
 use FS::Record qw( qsearch qsearchs dbh );
-use FS::m2m_Common;
-use FS::option_Common;
 use FS::access_user_pref;
 use FS::access_usergroup;
 use FS::agent;
 use FS::cust_main;
 
-@ISA = qw( FS::m2m_Common FS::option_Common FS::Record );
-#@ISA = qw( FS::m2m_Common FS::option_Common );
-
 $DEBUG = 0;
 $me = '[FS::access_user]';
 
@@ -367,6 +363,11 @@ user has the provided access right
 Optional table name in which agentnum is being checked.  Sometimes required to
 resolve 'column reference "agentnum" is ambiguous' errors.
 
+=item viewall_right
+
+All agents will be viewable if the current user has the provided access right.
+Defaults to 'View customers of all agents'.
+
 =back
 
 =cut
@@ -377,16 +378,21 @@ sub agentnums_sql {
 
   my $agentnum = $opt{'table'} ? $opt{'table'}.'.agentnum' : 'agentnum';
 
-#  my @agentnums = map { "$agentnum = $_" } $self->agentnums;
-  my @agentnums = ();
-  push @agentnums, "$agentnum IN (". join(',', $self->agentnums). ')';
+  my @or = ();
+
+  my $viewall_right = $opt{'viewall_right'} || 'View customers of all agents';
+  if ( $self->access_right($viewall_right) ) {
+    push @or, "$agentnum IS NOT NULL";
+  } else {
+    push @or, "$agentnum IN (". join(',', $self->agentnums). ')';
+  }
 
-  push @agentnums, "$agentnum IS NULL"
+  push @or, "$agentnum IS NULL"
     if $opt{'null'}
     || ( $opt{'null_right'} && $self->access_right($opt{'null_right'}) );
 
-  return ' 1 = 0 ' unless scalar(@agentnums);
-  '( '. join( ' OR ', @agentnums ). ' )';
+  return ' 1 = 0 ' unless scalar(@or);
+  '( '. join( ' OR ', @or ). ' )';
 
 }
 
index 674004b..3d7c245 100644 (file)
@@ -158,7 +158,8 @@ $html_init .= '</SELECT><INPUT TYPE="submit" VALUE="Clone existing event">'.
      
 my $count_query = 'SELECT COUNT(*) FROM part_event WHERE '.
                   $FS::CurrentUser::CurrentUser->agentnums_sql(
-                    'null_right' => 'Edit global billing events',
+                    'null_right'    => 'Edit global billing events',
+                    'viewall_right' => 'None',
                   );
 
 my $join_conditions  = FS::part_event_condition->join_conditions_sql;
index e226ce1..42eb5df 100755 (executable)
@@ -84,11 +84,11 @@ my $extra_sql = scalar(@where)
                   join( 'AND ', @where)
                 : '';
 
-my $agentnums = join(',', $curuser->agentnums);
+my $agentnums_sql = $curuser->agentnums_sql( 'table'=>'cust_main' );
 my $count_cust_pkg = "
   SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
     WHERE cust_pkg.pkgpart = part_pkg.pkgpart
-      AND cust_main.agentnum IN ($agentnums)
+      AND $agentnums_sql
 ";
 
 $select = "
index ebbc2f7..53419cd 100644 (file)
@@ -207,6 +207,7 @@ if ( $opt{'agent_virt'} ) {
 
     die "illegal agentnum"
       unless $curuser->agentnums_href->{$new->agentnum}
+          or $curuser->access_right('View customers of all agents')
           or $opt{'agent_null_right'}
              && ! $new->agentnum
              && $curuser->access_right($opt{'agent_null_right'});
index 90f971a..e867907 100644 (file)
@@ -109,6 +109,6 @@ my $m2_error_callback = sub {
       $cgi->param;
 };
 
-my @agentnums = $FS::CurrentUser::CurrentUser->agentnums;
+#my @agentnums = $FS::CurrentUser::CurrentUser->agentnums;
 
 </%init>
index b98e9dc..8bcab0d 100644 (file)
@@ -10,7 +10,8 @@
   <TD BGCOLOR="#ffffff"><FONT COLOR="#<% $cust_main->statuscolor %>"><B><% ucfirst($cust_main->status) %></B></FONT></TD>
 </TR>
 
-%unless ( scalar(@agentnums) == 1 ) {
+%unless ( scalar(@agentnums) == 1
+%         && !$curuser->access_right('View customers of all agents')  ) {
 %  my $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } );
    <TR>
      <TD ALIGN="right">Agent</TD>
index 9883e67..9517e39 100644 (file)
@@ -14,7 +14,8 @@
   <TD BGCOLOR="#FFFFFF"><B><% $prospectnum %></B></TD>
 </TR>
 
-%unless ( scalar(@agentnums) == 1 ) {
+%unless ( scalar(@agentnums) == 1
+%         && !$curuser->access_right('View customers of all agents') ) {
 %  my $agent = qsearchs('agent',{ 'agentnum' => $prospect_main->agentnum } );
    <TR>
      <TD ALIGN="right">Agent</TD>
diff --git a/httemplate/view/svc_acct/tr.html b/httemplate/view/svc_acct/tr.html
deleted file mode 100644 (file)
index e2ec7d4..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<TR>
-  <TD ALIGN="right"><% $opt{'label'} %></TD>
-  <TD BGCOLOR="#ffffff"><% $opt{'value'} %></TD>
-</TR>
-<%init>
-
-my %opt = @_;
-
-</%init>