[Rt-commit] rt branch 4.4/validate-cf-unique-values-on-web-create created. rt-4.4.5-39-g8c6a4ccead

BPS Git Server git at git.bestpractical.com
Fri Apr 1 22:21:18 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 4.4/validate-cf-unique-values-on-web-create has been created
        at  8c6a4ccead7099ce88bf4853f3084ca852e667f4 (commit)

- Log -----------------------------------------------------------------
commit 8c6a4ccead7099ce88bf4853f3084ca852e667f4
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Apr 2 06:00:02 2022 +0800

    Test validation of "unique values" custom fields on web UI

diff --git a/t/web/cf_unique.t b/t/web/cf_unique.t
new file mode 100644
index 0000000000..69c91a3f48
--- /dev/null
+++ b/t/web/cf_unique.t
@@ -0,0 +1,88 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+ok $m->login, 'logged in as root';
+
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
+
+my $cf = RT::Test->load_or_create_custom_field(
+    Name         => 'External ID',
+    Queue        => 'General',
+    Type         => 'FreeformSingle',
+    UniqueValues => 1,
+);
+my $cf_id = $cf->Id;
+
+$m->goto_create_ticket($queue);
+$m->submit_form_ok(
+    {
+        form_name => 'TicketCreate',
+        fields    => { Subject => 'Test unique values', "Object-RT::Ticket--CustomField-$cf_id-Value" => '123' },
+    },
+    'Create ticket with cf value 123',
+);
+
+$m->text_like(qr/Ticket \d+ created in queue/);
+my $ticket = RT::Test->last_ticket;
+is( $ticket->FirstCustomFieldValue($cf), 123, 'CF value is set' );
+
+$m->goto_create_ticket($queue);
+$m->submit_form_ok(
+    {
+        form_name => 'TicketCreate',
+        fields    => { Subject => 'Test unique values', "Object-RT::Ticket--CustomField-$cf_id-Value" => '123' },
+    },
+    'Create ticket with cf value 123',
+);
+$m->text_contains("'123' is not a unique value");
+$m->text_unlike(qr/Ticket \d+ created in queue/);
+
+$m->submit_form_ok(
+    {
+        form_name => 'TicketCreate',
+        fields    => { Subject => 'Test unique values', "Object-RT::Ticket--CustomField-$cf_id-Value" => '456' },
+    },
+    'Create ticket with cf value 456'
+);
+$m->text_like(qr/Ticket \d+ created in queue/);
+$ticket = RT::Test->last_ticket;
+is( $ticket->FirstCustomFieldValue($cf), 456, 'CF value is set' );
+my $ticket_id = $ticket->Id;
+
+$m->follow_link_ok( { text => 'Basics' } );
+$m->submit_form_ok(
+    {
+        form_name => 'TicketModify',
+        fields    => { "Object-RT::Ticket-$ticket_id-CustomField-$cf_id-Value" => '123' },
+    },
+    'Update ticket with cf value 123'
+
+);
+$m->text_contains("'123' is not a unique value");
+$m->text_lacks( 'External ID 456 changed to 123', 'Can not change to an existing value' );
+
+$m->submit_form_ok(
+    {
+
+        form_name => 'TicketModify',
+        fields    => { "Object-RT::Ticket-$ticket_id-CustomField-$cf_id-Value" => '789' },
+    },
+    'Update ticket with cf value 789'
+);
+$m->text_contains( 'External ID 456 changed to 789', 'Changed cf to a new value' );
+
+$m->submit_form_ok(
+    {
+
+        form_name => 'TicketModify',
+        fields    => { "Object-RT::Ticket-$ticket_id-CustomField-$cf_id-Value" => '456' },
+    },
+    'Update ticket with cf value 456'
+);
+$m->text_contains( 'External ID 789 changed to 456', 'Changed cf back to old value' );
+
+done_testing;

commit cd3aa133b6127a22f0bf5560f1e384847b7989a0
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Apr 2 05:26:19 2022 +0800

    Validate "unique values" custom fields correctly on web create
    
    As $Object->id is undef and the generated "!= NULL" SQL doesn't return
    anything, all values could pass the unique check previously.

diff --git a/share/html/Elements/ValidateCustomFields b/share/html/Elements/ValidateCustomFields
index d079100b59..8e04cb11f8 100644
--- a/share/html/Elements/ValidateCustomFields
+++ b/share/html/Elements/ValidateCustomFields
@@ -129,7 +129,7 @@ while ( my $CF = $CustomFields->Next ) {
             $existing->LimitToCustomField($CF->Id);
             $existing->LimitToEnabled;
             $existing->Limit(FIELD => 'ObjectType', VALUE => ref($Object));
-            $existing->Limit(FIELD => 'ObjectId', VALUE => $Object->id, OPERATOR => '!=');
+            $existing->Limit(FIELD => 'ObjectId', VALUE => $Object->id || 0, OPERATOR => '!=');
             $existing->Limit(
                 FIELD => 'Content',
                 VALUE => $value,

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list