X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_svc.pm;h=0bef7bcf5f23ecd1201326e5ab5f41aafb80f91c;hp=7f22411e0ec338a690350e99e43fdd491968899b;hb=7e6ab4562bb5490ca82422d91b6389fd844ea6ff;hpb=0af38652da3b3be7da2d35b048285ef6f2194e1a diff --git a/FS/FS/part_svc.pm b/FS/FS/part_svc.pm index 7f22411e0..0bef7bcf5 100644 --- a/FS/FS/part_svc.pm +++ b/FS/FS/part_svc.pm @@ -58,6 +58,17 @@ L, and L, among others. =item preserve - Preserve after cancellation, empty or 'Y' +=item selfservice_access - Access allowed to the service via self-service: +empty for full access, "readonly" for read-only, "hidden" to hide it entirely + +=item restrict_edit_password - Require the "Provision customer service" access +right to change the password field, rather than just "Edit password". Only +relevant to svc_acct for now. + +=item has_router - Allow the service to have an L connected +through it. Probably only relevant to svc_broadband, svc_acct, and svc_dsl +for now. + =back =head1 METHODS @@ -103,12 +114,8 @@ TODOC: JOB sub insert { my $self = shift; my @fields = (); - my @exportnums = (); @fields = @{shift(@_)} if @_; - if ( @_ ) { - my $exportnums = shift; - @exportnums = grep $exportnums->{$_}, keys %$exportnums; - } + my $exportnums = shift || {}; my $job = ''; $job = shift if @_; @@ -181,12 +188,14 @@ sub insert { } # add export_svc records + my @exportnums = grep $exportnums->{$_}, keys %$exportnums; my $slice = 100/scalar(@exportnums) if @exportnums; my $done = 0; foreach my $exportnum ( @exportnums ) { my $export_svc = new FS::export_svc ( { 'exportnum' => $exportnum, 'svcpart' => $self->svcpart, + 'role' => $exportnums->{$exportnum}, } ); $error = $export_svc->insert($job, $slice*$done++, $slice); if ( $error ) { @@ -317,9 +326,10 @@ sub replace { # maintain export_svc records - if ( $exportnums ) { + if ( $exportnums ) { # hash of exportnum => role #false laziness w/ edit/process/agent_type.cgi + #and, more importantly, with m2m_Common my @new_export_svc = (); foreach my $part_export ( qsearch('part_export', {}) ) { my $exportnum = $part_export->exportnum; @@ -329,13 +339,23 @@ sub replace { }; my $export_svc = qsearchs('export_svc', $hashref); - if ( $export_svc && ! $exportnums->{$exportnum} ) { - $error = $export_svc->delete; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; + if ( $export_svc ) { + my $old_role = $export_svc->role || 1; # 1 = null in the db + if ( ! $exportnums->{$exportnum} + or $old_role ne $exportnums->{$exportnum} ) { + + $error = $export_svc->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + undef $export_svc; # on a role change, force it to be reinserted + } - } elsif ( ! $export_svc && $exportnums->{$exportnum} ) { + } # if $export_svc + if ( ! $export_svc && $exportnums->{$exportnum} ) { + # also applies if it's been undef'd because of role change + $hashref->{role} = $exportnums->{$exportnum}; push @new_export_svc, new FS::export_svc ( $hashref ); } @@ -387,11 +407,13 @@ sub check { $self->ut_numbern('svcpart') || $self->ut_text('svc') || $self->ut_alpha('svcdb') - || $self->ut_enum('disabled', [ '', 'Y' ] ) - || $self->ut_enum('preserve', [ '', 'Y' ] ) + || $self->ut_flag('disabled') + || $self->ut_flag('preserve') || $self->ut_enum('selfservice_access', [ '', 'hidden', 'readonly' ] ) || $self->ut_foreign_keyn('classnum', 'part_svc_class', 'classnum' ) - ; + || $self->ut_flag('restrict_edit_password') + || $self->ut_flag('has_router') +; return $error if $error; my @fields = eval { fields( $self->svcdb ) }; #might die @@ -441,9 +463,10 @@ sub part_export { my $self = shift; my %search; $search{'exporttype'} = shift if @_; - sort { $a->weight <=> $b->weight } - map { qsearchs('part_export', { 'exportnum' => $_->exportnum, %search } ) } - qsearch('export_svc', { 'svcpart' => $self->svcpart } ); + map { $_ } #behavior of sort undefined in scalar context + sort { $a->weight <=> $b->weight } + map { qsearchs('part_export', { 'exportnum'=>$_->exportnum, %search } ) } + qsearch('export_svc', { 'svcpart'=>$self->svcpart } ); } =item part_export_usage @@ -748,11 +771,9 @@ sub process { if ( $flag =~ /^[MAH]$/ ) { $param->{ $f } = delete( $param->{ $f.'_classnum' } ); } - if ( $flag =~ /^S$/ - or $_ eq 'usergroup' ) { - $param->{ $f } = ref($param->{ $f }) - ? join(',', @{$param->{ $f }} ) - : $param->{ $f }; + if ( ( $flag =~ /^[MAHS]$/ or $_ eq 'usergroup' ) + and ref($param->{ $f }) ) { + $param->{ $f } = join(',', @{ $param->{ $f } }); } ( $f, $f.'_flag', $f.'_label' ); } @@ -765,7 +786,13 @@ sub process { my %exportnums = map { $_->exportnum => ( $param->{'exportnum'.$_->exportnum} || '') } qsearch('part_export', {} ); - + foreach my $exportnum (%exportnums) { + my $role = $param->{'exportnum'.$exportnum.'_role'}; + # role is undef if the export has no role selector + if ( $exportnums{$exportnum} && $role ) { + $exportnums{$exportnum} = $role; + } + } my $error; if ( $param->{'svcpart'} ) { $error = $new->replace( $old,