[Rt-commit] rt branch, 4.4/disabled-cf-sortorder, created. rt-4.4.2-45-g02b417e
Jim Brandt
jbrandt at bestpractical.com
Thu Nov 9 11:57:48 EST 2017
The branch, 4.4/disabled-cf-sortorder has been created
at 02b417e7640e1dcbe9762e27af56d16810f7261d (commit)
- Log -----------------------------------------------------------------
commit 0a931be1503224c19e917c6c8629945e07b8f4a1
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Nov 9 10:03:47 2017 -0500
Test showing incorrect sort order on re-enabled CF
diff --git a/t/api/customfield.t b/t/api/customfield.t
index dedeaa2..9166994 100644
--- a/t/api/customfield.t
+++ b/t/api/customfield.t
@@ -382,5 +382,61 @@ $cf = RT::CustomField->new( RT->SystemUser );
$cf->LoadByName(Name => 'TestingCF', Queue => 1, IncludeDisabled => 0 );
ok( ! $cf->id, "Doesn't find it if IncludeDisabled => 0" );
+$cf = RT::CustomField->new( RT->SystemUser );
+$cf->LoadByName(Name => 'TestingCF', Queue => 1, IncludeDisabled => 1 );
+($ok, $msg) = $cf->SetDisabled(0);
+ok($ok, "Re-enabled CF " . $cf->Name);
+
+diag 'Test sort ordering when disabling and re-enabling CFs';
+
+# Create more CFs
+foreach my $i (2..5) {
+ ($ok, $msg) = $cf->Create(
+ Name => "TestingCF$i",
+ Queue => '0',
+ Description => 'Global CF',
+ Type => 'SelectSingle'
+ );
+ ok($ok, "Created " . $cf->Name . " successfully");
+
+ $ocf = RT::ObjectCustomField->new( RT->SystemUser );
+ ( $ok, $msg ) = $ocf->LoadByCols( CustomField => $cf->id, ObjectId => 0 );
+ ok( $ok, "Found OCF " . $ocf->Id);
+ is( $ocf->SortOrder, $i, "Sort order is $i for OCF " . $ocf->Id);
+}
+
+diag 'Disable TestingCF4';
+$cf = RT::CustomField->new( RT->SystemUser );
+$cf->LoadByName(Name => 'TestingCF4', Queue => 0 );
+($ok, $msg) = $cf->SetDisabled(1);
+ok($ok, "Disabled " . $cf->Name);
+
+diag 'MoveUp TestingCF5';
+$cf = RT::CustomField->new( RT->SystemUser );
+$cf->LoadByName(Name => 'TestingCF5', Queue => 0 );
+$ocf = RT::ObjectCustomField->new( RT->SystemUser );
+( $ok, $msg ) = $ocf->LoadByCols( CustomField => $cf->id, ObjectId => 0 );
+ok( $ok, "Found OCF " . $ocf->Id . " for " . $cf->Name );
+is( $ocf->SortOrder, 5, 'Sort order before MoveUp');
+$ocf->MoveUp;
+is( $ocf->SortOrder, 3, 'Sort order after MoveUp');
+
+$cf = RT::CustomField->new( RT->SystemUser );
+$cf->LoadByName(Name => 'TestingCF3', Queue => 0 );
+$ocf = RT::ObjectCustomField->new( RT->SystemUser );
+( $ok, $msg ) = $ocf->LoadByCols( CustomField => $cf->id, ObjectId => 0 );
+ok( $ok, "Found OCF " . $ocf->Id . " for " . $cf->Name );
+is( $ocf->SortOrder, 4, 'Sort order is 4 for OCF ' . $ocf->Id);
+
+
+# Sort order should become 5 when re-enabled and not stay at 4
+$cf = RT::CustomField->new( RT->SystemUser );
+$cf->LoadByName(Name => 'TestingCF4', Queue => 0 );
+($ok, $msg) = $cf->SetDisabled(0);
+ok($ok, "Re-enabled " . $cf->Name);
+$ocf = RT::ObjectCustomField->new( RT->SystemUser );
+( $ok, $msg ) = $ocf->LoadByCols( CustomField => $cf->id, ObjectId => 0 );
+ok( $ok, "Found OCF for " . $cf->Name );
+is( $ocf->SortOrder, 5, 'Sort order is 5, CF moved to bottom of list on re-enable');
done_testing;
commit 22d89dab4e303046907f401c7623cc24df6b8e48
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Nov 9 11:44:25 2017 -0500
Reset ObjectCustomField sort order when re-enabling a Custom Field
When disabling and re-enabling custom fields, the sort order stored
in the ObjectCustomFields table is retained. If the sort order in a list
of CFs is modified with MoveUp and MoveDown and a disabled CF is
then re-enabled, the previous sort order can be the same as one of
the moved OCFs.
On re-enabling a custom field, move it to the bottom of the sort
order for all ObjectCustomField records to avoid duplicate sort
order values.
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 97010cb..f217492 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1181,6 +1181,19 @@ sub SetDisabled {
return ($status, $msg);
}
+ # Set to the end of the sort list when re-enabling to prevent duplicate
+ # sort order values.
+ if ( $val == 0 ) {
+ my $ocfs = RT::ObjectCustomFields->new( $self->CurrentUser );
+ $ocfs->LimitToCustomField( $self->id );
+
+ while ( my $ocf = $ocfs->Next ) {
+ my $sort = $ocf->NextSortOrder();
+ $ocf->SetSortOrder($sort);
+ RT::Logger->debug("Set Sort Order to $sort for Object Custom Field " . $ocf->Id);
+ }
+ }
+
if ( $val == 1 ) {
return (1, $self->loc("Disabled"));
} else {
commit 02b417e7640e1dcbe9762e27af56d16810f7261d
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu Nov 9 11:50:08 2017 -0500
Update test IDs to align with SetDisabled update
22d89dab4 fixes a duplicate sort order issue by resetting
sort order when a custom field is re-enabled. Earlier in the
customfield test, custom fields are disabled and re-enabled
which increments the initial sort order by 2 for the subsequent
sort order tests. Update the tests to account for this new offset.
diff --git a/t/api/customfield.t b/t/api/customfield.t
index 9166994..861790e 100644
--- a/t/api/customfield.t
+++ b/t/api/customfield.t
@@ -402,7 +402,7 @@ foreach my $i (2..5) {
$ocf = RT::ObjectCustomField->new( RT->SystemUser );
( $ok, $msg ) = $ocf->LoadByCols( CustomField => $cf->id, ObjectId => 0 );
ok( $ok, "Found OCF " . $ocf->Id);
- is( $ocf->SortOrder, $i, "Sort order is $i for OCF " . $ocf->Id);
+ is( $ocf->SortOrder, ($i + 2), "Sort order is " . ($i + 2) . " for OCF " . $ocf->Id);
}
diag 'Disable TestingCF4';
@@ -417,19 +417,18 @@ $cf->LoadByName(Name => 'TestingCF5', Queue => 0 );
$ocf = RT::ObjectCustomField->new( RT->SystemUser );
( $ok, $msg ) = $ocf->LoadByCols( CustomField => $cf->id, ObjectId => 0 );
ok( $ok, "Found OCF " . $ocf->Id . " for " . $cf->Name );
-is( $ocf->SortOrder, 5, 'Sort order before MoveUp');
+is( $ocf->SortOrder, 7, 'Sort order before MoveUp');
$ocf->MoveUp;
-is( $ocf->SortOrder, 3, 'Sort order after MoveUp');
+is( $ocf->SortOrder, 5, 'Sort order after MoveUp');
$cf = RT::CustomField->new( RT->SystemUser );
$cf->LoadByName(Name => 'TestingCF3', Queue => 0 );
$ocf = RT::ObjectCustomField->new( RT->SystemUser );
( $ok, $msg ) = $ocf->LoadByCols( CustomField => $cf->id, ObjectId => 0 );
ok( $ok, "Found OCF " . $ocf->Id . " for " . $cf->Name );
-is( $ocf->SortOrder, 4, 'Sort order is 4 for OCF ' . $ocf->Id);
+is( $ocf->SortOrder, 6, 'Sort order is 6 for OCF ' . $ocf->Id);
-
-# Sort order should become 5 when re-enabled and not stay at 4
+# Sort order should become 7 when re-enabled and not stay at 6
$cf = RT::CustomField->new( RT->SystemUser );
$cf->LoadByName(Name => 'TestingCF4', Queue => 0 );
($ok, $msg) = $cf->SetDisabled(0);
@@ -437,6 +436,6 @@ ok($ok, "Re-enabled " . $cf->Name);
$ocf = RT::ObjectCustomField->new( RT->SystemUser );
( $ok, $msg ) = $ocf->LoadByCols( CustomField => $cf->id, ObjectId => 0 );
ok( $ok, "Found OCF for " . $cf->Name );
-is( $ocf->SortOrder, 5, 'Sort order is 5, CF moved to bottom of list on re-enable');
+is( $ocf->SortOrder, 7, 'Sort order is 7, CF moved to bottom of list on re-enable');
done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list