Skip to content

Commit

Permalink
Issue #65: use the old value for readonly CustomerCompany fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmalhofer committed Aug 21, 2020
1 parent f9557f6 commit 04e947b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
30 changes: 26 additions & 4 deletions Kernel/Modules/AdminCustomerCompany.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ package Kernel::Modules::AdminCustomerCompany;
use strict;
use warnings;

use Kernel::Language qw(Translatable);
# core modules
use List::Util qw(any);

our $ObjectManagerDisabled = 1;
# CPAN modules

# OTOBO modules
use Kernel::Language qw(Translatable);
use Kernel::System::VariableCheck qw(:all);

our $ObjectManagerDisabled = 1;

sub new {
my ( $Type, %Param ) = @_;

Expand Down Expand Up @@ -99,11 +104,23 @@ sub Run {
my %Errors;
$GetParam{CustomerCompanyID} = $ParamObject->GetParam( Param => 'CustomerCompanyID' );

my @CustomerCompanyMap = $ConfigObject->Get( $GetParam{Source} )->{Map}->@*;

# The readonly fields should not be settable from the WebApp.
# So update with the old values, regardless what was passed from the client.
# The old data is only needed when there are any readonly fields.
my %OldData;
if ( any { $_->[7] } @CustomerCompanyMap ) {
%OldData = $CustomerCompanyObject->CustomerCompanyGet(
CustomerID => $GetParam{CustomerCompanyID},
);
}

# Get dynamic field backend object.
my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend');

ENTRY:
for my $Entry ( @{ $ConfigObject->Get( $GetParam{Source} )->{Map} } ) {
for my $Entry ( @CustomerCompanyMap ) {

# check dynamic fields
if ( $Entry->[5] eq 'dynamic_field' ) {
Expand Down Expand Up @@ -138,6 +155,11 @@ sub Run {
}
}

# reuse the old data for readonly field
elsif ( $Entry->[7] ) {
$GetParam{ $Entry->[0] } = $OldData{ $Entry->[0] };
}

# check remaining non-dynamic-field mandatory fields
else {
$GetParam{ $Entry->[0] } = $ParamObject->GetParam( Param => $Entry->[0] ) // '';
Expand Down Expand Up @@ -180,7 +202,7 @@ sub Run {
my $DynamicFieldObject = $Kernel::OM->Get('Kernel::System::DynamicField');

ENTRY:
for my $Entry ( @{ $ConfigObject->Get( $GetParam{Source} )->{Map} } ) {
for my $Entry ( @CustomerCompanyMap ) {
next ENTRY if $Entry->[5] ne 'dynamic_field';

my $DynamicFieldConfig = $Self->{DynamicFieldLookup}->{ $Entry->[2] };
Expand Down
33 changes: 16 additions & 17 deletions Kernel/System/CustomerCompany/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -910,28 +910,27 @@ sub CustomerCompanyUpdate {
}

# check needed stuff
FIELD:
for my $Entry ( @{ $Self->{CustomerCompanyMap}->{Map} } ) {
if (
!$Param{ $Entry->[0] }
&& $Entry->[5] ne 'dynamic_field' # ignore dynamic fields here
&& $Entry->[4]
&& $Entry->[0] ne 'UserPassword'
)
{
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Entry->[0]!"
);
return;
}
}
next FIELD if $Param{ $Entry->[0] }; # worry only about empty fields, '0' is considered as being empty
next FIELD if $Entry->[5] eq 'dynamic_field'; # do not complain about missing dynamic fields
next FIELD if !$Entry->[4]; # complain only about missing required fields
next FIELD if $Entry->[0] eq 'UserPassword'; # do not complain about missing password field

my @Fields;
my @Values;
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Entry->[0]!"
);

return;
}

# Collect the info needed for the SQL UPDATE statement
# The readonly flag is not honored here.
my ( @Fields, @Values );
FIELD:
for my $Entry ( @{ $Self->{CustomerCompanyMap}->{Map} } ) {
next FIELD if $Entry->[0] =~ /^UserPassword$/i;
next FIELD if $Entry->[0] =~ m/^UserPassword$/i; # skip the password field
next FIELD if $Entry->[5] eq 'dynamic_field'; # skip dynamic fields
push @Fields, $Entry->[2] . ' = ?';
push @Values, \$Param{ $Entry->[0] };
Expand Down

0 comments on commit 04e947b

Please sign in to comment.