[Rt-commit] rt branch, 4.4/initial-custom-field, updated. rt-4.4.0rc2-23-gdd4105f

Shawn Moore shawn at bestpractical.com
Thu Mar 3 18:55:46 EST 2016


The branch, 4.4/initial-custom-field has been updated
       via  dd4105f6a7b8d20f8ef57fc6489ea574c1501bfd (commit)
      from  60c12a84b12151f16e4454a26ca9ccb11ad7cd38 (commit)

Summary of changes:
 share/html/Elements/EditCustomFields | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

- Log -----------------------------------------------------------------
commit dd4105f6a7b8d20f8ef57fc6489ea574c1501bfd
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Mar 3 23:19:07 2016 +0000

    Hide empty "edit custom fields" panels
    
        The titlebox widget hides its chrome when its content contains only
        whitespace characters. This commit suppresses all output from
        EditCustomFields when there are no editable custom fields. This causes
        the titlebox to render nothing, rather than a panel with
        chrome but without content.
    
        Beware that the BeforeCustomFields and AfterCustomFields callbacks
        _may_ generate output even when there are no editable custom fields.
        This commit was carefully written to handle such cases by continuing to
        invoke those callbacks unconditionally.
    
        As best I can tell, we have always had this bug surviving through
        several refactorings. The only conditions under which we successfully
        hid "edit custom field" panels is for users who had no rights to _see_
        any custom fields, since that triggers the following long-standing
        short-circuit return:
    
            # don't print anything if there is no custom fields
            return unless $CustomFields->First;
    
        If you can _see_ any custom fields, they are included in the
        $CustomFields collection, causing us to skip right past that
        short-circuit return. Then, we begin rendering with a <div> or <table>
        container tag. We then iterate over $CustomFields, skipping any custom
        fields you have no modify permissions for. Finally we close the
        container tag. So in the failure case, even though there was no
        _visible_ content, there was still some non-whitespace content (the HTML
        of the container tag) being produced, which was enough to cause the
        titlebox to render its chrome.

diff --git a/share/html/Elements/EditCustomFields b/share/html/Elements/EditCustomFields
index 4e96090..7e21d31 100644
--- a/share/html/Elements/EditCustomFields
+++ b/share/html/Elements/EditCustomFields
@@ -47,12 +47,18 @@
 %# END BPS TAGGED BLOCK }}}
 % $m->callback( CallbackName => 'BeforeCustomFields', Object => $Object,
 %               Grouping => $Grouping, ARGSRef => \%ARGS, CustomFields => $CustomFields);
+
+%# only show the wrapper if there are editable custom fields, so we can
+%# suppress the empty titlebox. we do this in such a way that we still call the
+%# BeforeCustomFields and AfterCustomFields callbacks (rather than returning
+%# from the INIT block) to maintain compatibility with old behavior
+
+% if (@CustomFields) {
+
 % if ( $WRAP ) {
 <<% $WRAP %> class="edit-custom-fields">
 % }
-% while ( my $CustomField = $CustomFields->Next ) {
-% next unless $CustomField->CurrentUserHasRight('ModifyCustomField')
-%          || ($ForCreation && $CustomField->CurrentUserHasRight('SetInitialCustomField'));
+% for my $CustomField (@CustomFields) {
 % my $Type = $CustomField->Type || 'Unknown';
 
   <<% $FIELD %> class="edit-custom-field cftype-<% $Type %>">
@@ -86,6 +92,9 @@
 % if ( $WRAP ) {
 </<% $WRAP %>>
 % }
+
+% }
+
 % $m->callback( CallbackName => 'AfterCustomFields', Object => $Object,
 %               Grouping => $Grouping, ARGSRef => \%ARGS );
 <%INIT>
@@ -95,9 +104,14 @@ $CustomFields->LimitToGrouping( $Object => $Grouping ) if defined $Grouping;
 
 $m->callback( %ARGS, CallbackName => 'MassageCustomFields', CustomFields => $CustomFields );
 
-# don't print anything if there is no custom fields
-return unless $CustomFields->First;
 $CustomFields->GotoFirstItem;
+my @CustomFields;
+while ( my $CustomField = $CustomFields->Next ) {
+    next unless $CustomField->CurrentUserHasRight('ModifyCustomField')
+             || ($ForCreation && $CustomField->CurrentUserHasRight('SetInitialCustomField'));
+
+    push @CustomFields, $CustomField;
+}
 
 $AsTable ||= $InTable;
 my $FIELD = $AsTable ? 'tr' : 'div';

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


More information about the rt-commit mailing list