[Rt-commit] rt branch, 4.4/user-create-skip-cfs, created. rt-4.4.4-66-ga80deb3d0

? sunnavy sunnavy at bestpractical.com
Fri Sep 27 11:12:30 EDT 2019


The branch, 4.4/user-create-skip-cfs has been created
        at  a80deb3d0487869ccabaa061bd78d7ce31fb7e72 (commit)

- Log -----------------------------------------------------------------
commit 4035b3670f2bbc372016174eb27e06f6e4df950f
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Sep 23 15:22:27 2019 -0400

    Add test showing user CF deleted after create

diff --git a/t/externalauth/ldap.t b/t/externalauth/ldap.t
index 671d3fcd9..362ab5fb5 100644
--- a/t/externalauth/ldap.t
+++ b/t/externalauth/ldap.t
@@ -171,7 +171,7 @@ diag "test admin user create";
     $user->Load( $id );
     is( $user->EmailAddress, "$username\@invalid.tld", 'email is not changed' );
     is( $user->Name, $username, 'got canonicalized Name' );
-
+    is( $user->FirstCustomFieldValue('Employee Type'), 'sale', 'Employee Type set to sale from LDAP' );
 }
 
 diag "test user update via login";

commit 3295013b07d80d5e5b35cb606b0355c24cab24a4
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Sep 23 15:23:07 2019 -0400

    Clear user CFs from form args if set on create
    
    On create, user objects can now have custom field values set
    from LDAP or other sources. The user create form submission
    also submitted these values and, even if left empty, they
    replaced the values set during create.
    
    Check any submitted user CFs on create and if the user object
    already has a value, remove the form arg to prevent a second
    update and give precedence to the value set on create.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index b6ccf6ff7..3ea5dbc44 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3467,6 +3467,44 @@ sub _NormalizeObjectCustomFieldValue {
     return @values;
 }
 
+=head2 _FilterUserCFValuesOnCreate
+
+On create, user objects can have CFs set from LDAP or other sources.
+Clear submitted user custom field form values on create if the custom field
+already has a value set on create.
+
+=cut
+
+sub _FilterUserCFValuesOnCreate {
+    my %args    = @_;
+    my $ARGSRef = $args{'ARGSRef'};
+    my $UserObj = $args{'UserObj'};
+
+    my %custom_fields_to_mod = _ParseObjectCustomFieldArgs($ARGSRef);
+
+    foreach my $cf ( keys %{ $custom_fields_to_mod{'RT::User'}{0} } ) {
+        my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
+        $CustomFieldObj->SetContextObject($UserObj);
+        $CustomFieldObj->LoadById($cf);
+        unless ( $CustomFieldObj->id ) {
+            $RT::Logger->warning("Couldn't load custom field #$cf");
+            next;
+        }
+
+        if ( $UserObj->FirstCustomFieldValue($CustomFieldObj->Id) ) {
+
+            my ($ret, $grouping) = _ValidateConsistentCustomFieldValues($cf,
+                    $custom_fields_to_mod{'RT::User'}{0}{$cf});
+            my $user_cf_name = GetCustomFieldInputName( CustomField => $CustomFieldObj, Grouping => $grouping );
+
+            delete $ARGSRef->{$user_cf_name} if exists $ARGSRef->{$user_cf_name};
+            delete $ARGSRef->{$user_cf_name . "-Magic"} if exists $ARGSRef->{$user_cf_name . "-Magic"};
+        }
+    }
+
+    return;
+}
+
 =head2 ProcessTicketWatchers ( TicketObj => $Ticket, ARGSRef => \%ARGS );
 
 Returns an array of results messages.
