encryption fixes from huntsberg & jayce
[freeside.git] / FS / FS / access_user.pm
index f32fa3a..7529354 100644 (file)
@@ -5,6 +5,7 @@ use vars qw( @ISA $htpasswd_file );
 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 );
 
@@ -213,7 +214,7 @@ sub check {
 
   my $error = 
     $self->ut_numbern('usernum')
-    || $self->ut_text('username')
+    || $self->ut_alpha('username')
     || $self->ut_text('_password')
     || $self->ut_text('last')
     || $self->ut_text('first')
@@ -296,9 +297,14 @@ Returns an sql fragement to select only agentnums this user can view.
 
 sub agentnums_sql {
   my $self = shift;
-  '( '.
-    join( ' OR ', map "agentnum = $_", $self->agentnums ).
-  ' )';
+
+  my @agentnums = map { "agentnum = $_" } $self->agentnums;
+
+  push @agentnums, 'agentnum IS NULL'
+    if $self->access_right('View/link unlinked services');
+
+  return ' 1 = 0 ' unless scalar(@agentnums);
+  '( '. join( ' OR ', @agentnums ). ' )';
 }
 
 =item agentnum
@@ -318,6 +324,21 @@ sub agentnum {
   $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