Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
best-practical
rt-extension-commandbymail
Commits
49add88a
Commit
49add88a
authored
Feb 07, 2013
by
Ruslan Zakirov
Browse files
support transaction custom fields
parent
9ca419e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
13 deletions
+121
-13
lib/RT/Interface/Email/Filter/TakeAction.pm
lib/RT/Interface/Email/Filter/TakeAction.pm
+50
-13
t/txn-cfs.t
t/txn-cfs.t
+71
-0
No files found.
lib/RT/Interface/Email/Filter/TakeAction.pm
View file @
49add88a
...
...
@@ -128,6 +128,19 @@ Short forms:
AddCF.{<CFName>}: <custom field value>
DelCF.{<CFName>}: <custom field value>
=head3 Transaction Custom field values
Manage custom field values of transactions. Could be used multiple times. (The curly braces
are literal.)
TransactionCustomField.{<CFName>}: <custom field value>
Short forms:
TxnCustomField.{<CFName>}: <custom field value>
TransactionCF.{<CFName>}: <custom field value>
TxnCF.{<CFName>}: <custom field value>
=cut
=head2 GetCurrentUser
...
...
@@ -245,6 +258,8 @@ sub GetCurrentUser {
$queue
->
Load
(
$args
{'
Queue
'}
->
id
);
}
my
$transaction
;
# If we're updating.
if
(
$args
{'
Ticket
'}
->
id
)
{
$ticket_as_user
->
Load
(
$args
{'
Ticket
'}
->
id
);
...
...
@@ -343,7 +358,7 @@ sub GetCurrentUser {
}
my
$method
=
ucfirst
$args
{'
Action
'};
my
(
$status
,
$msg
)
=
$ticket_as_user
->
$method
(
(
my
$status
,
my
$msg
,
$transaction
)
=
$ticket_as_user
->
$method
(
TimeTaken
=>
$time_taken
,
MIMEObj
=>
$args
{'
Message
'},
);
...
...
@@ -447,13 +462,6 @@ sub GetCurrentUser {
);
}
_ReportResults
(
Ticket
=>
$args
{'
Ticket
'},
Results
=>
\
%results
,
Message
=>
$args
{'
Message
'}
);
return
(
$args
{'
CurrentUser
'},
-
2
);
}
else
{
my
%create_args
=
();
...
...
@@ -550,13 +558,40 @@ sub GetCurrentUser {
return
(
$args
{'
CurrentUser
'},
$args
{'
AuthLevel
'});
}
$transaction
=
RT::
Transaction
->
new
(
$ticket_as_user
->
CurrentUser
);
$transaction
->
Load
(
$txn_id
);
_ReportResults
(
Results
=>
\
%results
,
Message
=>
$args
{'
Message
'}
);
}
# now that we've created a ticket, we abort so we don't create another.
$args
{'
Ticket
'}
->
Load
(
$id
);
return
(
$args
{'
CurrentUser
'},
-
2
);
if
(
$transaction
&&
$transaction
->
id
)
{
my
$custom_fields
=
$transaction
->
CustomFields
;
while
(
my
$cf
=
$custom_fields
->
Next
)
{
my
$cmd
=
'
TransactionCustomField{
'
.
$cf
->
Name
.
'
}
';
my
@values
=
(
$cmds
{
lc
$cmd
});
next
unless
@values
&&
$values
[
0
];
@values
=
@
{
$values
[
0
]
}
if
ref
$values
[
0
]
eq
'
ARRAY
';
foreach
my
$value
(
@values
)
{
my
(
$status
,
$msg
)
=
$transaction
->
AddCustomFieldValue
(
Field
=>
$cf
->
Name
,
Value
=>
$value
,
);
push
@
{
$results
{
$cmd
}
||=
[]
},
{
value
=>
$value
,
result
=>
$status
,
message
=>
$msg
,
};
}
}
}
_ReportResults
(
Ticket
=>
$args
{'
Ticket
'},
Results
=>
\
%results
,
Message
=>
$args
{'
Message
'},
);
# make sure ticket is loaded
$args
{'
Ticket
'}
->
Load
(
$transaction
->
ObjectId
);
return
(
$args
{'
CurrentUser
'},
-
2
);
}
sub
_ParseAdditiveCommand
{
...
...
@@ -658,12 +693,14 @@ sub _CanonicalizeCommand {
$key
=
lc
$key
;
# CustomField commands
$key
=~
s/^(add|del|)c(?:ustom)?-?f(?:ield)?\.?[({\[](.*)[)}\]]$/$1customfield{$2}/i
;
$key
=~
s/^(?:transaction|txn)c(?:ustom)?-?f(?:ield)?\.?[({\[](.*)[)}\]]$/transactioncustomfield{$1}/i
;
return
$key
;
}
sub
_CheckCommand
{
my
(
$cmd
,
$val
)
=
(
lc
shift
,
shift
);
return
1
if
$cmd
=~
/^(add|del|)customfield{.*}$/i
;
return
1
if
$cmd
=~
/^transactioncustomfield{.*}$/i
;
if
(
grep
$cmd
eq
lc
$_
,
@REGULAR_ATTRIBUTES
,
@TIME_ATTRIBUTES
,
@DATE_ATTRIBUTES
)
{
return
1
unless
ref
$val
;
return
(
0
,
"
Command '
$cmd
' doesn't support multiple values
");
...
...
@@ -684,7 +721,7 @@ sub _ReportResults {
my
%args
=
(
Ticket
=>
undef
,
Message
=>
undef
,
Results
=>
{},
@
_
);
my
$msg
=
'';
unless
(
$args
{'
Ticket
'}
)
{
unless
(
$args
{'
Ticket
'}
&&
$args
{'
Ticket
'}
->
id
)
{
$msg
.=
$args
{'
Results
'}{'
Create
'}{'
message
'}
||
'';
$msg
.=
"
\n
"
if
$msg
;
delete
$args
{'
Results
'}{'
Create
'};
...
...
t/txn-cfs.t
0 → 100644
View file @
49add88a
use
strict
;
use
warnings
;
use
RT::Extension::CommandByMail::
Test
tests
=>
undef
;
my
$test
=
'
RT::Extension::CommandByMail::Test
';
RT
->
Config
->
Set
('
MailPlugins
',
'
Auth::MailFrom
',
'
Filter::TakeAction
');
my
$cf_name
=
'
Test CF
';
{
my
$cf
=
RT::
CustomField
->
new
(
RT
->
SystemUser
);
my
(
$status
,
$msg
)
=
$cf
->
Create
(
Name
=>
$cf_name
,
Type
=>
'
Freeform
',
MaxValues
=>
0
,
LookupType
=>
RT::
Transaction
->
CustomFieldLookupType
,
);
ok
$status
,
"
created a CF
"
or
diag
"
error:
$msg
";
(
$status
,
$msg
)
=
$cf
->
AddToObject
(
RT::
Queue
->
new
(
RT
->
SystemUser
)
);
ok
$status
,
"
applied CF
"
or
diag
"
error:
$msg
";
}
my
$test_ticket_id
;
diag
("
txn CFs on create
")
if
$ENV
{'
TEST_VERBOSE
'};
{
my
$text
=
<<END;
Subject: test
From: root\@localhost
TxnCF{$cf_name}: foo
TxnCF{$cf_name}: bar
END
my
(
undef
,
$id
)
=
$test
->
send_via_mailgate
(
$text
);
ok
(
$id
,
"
created ticket
");
my
$obj
=
RT::
Ticket
->
new
(
$
RT::
SystemUser
);
$obj
->
Load
(
$id
);
is
(
$obj
->
id
,
$id
,
"
loaded ticket
");
my
@values
=
sort
map
$_
->
Content
,
@
{
$obj
->
Transactions
->
First
->
CustomFieldValues
(
$cf_name
)
->
ItemsArrayRef
};
is_deeply
\
@values
,
[
qw(bar foo)
];
$test_ticket_id
=
$obj
->
id
;
}
diag
("
txn CFs on update
")
if
$ENV
{'
TEST_VERBOSE
'};
{
my
$text
=
<<END;
Subject: [$RT::rtname #$test_ticket_id] test
From: root\@localhost
TxnCF{$cf_name}: foo
TxnCF{$cf_name}: bar
END
my
(
undef
,
$id
)
=
$test
->
send_via_mailgate
(
$text
);
ok
(
$id
,
"
created ticket
");
my
$obj
=
RT::
Ticket
->
new
(
$
RT::
SystemUser
);
$obj
->
Load
(
$id
);
is
(
$obj
->
id
,
$id
,
"
loaded ticket
");
my
$txns
=
$obj
->
Transactions
;
$txns
->
Limit
(
FIELD
=>
'
Type
',
VALUE
=>
'
Correspond
'
);
my
@values
=
sort
map
$_
->
Content
,
@
{
$txns
->
First
->
CustomFieldValues
(
$cf_name
)
->
ItemsArrayRef
};
is_deeply
\
@values
,
[
qw(bar foo)
];
$test_ticket_id
=
$obj
->
id
;
}
done_testing
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment