From 06efdbe95e7beeb7234f029fae7a012d7d75f586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 18 Mar 2024 11:47:30 +0100 Subject: [PATCH 1/9] Issue #3186: Made condition check more straightforward. --- Kernel/System/DynamicField/ObjectType/Ticket.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel/System/DynamicField/ObjectType/Ticket.pm b/Kernel/System/DynamicField/ObjectType/Ticket.pm index 5a051b723..b3fa848b4 100644 --- a/Kernel/System/DynamicField/ObjectType/Ticket.pm +++ b/Kernel/System/DynamicField/ObjectType/Ticket.pm @@ -289,7 +289,7 @@ sub ObjectDataGet { Param => 'TicketID', ); - return if !$TicketID; + return unless $TicketID; my %TicketData = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet( TicketID => $TicketID, From 328a70fc2417f72c382d40c05056d1dd76c94953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 18 Mar 2024 11:47:55 +0100 Subject: [PATCH 2/9] Issue #3186: Only search for ticket types in Ticket Reference fields if they are present. --- Kernel/System/DynamicField/Driver/Ticket.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Kernel/System/DynamicField/Driver/Ticket.pm b/Kernel/System/DynamicField/Driver/Ticket.pm index 9a97a7e6b..0727112f7 100644 --- a/Kernel/System/DynamicField/Driver/Ticket.pm +++ b/Kernel/System/DynamicField/Driver/Ticket.pm @@ -341,6 +341,12 @@ sub SearchObjects { my $DynamicFieldConfig = $Param{DynamicFieldConfig}; my %SearchParams; + my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); + if ( $ConfigObject->Get('Ticket::Type') ) { + if ( IsArrayRefWithData( $DynamicFieldConfig->{Config}->{TicketType} ) ) { + $SearchParams{TypeIDs} = $DynamicFieldConfig->{Config}->{TicketType}; + } + } if ( $Param{ObjectID} ) { $SearchParams{TicketID} = $Param{ObjectID}; From f2571dda673381b1d791225c0d4191e772616a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 18 Mar 2024 11:48:22 +0100 Subject: [PATCH 3/9] Issue #3186: Perform ACL evaluation also if lens attribute DF sets dynamic content. --- Kernel/System/DynamicField/Driver/Lens.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Kernel/System/DynamicField/Driver/Lens.pm b/Kernel/System/DynamicField/Driver/Lens.pm index b1df7886c..ad37fa756 100644 --- a/Kernel/System/DynamicField/Driver/Lens.pm +++ b/Kernel/System/DynamicField/Driver/Lens.pm @@ -611,6 +611,10 @@ sub GetFieldState { DynamicFieldConfig => $DynamicFieldConfig, Behavior => 'IsACLReducible', ); + my $SetsDynamicContent = $Self->HasBehavior( + DynamicFieldConfig => $DynamicFieldConfig, + Behavior => 'SetsDynamicContent', + ); my %Return; my $ReferenceID = $DFParam->{ $DynamicFieldConfig->{Config}{ReferenceDFName} } ? $DFParam->{ $DynamicFieldConfig->{Config}{ReferenceDFName} }[0] : undef; @@ -693,7 +697,7 @@ sub GetFieldState { } # if this field is non ACL reducible, set the field values - return %Return if !$IsACLReducible; + return %Return if ( !$IsACLReducible && !$SetsDynamicContent ); # get possible values if ACLReducible # this is what the FieldRestrictions object would do for other fields From 0ebee33c72b92d1d9f3db3dce4493531f6df74e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 3 Jun 2024 11:20:30 +0200 Subject: [PATCH 4/9] Issue #3186: Further progress. --- Kernel/Modules/AgentReferenceSearch.pm | 52 +++++++++++++------ .../DynamicField/Driver/BaseReference.pm | 6 ++- Kernel/System/DynamicField/Driver/Lens.pm | 20 ++++++- Kernel/System/DynamicField/Driver/Ticket.pm | 1 - var/httpd/htdocs/js/Core.AJAX.js | 27 ++++++++++ 5 files changed, 88 insertions(+), 18 deletions(-) diff --git a/Kernel/Modules/AgentReferenceSearch.pm b/Kernel/Modules/AgentReferenceSearch.pm index ef574b33d..a4f4bffce 100644 --- a/Kernel/Modules/AgentReferenceSearch.pm +++ b/Kernel/Modules/AgentReferenceSearch.pm @@ -108,24 +108,46 @@ sub Run { # Get config for the dynamic field and check the sanity. my $DynamicFieldBackendObject = $Kernel::OM->Get('Kernel::System::DynamicField::Backend'); - my $DynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet( + my $InitialDynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet( Name => $FieldName, ); - if ( - !IsHashRefWithData($DynamicFieldConfig) - || - !$DynamicFieldBackendObject->HasBehavior( - DynamicFieldConfig => $DynamicFieldConfig, - Behavior => 'IsReferenceField', - ) - ) - { - return $LayoutObject->JSONReply( - Data => { - Success => 0, - Messsage => qq{Error reading the dynamic field '$FieldName'!}, + return unless IsHashRefWithData($InitialDynamicFieldConfig); + + # Check if we deal with a reference field + my $IsReferenceField = $DynamicFieldBackendObject->HasBehavior( + DynamicFieldConfig => $InitialDynamicFieldConfig, + Behavior => 'IsReferenceField', + ); + + my $DynamicFieldConfig; + if ( !$IsReferenceField ) { + + # Check if we deal with a lens field with a reference attribute field + if ( $InitialDynamicFieldConfig->{FieldType} eq 'Lens' ) { + + # TODO perhaps better use 'AttributeDFConfigGet' + $DynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet( + ID => $InitialDynamicFieldConfig->{Config}{AttributeDF}, + ); + return unless IsHashRefWithData($DynamicFieldConfig); + + $IsReferenceField = $DynamicFieldBackendObject->HasBehavior( + DynamicFieldConfig => $DynamicFieldConfig, + Behavior => 'IsReferenceField', + ); + + if ( !$IsReferenceField ) { + return $LayoutObject->JSONReply( + Data => { + Success => 0, + Messsage => qq{Error reading the dynamic field '$FieldName'!}, + } + ); } - ); + } + } + else { + $DynamicFieldConfig = $InitialDynamicFieldConfig; } # search referenced object diff --git a/Kernel/System/DynamicField/Driver/BaseReference.pm b/Kernel/System/DynamicField/Driver/BaseReference.pm index 405a6c634..83f8f4404 100644 --- a/Kernel/System/DynamicField/Driver/BaseReference.pm +++ b/Kernel/System/DynamicField/Driver/BaseReference.pm @@ -1068,7 +1068,11 @@ sub GetFieldState { my $DynamicFieldConfig = $Param{DynamicFieldConfig}; return () if !IsArrayRefWithData( $DynamicFieldConfig->{Config}{ReferenceFilterList} ); - return () if none { $Param{ChangedElements}->{ $_->{EqualsObjectAttribute} // '' } } $DynamicFieldConfig->{Config}{ReferenceFilterList}->@*; + return () + if ( + ( none { $Param{ChangedElements}->{ $_->{EqualsObjectAttribute} // '' } } $DynamicFieldConfig->{Config}{ReferenceFilterList}->@* ) + && !$Param{Lens} + ); my $Value = $Param{GetParam}{DynamicField}{ 'DynamicField_' . $DynamicFieldConfig->{Name} }; diff --git a/Kernel/System/DynamicField/Driver/Lens.pm b/Kernel/System/DynamicField/Driver/Lens.pm index ad37fa756..352d9781a 100644 --- a/Kernel/System/DynamicField/Driver/Lens.pm +++ b/Kernel/System/DynamicField/Driver/Lens.pm @@ -696,8 +696,26 @@ sub GetFieldState { $DFParam->{"DynamicField_$DynamicFieldConfig->{Name}"} = $AttributeFieldValue; } + if ($SetsDynamicContent) { + + my $AttributeDFConfig = $Self->_GetAttributeDFConfig( + LensDynamicFieldConfig => $DynamicFieldConfig, + ); + + my %GetFieldState = $Param{DynamicFieldBackendObject}->GetFieldState( + %Param, + Lens => 1, + DynamicFieldConfig => $AttributeDFConfig, + ); + + return ( + %GetFieldState, + %Return, + ); + } + # if this field is non ACL reducible, set the field values - return %Return if ( !$IsACLReducible && !$SetsDynamicContent ); + return %Return unless $IsACLReducible; # get possible values if ACLReducible # this is what the FieldRestrictions object would do for other fields diff --git a/Kernel/System/DynamicField/Driver/Ticket.pm b/Kernel/System/DynamicField/Driver/Ticket.pm index 0727112f7..790c29111 100644 --- a/Kernel/System/DynamicField/Driver/Ticket.pm +++ b/Kernel/System/DynamicField/Driver/Ticket.pm @@ -521,7 +521,6 @@ sub SearchObjects { } # Support restriction by ticket type when the Ticket::Type feature is activated. - my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); if ( $ConfigObject->Get('Ticket::Type') && !$Param{ExternalSource} ) { if ( IsArrayRefWithData( $DynamicFieldConfig->{Config}{TicketType} ) ) { if ( $SearchParams{TypeIDs} || $SearchParams{Types} ) { diff --git a/var/httpd/htdocs/js/Core.AJAX.js b/var/httpd/htdocs/js/Core.AJAX.js index a4659a2c4..4a84a5391 100644 --- a/var/httpd/htdocs/js/Core.AJAX.js +++ b/var/httpd/htdocs/js/Core.AJAX.js @@ -472,6 +472,33 @@ Core.AJAX = (function (TargetNS) { $Element.val( '' ); $ReferenceElement.val( '' ); } + + // trigger reference search if autocomplete + if ( $Element.is('input') ) { + + var $AutocompleteElement = $Element.parent().find('.DynamicFieldReference'); + + // check for surrounding set and if so, send setindex as request param + var SetIndexStrg = ''; + var SetOuterFieldList = $Element.parents('.DFSetOuterField'); + if ( SetOuterFieldList.length ) { + var MultiValueClass = Array.from(SetOuterFieldList[0].parentElement.classList).find(c => c.startsWith('MultiValue')); + if (MultiValueClass !== undefined && MultiValueClass != '') { + var SetIndexRegExp = new RegExp(/^MultiValue_(\d+)$/); + var MatchResults = SetIndexRegExp.exec(MultiValueClass); + SetIndexStrg = ';SetIndex=' + MatchResults[1]; + } + } + + var URL = Core.Config.Get('Baselink'), + QueryString = "Action=AgentReferenceSearch;ObjectID=" + DataValue[0][0] + + ";Field=" + $AutocompleteElement.attr('id') + + SetIndexStrg + ';'; + + QueryString += Core.AJAX.SerializeForm($Element.closest('form'), {'Action': 1, 'Subaction': 1, 'Term': 1, 'Field': 1, 'MaxResults': 1}); + TargetNS.FunctionCall(URL, QueryString, function (Result) { + }); + } return; } From 26de251cb3e1083bebbfde35fd58d7d87da3af1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 3 Jun 2024 11:22:25 +0200 Subject: [PATCH 5/9] Issue #3186: Removing now obsolete changes on ticket df driver. --- Kernel/System/DynamicField/Driver/Ticket.pm | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Kernel/System/DynamicField/Driver/Ticket.pm b/Kernel/System/DynamicField/Driver/Ticket.pm index 790c29111..9a97a7e6b 100644 --- a/Kernel/System/DynamicField/Driver/Ticket.pm +++ b/Kernel/System/DynamicField/Driver/Ticket.pm @@ -341,12 +341,6 @@ sub SearchObjects { my $DynamicFieldConfig = $Param{DynamicFieldConfig}; my %SearchParams; - my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); - if ( $ConfigObject->Get('Ticket::Type') ) { - if ( IsArrayRefWithData( $DynamicFieldConfig->{Config}->{TicketType} ) ) { - $SearchParams{TypeIDs} = $DynamicFieldConfig->{Config}->{TicketType}; - } - } if ( $Param{ObjectID} ) { $SearchParams{TicketID} = $Param{ObjectID}; @@ -521,6 +515,7 @@ sub SearchObjects { } # Support restriction by ticket type when the Ticket::Type feature is activated. + my $ConfigObject = $Kernel::OM->Get('Kernel::Config'); if ( $ConfigObject->Get('Ticket::Type') && !$Param{ExternalSource} ) { if ( IsArrayRefWithData( $DynamicFieldConfig->{Config}{TicketType} ) ) { if ( $SearchParams{TypeIDs} || $SearchParams{Types} ) { From 2bf09a7803c58a692219a99ef66295ccaa90f817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 10 Jun 2024 15:31:02 +0200 Subject: [PATCH 6/9] Issue #3186: Enhanced error handling in AgentReferenceSearch. --- Kernel/Modules/AgentReferenceSearch.pm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Kernel/Modules/AgentReferenceSearch.pm b/Kernel/Modules/AgentReferenceSearch.pm index a4f4bffce..439f04470 100644 --- a/Kernel/Modules/AgentReferenceSearch.pm +++ b/Kernel/Modules/AgentReferenceSearch.pm @@ -111,7 +111,14 @@ sub Run { my $InitialDynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet( Name => $FieldName, ); - return unless IsHashRefWithData($InitialDynamicFieldConfig); + if ( !IsHashRefWithData($InitialDynamicFieldConfig) ) { + return $LayoutObject->JSONReply( + Data => { + Success => 0, + Messsage => qq{Error reading the dynamic field '$FieldName'!}, + }, + ); + } # Check if we deal with a reference field my $IsReferenceField = $DynamicFieldBackendObject->HasBehavior( @@ -129,7 +136,14 @@ sub Run { $DynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet( ID => $InitialDynamicFieldConfig->{Config}{AttributeDF}, ); - return unless IsHashRefWithData($DynamicFieldConfig); + if ( !IsHashRefWithData($InitialDynamicFieldConfig) ) { + return $LayoutObject->JSONReply( + Data => { + Success => 0, + Messsage => qq{Error reading the dynamic field '$FieldName'!}, + }, + ); + } $IsReferenceField = $DynamicFieldBackendObject->HasBehavior( DynamicFieldConfig => $DynamicFieldConfig, @@ -141,7 +155,7 @@ sub Run { Data => { Success => 0, Messsage => qq{Error reading the dynamic field '$FieldName'!}, - } + }, ); } } From 8a0f67056ca1fa947972a5a6dd30a49f5d858392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Thu, 12 Sep 2024 12:54:01 +0200 Subject: [PATCH 7/9] Issue #3186: Re-correct dynamic field name for lens autocomplete fields. --- Kernel/Modules/AgentReferenceSearch.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/Kernel/Modules/AgentReferenceSearch.pm b/Kernel/Modules/AgentReferenceSearch.pm index 439f04470..89a0f43e8 100644 --- a/Kernel/Modules/AgentReferenceSearch.pm +++ b/Kernel/Modules/AgentReferenceSearch.pm @@ -158,6 +158,7 @@ sub Run { }, ); } + $DynamicFieldConfig->{Name} = $FieldName; } } else { From 116dc0a725c6ca3194cb45c2d19325f092f68e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 30 Sep 2024 14:39:47 +0200 Subject: [PATCH 8/9] Issue #3186: Updated dynamic field lens restrictions. --- Kernel/Modules/AdminDynamicFieldLens.pm | 42 +++++++++---------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/Kernel/Modules/AdminDynamicFieldLens.pm b/Kernel/Modules/AdminDynamicFieldLens.pm index 6b226a3f6..27c030222 100644 --- a/Kernel/Modules/AdminDynamicFieldLens.pm +++ b/Kernel/Modules/AdminDynamicFieldLens.pm @@ -42,35 +42,23 @@ sub new { # field types which are usable as attribute df $Self->{IsAttributeFieldCapable} = { - - # see https://github.com/RotherOSS/issues/3186 - Agent => 0, + Agent => 1, Checkbox => 1, # see https://github.com/RotherOSS/otobo/issues/3809 - ContactWD => 0, - - # see https://github.com/RotherOSS/issues/3186 - CustomerCompany => 0, - - # see https://github.com/RotherOSS/issues/3186 - CustomerUser => 0, + ContactWD => 0, + CustomerCompany => 1, + CustomerUser => 1, # see https://github.com/RotherOSS/otobo/issues/3793 - Database => 0, - Date => 1, - DateTime => 1, - Dropdown => 1, - - # see https://github.com/RotherOSS/issues/3186 - FAQ => 0, - GeneralCatalog => 1, - - # see https://github.com/RotherOSS/issues/3186 - ITSMConfigItem => 0, - - # see https://github.com/RotherOSS/issues/3186 - ITSMConfigItemVersion => 0, + Database => 0, + Date => 1, + DateTime => 1, + Dropdown => 1, + FAQ => 1, + GeneralCatalog => 1, + ITSMConfigItem => 1, + ITSMConfigItemVersion => 1, # see https://github.com/RotherOSS/otobo/issues/3789 Lens => 0, @@ -86,10 +74,8 @@ sub new { Set => 1, Text => 1, TextArea => 1, - - # see https://github.com/RotherOSS/issues/3186 - Ticket => 0, - Title => 1, + Ticket => 1, + Title => 1, # see https://github.com/RotherOSS/otobo/issues/3446 WebService => 0, From 1974050762362f72946ccea3c301802a7f6b4064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=A4rter?= Date: Mon, 30 Sep 2024 14:45:19 +0200 Subject: [PATCH 9/9] Issue #3186: Removed small change. --- Kernel/System/DynamicField/ObjectType/Ticket.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel/System/DynamicField/ObjectType/Ticket.pm b/Kernel/System/DynamicField/ObjectType/Ticket.pm index b3fa848b4..5a051b723 100644 --- a/Kernel/System/DynamicField/ObjectType/Ticket.pm +++ b/Kernel/System/DynamicField/ObjectType/Ticket.pm @@ -289,7 +289,7 @@ sub ObjectDataGet { Param => 'TicketID', ); - return unless $TicketID; + return if !$TicketID; my %TicketData = $Kernel::OM->Get('Kernel::System::Ticket')->TicketGet( TicketID => $TicketID,