From: ivan Date: Thu, 17 Jun 2010 02:08:53 +0000 (+0000) Subject: Add "View customers of all agents" access rights, RT#7010 X-Git-Tag: root_of_svc_elec_features~150 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=8966833a87b9a002c9d72c56832e35b55628dc81 Add "View customers of all agents" access rights, RT#7010 --- diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index 08d31d263..1e1b9ead3 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -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 diff --git a/FS/FS/access_user.pm b/FS/FS/access_user.pm index 1bf6e9387..25aa8af01 100644 --- a/FS/FS/access_user.pm +++ b/FS/FS/access_user.pm @@ -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 ). ' )'; } diff --git a/httemplate/browse/part_event.html b/httemplate/browse/part_event.html index 674004bc7..3d7c245ac 100644 --- a/httemplate/browse/part_event.html +++ b/httemplate/browse/part_event.html @@ -158,7 +158,8 @@ $html_init .= ''. 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; diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index e226ce13e..42eb5dfcb 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -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 = " diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html index ebbc2f778..53419cde0 100644 --- a/httemplate/edit/process/elements/process.html +++ b/httemplate/edit/process/elements/process.html @@ -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'}); diff --git a/httemplate/edit/prospect_main.html b/httemplate/edit/prospect_main.html index 90f971a91..e867907ed 100644 --- a/httemplate/edit/prospect_main.html +++ b/httemplate/edit/prospect_main.html @@ -109,6 +109,6 @@ my $m2_error_callback = sub { $cgi->param; }; -my @agentnums = $FS::CurrentUser::CurrentUser->agentnums; +#my @agentnums = $FS::CurrentUser::CurrentUser->agentnums; diff --git a/httemplate/view/cust_main/misc.html b/httemplate/view/cust_main/misc.html index b98e9dc3e..8bcab0df5 100644 --- a/httemplate/view/cust_main/misc.html +++ b/httemplate/view/cust_main/misc.html @@ -10,7 +10,8 @@ <% ucfirst($cust_main->status) %> -%unless ( scalar(@agentnums) == 1 ) { +%unless ( scalar(@agentnums) == 1 +% && !$curuser->access_right('View customers of all agents') ) { % my $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } ); Agent diff --git a/httemplate/view/prospect_main.html b/httemplate/view/prospect_main.html index 9883e6766..9517e3920 100644 --- a/httemplate/view/prospect_main.html +++ b/httemplate/view/prospect_main.html @@ -14,7 +14,8 @@ <% $prospectnum %> -%unless ( scalar(@agentnums) == 1 ) { +%unless ( scalar(@agentnums) == 1 +% && !$curuser->access_right('View customers of all agents') ) { % my $agent = qsearchs('agent',{ 'agentnum' => $prospect_main->agentnum } ); Agent diff --git a/httemplate/view/svc_acct/tr.html b/httemplate/view/svc_acct/tr.html deleted file mode 100644 index e2ec7d42f..000000000 --- a/httemplate/view/svc_acct/tr.html +++ /dev/null @@ -1,9 +0,0 @@ - - <% $opt{'label'} %> - <% $opt{'value'} %> - -<%init> - -my %opt = @_; - -