[freeside-commits] freeside/FS/FS part_referral.pm, 1.6, 1.7 access_user.pm, 1.7, 1.8

Ivan,,, ivan at wavetail.420.am
Fri Aug 11 01:02:28 PDT 2006


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv9900/FS/FS

Modified Files:
	part_referral.pm access_user.pm 
Log Message:
virtualize referrals on customer addition

Index: access_user.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/access_user.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- access_user.pm	10 Aug 2006 11:55:50 -0000	1.7
+++ access_user.pm	11 Aug 2006 08:02:26 -0000	1.8
@@ -5,6 +5,7 @@
 use FS::Record qw( qsearch qsearchs dbh );
 use FS::m2m_Common;
 use FS::access_usergroup;
+use FS::agent;
 
 @ISA = qw( FS::m2m_Common FS::Record );
 
@@ -318,6 +319,21 @@
   $sth->fetchrow_arrayref->[0];
 }
 
+=item agents
+
+Returns the list of agents this user can view (via group membership), as
+FS::agent objects.
+
+=cut
+
+sub agents {
+  my $self = shift;
+  qsearch({
+    'table'     => 'agent',
+    'hashref'   => { disabled=>'' },
+    'extra_sql' => ' AND '. $self->agentnums_sql,
+  });
+}
 
 =item access_right
 

Index: part_referral.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_referral.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- part_referral.pm	10 Aug 2006 13:50:44 -0000	1.6
+++ part_referral.pm	11 Aug 2006 08:02:26 -0000	1.7
@@ -124,30 +124,37 @@
 
 =over 4
 
-=item acl_agentnum_sql
+=item acl_agentnum_sql [ INCLUDE_GLOBAL_BOOL ]
 
 Returns an SQL fragment for searching for part_referral records allowed by the
 current users's agent ACLs (and "Edit global advertising sources" right).
 
+Pass a true value to include global advertising sources (for example, when
+simply using rather than editing advertising sources).
+
 =cut
 
 sub acl_agentnum_sql {
-  #my $class = shift;
+  my $self = shift;
 
   my $curuser = $FS::CurrentUser::CurrentUser;
   my $sql = $curuser->agentnums_sql;
   $sql = " ( $sql OR agentnum IS NULL ) "
-    if $curuser->access_right('Edit global advertising sources');
+    if $curuser->access_right('Edit global advertising sources')
+    or defined($_[0]) && $_[0];
 
   $sql;
 
 }
 
-=item all_part_referral
+=item all_part_referral [ INCLUDE_GLOBAL_BOOL ]
 
 Returns all part_referral records allowed by the current users's agent ACLs
 (and "Edit global advertising sources" right).
 
+Pass a true value to include global advertising sources (for example, when
+simply using rather than editing advertising sources).
+
 =cut
 
 sub all_part_referral {
@@ -155,12 +162,12 @@
 
   qsearch({
     'table'     => 'part_referral',
-    'extra_sql' => ' WHERE '. $self->acl_agentnum_sql. ' ORDER BY refnum ',
+    'extra_sql' => ' WHERE '. $self->acl_agentnum_sql(@_). ' ORDER BY refnum ',
   });
 
 }
 
-=item num_part_referral
+=item num_part_referral [ INCLUDE_GLOBAL_BOOL ]
 
 Returns the number of part_referral records allowed by the current users's
 agent ACLs (and "Edit global advertising sources" right).
@@ -171,7 +178,7 @@
   my $self = shift;
 
   my $sth = dbh->prepare(
-    'SELECT COUNT(*) FROM part_referral WHERE '. $self->acl_agentnum_sql
+    'SELECT COUNT(*) FROM part_referral WHERE '. $self->acl_agentnum_sql(@_)
   ) or die dbh->errstr;
   $sth->execute() or die $sth->errstr;
   $sth->fetchrow_arrayref->[0];



More information about the freeside-commits mailing list