/usr/share/otrs/Kernel/Modules/AdminGenericInterfaceInvokerEvent.pm is in otrs2 6.0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | # --
# Copyright (C) 2001-2018 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::Modules::AdminGenericInterfaceInvokerEvent;
use strict;
use warnings;
use Kernel::Language qw(Translatable);
use Kernel::System::VariableCheck qw(:all);
our $ObjectManagerDisabled = 1;
sub new {
my ( $Type, %Param ) = @_;
my $Self = {%Param};
bless( $Self, $Type );
$Self->{DeletedString} = '_GenericInterface_Invoker_Event_DeletedString_Dont_Use_It_String_Please';
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
my $WebserviceObject = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice');
my $WebserviceID = $ParamObject->GetParam( Param => 'WebserviceID' );
if ( !$WebserviceID ) {
return $LayoutObject->ErrorScreen(
Message => Translatable("Need WebserviceID!"),
);
}
my $Invoker = $ParamObject->GetParam( Param => 'Invoker' );
if ( !$Invoker ) {
return $LayoutObject->ErrorScreen(
Message => Translatable("Need Invoker!"),
);
}
my $Event = $ParamObject->GetParam( Param => 'Event' );
if ( !$Event ) {
return $LayoutObject->ErrorScreen(
Message => Translatable("Need Event!"),
);
}
# Get configured Invoker registrations.
my $InvokerModules = $Kernel::OM->Get('Kernel::Config')->Get('GenericInterface::Invoker::Module');
# Check for valid Invoker registration.
if ( !IsHashRefWithData($InvokerModules) ) {
return $LayoutObject->ErrorScreen(
Message => "Could not get registered modules for Invoker",
);
}
# Get web service configuration.
my $WebserviceData = $WebserviceObject->WebserviceGet( ID => $WebserviceID );
# Check for valid web service configuration.
if ( !IsHashRefWithData($WebserviceData) ) {
return $LayoutObject->ErrorScreen(
Message => "Could not get data for WebserviceID $WebserviceID",
);
}
if ( !IsHashRefWithData( $WebserviceData->{Config}->{Requester}->{Invoker}->{$Invoker} ) ) {
return $LayoutObject->ErrorScreen(
Message => "Could not determine config for invoker $Invoker",
);
}
my $InvokerConfig = $WebserviceData->{Config}->{Requester}->{Invoker}->{$Invoker};
my $InvokerType = $InvokerConfig->{Type};
# Check for valid InvokerType backend.
if ( !$InvokerType ) {
return $LayoutObject->ErrorScreen(
Message => "Could not get backend for Invoker $Invoker",
);
}
# Get the configuration dialog for the event.
my $InvokerEventFrontendModule = $InvokerModules->{$InvokerType}->{'EventEditDialog'}
|| 'AdminGenericInterfaceInvokerEvent';
# Get the configuration dialog for the Invoker.
my $InvokerTypeFrontendModule = $InvokerModules->{$InvokerType}->{'ConfigDialog'};
my $WebserviceName = $WebserviceData->{Name};
my @InvokerEvents = @{ $InvokerConfig->{Events} };
# Get list of all registered events.
my %RegisteredEvents = $Kernel::OM->Get('Kernel::System::Event')->EventList();
# Prepare details.
my $EventType;
my $Condition;
my $Asynchronous;
# Loop trough invoker events and compare them with current event.
INVOKEREVENT:
for my $InvokerEvent (@InvokerEvents) {
next INVOKEREVENT if $Event ne $InvokerEvent->{Event};
# Set the event type (event object like Article or Ticket) and event condition
EVENTTYPE:
for my $Type ( sort keys %RegisteredEvents ) {
if ( grep { $_ eq $InvokerEvent->{Event} } @{ $RegisteredEvents{$Type} || [] } ) {
$EventType = $Type;
$Condition = $InvokerEvent->{Condition};
$Asynchronous = $InvokerEvent->{Asynchronous};
last EVENTTYPE;
}
}
last INVOKEREVENT;
}
# Check if we found a valid event
if ( !$EventType ) {
return $LayoutObject->ErrorScreen(
Message => "The event $Event is not valid.",
);
}
$LayoutObject->AddJSData(
Key => 'InvokerEvent',
Value => {
WebserviceID => $WebserviceID,
Invoker => $Invoker,
Event => $Event,
InvokerTypeFrontendModule => $InvokerTypeFrontendModule,
},
);
# ------------------------------------------------------------ #
# sub-action Change: load web service and show edit screen
# ------------------------------------------------------------ #
if ( $Self->{Subaction} eq 'Add' || $Self->{Subaction} eq 'Change' ) {
return $Self->_ShowEdit(
%Param,
WebserviceID => $WebserviceID,
WebserviceName => $WebserviceName,
Invoker => $Invoker,
InvokerType => $InvokerType,
InvokerTypeFrontendModule => $InvokerTypeFrontendModule,
InvokerEventFrontendModule => $InvokerEventFrontendModule,
Event => $Event,
EventType => $EventType,
Condition => $Condition,
Asynchronous => $Asynchronous,
Action => 'Change',
);
}
# ------------------------------------------------------------ #
# sub-action ChangeAction: write config and return to overview
# ------------------------------------------------------------ #
elsif ( $Self->{Subaction} eq 'ChangeAction' ) {
# challenge token check for write action
$LayoutObject->ChallengeTokenCheck();
# get parameter from web browser
my $GetParam = $Self->_GetParams();
# if there is an error return to edit screen
if ( $GetParam->{Error} ) {
return $Self->_ShowEdit(
%Param,
WebserviceID => $WebserviceID,
WebserviceName => $WebserviceName,
Invoker => $Invoker,
InvokerType => $InvokerType,
InvokerTypeFrontendModule => $InvokerTypeFrontendModule,
InvokerEventFrontendModule => $InvokerEventFrontendModule,
Event => $Event,
EventType => $EventType,
Condition => $Condition,
Asynchronous => $Asynchronous,
Action => 'Change',
);
}
my %NewCondition = (
Condition => $GetParam->{Config},
);
# This loop goes through the Array of Hashes of
# @{ $WebserviceData->{Config}->{Requester}->{Invoker}->{$Invoker}->{Events} }.
#
# If it stumbles upon the array containing the HashKeys "Event" and this Key equals
# $Event, it takes the Original Hash and extends the keys by the keys of %NewCondition.
#
# If it doesn't match $Event it takes the original unchanged HashRef
# (e.g. just extending one single hash of all existing hashes inside the Events Array).
my @NewEventsArray;
for my $EventsHashRef ( @{ $WebserviceData->{Config}->{Requester}->{Invoker}->{$Invoker}->{Events} } ) {
if ( $EventsHashRef->{Event} && $EventsHashRef->{Event} eq $Event ) {
push @NewEventsArray, {
%{$EventsHashRef},
%NewCondition,
Asynchronous => $GetParam->{Asynchronous},
};
}
else {
push @NewEventsArray, $EventsHashRef;
}
}
$WebserviceData->{Config}->{Requester}->{Invoker}->{$Invoker}->{Events} = \@NewEventsArray;
# Otherwise save configuration and return to overview screen.
my $Success = $WebserviceObject->WebserviceUpdate(
ID => $WebserviceID,
Name => $WebserviceData->{Name},
Config => $WebserviceData->{Config},
ValidID => $WebserviceData->{ValidID},
UserID => $Self->{UserID},
);
# Check for successful web service update.
if ( !$Success ) {
return $LayoutObject->ErrorScreen(
Message => "Could not update configuration data for WebserviceID $WebserviceID",
);
}
# Save and finish button: go to web service.
if ( $ParamObject->GetParam( Param => 'ReturnToAction' ) ) {
my $RedirectURL = "Action=$InvokerTypeFrontendModule;Subaction=Change;Invoker=$Invoker;"
. "WebserviceID=$WebserviceID;";
return $LayoutObject->Redirect(
OP => $RedirectURL,
);
}
# Recreate structure for edit.
$Condition = $NewCondition{Condition};
$Asynchronous = $GetParam->{Asynchronous};
# Check if stay on invoker events screen or redirect to previous screen.
return $Self->_ShowEdit(
%Param,
WebserviceID => $WebserviceID,
WebserviceName => $WebserviceName,
Invoker => $Invoker,
InvokerType => $InvokerType,
InvokerTypeFrontendModule => $InvokerTypeFrontendModule,
InvokerEventFrontendModule => $InvokerEventFrontendModule,
Event => $Event,
EventType => $EventType,
Condition => $Condition,
Asynchronous => $Asynchronous,
Action => 'Change',
);
}
elsif ( $Self->{Subaction} eq 'Delete' ) {
# challenge token check for write action
$LayoutObject->ChallengeTokenCheck();
EVENTCONFIG:
for my $EventConfig ( @{ $WebserviceData->{Config}->{Requester}->{Invoker}->{$Invoker}->{Events} } ) {
next EVENTCONFIG if $EventConfig->{Event} ne $Event;
delete $EventConfig->{Condition};
last EVENTCONFIG;
}
# Otherwise save configuration and return to overview screen.
my $Success = $WebserviceObject->WebserviceUpdate(
ID => $WebserviceID,
Name => $WebserviceData->{Name},
Config => $WebserviceData->{Config},
ValidID => $WebserviceData->{ValidID},
UserID => $Self->{UserID},
);
# build JSON output
my $JSON = $LayoutObject->JSONEncode(
Data => {
Success => $Success,
},
);
# send JSON response
return $LayoutObject->Attachment(
ContentType => 'application/json; charset=' . $LayoutObject->{Charset},
Content => $JSON,
Type => 'inline',
NoCache => 1,
);
}
# ------------------------------------------------------------ #
# Error
# ------------------------------------------------------------ #
else {
return $LayoutObject->ErrorScreen(
Message => "This sub-action is not valid",
);
}
}
sub _ShowEdit {
my ( $Self, %Param ) = @_;
my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
my $ConditionData = $Param{Condition} || {};
# Set action for go back button
$Param{LowerCaseActionType} = lc 'Invoker';
my $Output = $LayoutObject->Header();
$Output .= $LayoutObject->NavigationBar();
my %Error;
if ( defined $Param{WebserviceData}->{Error} ) {
%Error = %{ $Param{WebserviceData}->{Error} };
}
$Param{DeletedString} = $Self->{DeletedString};
$Param{FreshConditionLinking} = $LayoutObject->BuildSelection(
Data => [ 'and', 'or', 'xor' ],
Name => "ConditionLinking[_INDEX_]",
Sort => 'AlphanumericKey',
Translation => 1,
Class => 'Modernize W50pc',
);
$Param{FreshConditionFieldType} = $LayoutObject->BuildSelection(
Data => {
'String' => 'String',
'Regexp' => 'Regexp',
'Module' => 'Validation Module'
},
SelectedID => 'String',
Name => "ConditionFieldType[_INDEX_][_FIELDINDEX_]",
Sort => 'AlphanumericKey',
Translation => 1,
Class => 'Modernize',
);
if (
defined $Param{Action}
&& $Param{Action} eq 'Change'
&& IsHashRefWithData( $Param{Condition} )
&& IsHashRefWithData( $Param{Condition}->{Condition} )
&& IsStringWithData( $Param{Condition}->{ConditionLinking} )
)
{
$Param{OverallConditionLinking} = $LayoutObject->BuildSelection(
Data => [ 'and', 'or', 'xor' ],
Name => 'OverallConditionLinking',
ID => 'OverallConditionLinking',
Sort => 'AlphanumericKey',
Translation => 1,
Class => 'Modernize',
SelectedID => $ConditionData->{ConditionLinking},
);
my @Conditions = sort keys %{ $ConditionData->{Condition} };
for my $Condition (@Conditions) {
my %ConditionData = %{ $ConditionData->{Condition}->{$Condition} };
my $ConditionLinking = $LayoutObject->BuildSelection(
Data => [ 'and', 'or', 'xor' ],
Name => "ConditionLinking[$Condition]",
Sort => 'AlphanumericKey',
Translation => 1,
Class => 'Modernize',
SelectedID => $ConditionData{Type},
);
$LayoutObject->Block(
Name => 'ConditionItemEditRow',
Data => {
ConditionLinking => $ConditionLinking,
Index => $Condition,
},
);
my @Fields = sort keys %{ $ConditionData{Fields} };
for my $Field (@Fields) {
my %FieldData = %{ $ConditionData{Fields}->{$Field} };
my $ConditionFieldType = $LayoutObject->BuildSelection(
Data => {
'String' => 'String',
'Regexp' => 'Regexp',
'Module' => 'Validation Module'
},
Name => "ConditionFieldType[$Condition][$Field]",
Sort => 'AlphanumericKey',
Translation => 1,
SelectedID => $FieldData{Type},
Class => 'Modernize',
);
# Show fields.
$LayoutObject->Block(
Name => "ConditionItemEditRowField",
Data => {
Index => $Condition,
FieldIndex => $Field,
ConditionFieldType => $ConditionFieldType,
%FieldData,
},
);
}
}
}
else {
$Param{OverallConditionLinking} = $LayoutObject->BuildSelection(
Data => [ 'and', 'or', 'xor' ],
Name => 'OverallConditionLinking',
ID => 'OverallConditionLinking',
Sort => 'AlphanumericKey',
Translation => 1,
Class => 'Modernize W50pc',
);
$Param{ConditionLinking} = $LayoutObject->BuildSelection(
Data => [ 'and', 'or', 'xor' ],
Name => 'ConditionLinking[_INDEX_]',
Sort => 'AlphanumericKey',
Translation => 1,
Class => 'Modernize W50pc',
);
$Param{ConditionFieldType} = $LayoutObject->BuildSelection(
Data => {
'String' => 'String',
'Regexp' => 'Regexp',
'Module' => 'Validation Module'
},
Name => 'ConditionFieldType[_INDEX_][_FIELDINDEX_]',
Sort => 'AlphanumericKey',
Translation => 1,
SelectedID => 'String',
Class => 'Modernize',
);
$LayoutObject->Block(
Name => 'ConditionItemInitRow',
Data => {
%Param,
},
);
}
$Output .= $LayoutObject->Output(
TemplateFile => $Param{InvokerEventFrontendModule},
Data => {
%Param,
%{$ConditionData},
},
);
$Output .= $LayoutObject->Footer();
return $Output;
}
sub _GetParams {
my ( $Self, %Param ) = @_;
my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');
my $GetParam;
# Get parameters from web browser.
$GetParam->{Name} = $ParamObject->GetParam( Param => 'Name' ) || '';
$GetParam->{ConditionConfig} = $ParamObject->GetParam( Param => 'ConditionConfig' )
|| '';
my $Config = $Kernel::OM->Get('Kernel::System::JSON')->Decode(
Data => $GetParam->{ConditionConfig}
);
$GetParam->{Config} = {};
$GetParam->{Config}->{Condition} = $Config;
$GetParam->{Config}->{ConditionLinking} = $ParamObject->GetParam( Param => 'OverallConditionLinking' ) || '';
$GetParam->{Asynchronous} = $ParamObject->GetParam( Param => 'Asynchronous' ) || '';
return $GetParam;
}
1;
|