diff --git a/share/html/Admin/Users/Modify.html b/share/html/Admin/Users/Modify.html
index fc80c9aa7..6f1d21b5a 100644
--- a/share/html/Admin/Users/Modify.html
+++ b/share/html/Admin/Users/Modify.html
@@ -282,6 +282,7 @@ if ($Create) {
 
     if ($val) {
         push @results, $msg;
+        _FilterUserCFValuesOnCreate( ARGSRef => \%ARGS, UserObj => $UserObj );
         push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $UserObj );
         $title = loc("Modify the user [_1]", $UserObj->Name);
     } else {

commit 0abfc2018cb799e7c19bd7cd595e95edd15a3580
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Sep 24 05:23:17 2019 +0800

    Only show hints for user CFs configured in external settings on create
    
    These cfs will be automatically set in external sources.

diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index 3f24c0189..04af52569 100644
--- a/share/html/Elements/EditCustomField
+++ b/share/html/Elements/EditCustomField
@@ -122,6 +122,16 @@ $m->out("\n".'<input type="hidden" class="hidden" name="'
         . ($Name ? $m->interp->apply_escapes($Name, 'h') : $m->interp->apply_escapes($NamePrefix, 'h').$CustomField->Id.'-Values')
         . '-Magic" value="1" />'."\n");
 
+# Just show hints for user cfs that will be set from external sources on create
+if ( RT->Config->Get('ExternalInfoPriority') && $Object && $Object->isa('RT::User') && !$Object->Id ) {
+    for my $source ( @{RT->Config->Get('ExternalInfoPriority')} ) {
+        if ( RT->Config->Get('ExternalSettings')->{$source}{attr_map}{'UserCF.'.$CustomField->Name} ) {
+            $Type = 'Display';
+            $Default = loc('Set from external source');
+            last;
+        }
+    }
+}
 
 my $EditComponent = "EditCustomField$Type";
 $m->callback( %ARGS, CallbackName => 'EditComponentName', Name => \$EditComponent, CustomField => $CustomField, Object => $Object, Rows => \$Rows, Cols => \$Cols);
diff --git a/share/html/Elements/EditCustomFieldDisplay b/share/html/Elements/EditCustomFieldDisplay
new file mode 100644
index 000000000..76bc09948
--- /dev/null
+++ b/share/html/Elements/EditCustomFieldDisplay
@@ -0,0 +1,52 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC
+%#                                          <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<i><% $Default %></i>
+
+<%ARGS>
+$Default => undef
+</%ARGS>

commit a80deb3d0487869ccabaa061bd78d7ce31fb7e72
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Sep 24 05:28:56 2019 +0800

    Add more tests for user create forms where some cfs are set in LDAP

diff --git a/t/externalauth/ldap.t b/t/externalauth/ldap.t
index 362ab5fb5..b6d696abc 100644
--- a/t/externalauth/ldap.t
+++ b/t/externalauth/ldap.t
@@ -51,6 +51,17 @@ ok( $employee_id_cf->Create(
 );
 ok( $employee_id_cf->AddToObject( RT::User->new( RT->SystemUser ) ), 'applied Employee ID globally' );
 
+my $delegate_cf = RT::CustomField->new( RT->SystemUser );
+ok( $delegate_cf->Create(
+        Name       => 'Delegate',
+        LookupType => RT::User->CustomFieldLookupType,
+        Type       => 'Freeform',
+        MaxValues  => 1,
+    ),
+    'created cf Delegate'
+);
+ok( $delegate_cf->AddToObject( RT::User->new( RT->SystemUser ) ), 'applied Delegate globally' );
+
 RT->Config->Set( ExternalAuthPriority        => ['My_LDAP'] );
 RT->Config->Set( ExternalInfoPriority        => ['My_LDAP'] );
 RT->Config->Set( AutoCreateNonExternalUsers  => 0 );
@@ -139,6 +150,8 @@ diag "test admin user create";
     $m->logout;
     ok( $m->login );
     $m->get_ok( $baseurl . '/Admin/Users/Modify.html?Create=1', 'user create page' );
+    $m->text_contains( 'Employee Type:Select one value Set from external source' );
+    $m->text_contains( 'Employee ID:Enter one value Set from external source' );
 
     my $username = 'testuser2';
     $m->submit_form(
@@ -161,9 +174,17 @@ diag "test admin user create";
     my $dn = "uid=$username,$base";
     $ldap->add( $dn, attr => [ %$entry ] );
 
+    my $delegate_input = RT::Interface::Web::GetCustomFieldInputName(
+        Object => RT::User->new( RT->SystemUser ),
+        CustomField => $delegate_cf,
+    );
     $m->submit_form(
         form_name => 'UserCreate',
-        fields    => { Name => '', EmailAddress => "$username\@invalid.tld" },
+        fields    => {
+            Name            => '',
+            EmailAddress    => "$username\@invalid.tld",
+            $delegate_input => 'root',
+        },
     );
     $m->text_contains( 'User created' );
     my ( $id ) = ( $m->uri =~ /id=(\d+)/ );
@@ -172,6 +193,7 @@ diag "test admin user create";
     is( $user->EmailAddress, "$username\@invalid.tld", 'email is not changed' );
     is( $user->Name, $username, 'got canonicalized Name' );
     is( $user->FirstCustomFieldValue('Employee Type'), 'sale', 'Employee Type set to sale from LDAP' );
+    is( $user->FirstCustomFieldValue('Delegate'), 'root', 'Delegate set to root from Web' );
 }
 
 diag "test user update via login";

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


More information about the rt-commit mailing list