X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Faccess_user.pm;h=de3c8847c080cb303f53d052b2759d5267c68750;hb=9b27a2b16c37b060ef48029581e4196990a9963b;hp=72e9140688716a79c5286cdc38277f93f71366e1;hpb=efa7c9c0233f2c3d1e39d62f17cac30b36f593c4;p=freeside.git diff --git a/FS/FS/access_user.pm b/FS/FS/access_user.pm index 72e914068..de3c8847c 100644 --- a/FS/FS/access_user.pm +++ b/FS/FS/access_user.pm @@ -10,6 +10,8 @@ use FS::access_user_pref; use FS::access_usergroup; use FS::agent; use FS::cust_main; +use FS::sales; +use FS::sched_item; $DEBUG = 0; $me = '[FS::access_user]'; @@ -132,9 +134,8 @@ sub insert { sub htpasswd_kludge { my $self = shift; - - #awful kludge to skip setting htpasswd for fs_* users - return '' if $self->username =~ /^fs_/; + + return '' if $self->is_system_user; unshift @_, '-c' unless -e $htpasswd_file; if ( @@ -255,6 +256,7 @@ sub check { || $self->ut_text('last') || $self->ut_text('first') || $self->ut_foreign_keyn('user_custnum', 'cust_main', 'custnum') + || $self->ut_foreign_keyn('report_salesnum', 'sales', 'salesnum') || $self->ut_enum('disabled', [ '', 'Y' ] ) ; return $error if $error; @@ -287,6 +289,18 @@ sub user_cust_main { qsearchs( 'cust_main', { 'custnum' => $self->user_custnum } ); } +=item report_sales + +Returns the FS::sales object (see L), if any, for this +user. + +=cut + +sub report_sales { + my $self = shift; + qsearchs( 'sales', { 'salesnum' => $self->report_salesnum } ); +} + =item access_usergroup Returns links to the the groups this user is a part of, as FS::access_usergroup @@ -428,6 +442,7 @@ sub agents { 'table' => 'agent', 'hashref' => { disabled=>'' }, 'extra_sql' => ' AND '. $self->agentnums_sql(@_), + 'order_by' => 'ORDER BY agent', }); } @@ -455,7 +470,7 @@ sub access_right { unless ( grep !exists($self->{_ACLcache}{$_}), @$rightname ) { warn "$me ACL cache hit for ". join(', ', @$rightname). "\n" if $DEBUG; - return grep $self->{_ACLcache}{$_}, @$rightname + return scalar( grep $self->{_ACLcache}{$_}, @$rightname ); } warn "$me ACL cache miss for ". join(', ', @$rightname). "\n" @@ -499,7 +514,7 @@ sub access_right { Returns the default customer view for this user, from the "default_customer_view" user preference, the "cust_main-default_view" config, -or the hardcoded default, "jumbo" (may change to "basics" in the near future). +or the hardcoded default, "basics" (formerly "jumbo" prior to 3.0). =cut @@ -508,8 +523,68 @@ sub default_customer_view { $self->option('default_customer_view') || $conf->config('cust_main-default_view') - || 'jumbo'; #'basics' in 1.9.1? + || 'basics'; #s/jumbo/basics/ starting with 3.0 + +} + +=item spreadsheet_format [ OVERRIDE ] + +Returns a hashref of this user's Excel spreadsheet download settings: +'extension' (xls or xlsx), 'class' (Spreadsheet::WriteExcel or +Excel::Writer::XLSX), and 'mime_type'. If OVERRIDE is 'XLS' or 'XLSX', +use that instead of the user's setting. + +=cut +# is there a better place to put this? +my %formats = ( + XLS => { + extension => '.xls', + class => 'Spreadsheet::WriteExcel', + mime_type => 'application/vnd.ms-excel', + }, + XLSX => { + extension => '.xlsx', + class => 'Excel::Writer::XLSX', + mime_type => # it's on wikipedia, it must be true + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + } +); + +sub spreadsheet_format { + my $self = shift; + my $override = shift; + + my $f = $override + || $self->option('spreadsheet_format') + || $conf->config('spreadsheet_format') + || 'XLS'; + + $formats{$f}; +} + +=item is_system_user + +Returns true if this user has the name of a known system account. These +users will not appear in the htpasswd file and can't have passwords set. + +=cut + +sub is_system_user { + my $self = shift; + return grep { $_ eq $self->username } ( qw( + fs_queue + fs_daily + fs_selfservice + fs_signup + fs_bootstrap + fs_selfserv +) ); +} + +sub sched_item { + my $self = shift; + qsearch( 'sched_item', { 'usernum' => $self->usernum } ); } =back