[Rt-commit] rt branch, 4.4/select-object-always-include-valid-default, created. rt-4.4.2-73-g844cc08c2

? sunnavy sunnavy at bestpractical.com
Thu Feb 8 13:40:36 EST 2018


The branch, 4.4/select-object-always-include-valid-default has been created
        at  844cc08c2b445e74e39024eeda53b3e13cc0da06 (commit)

- Log -----------------------------------------------------------------
commit 3b87bfb7dc7a77770346c0848849ec0dbb35c2a5
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Feb 9 02:12:50 2018 +0800

    add default value to cache key since it affects the cached object list

diff --git a/share/html/Elements/SelectObject b/share/html/Elements/SelectObject
index 7a4ecdfc9..9d8642fd5 100644
--- a/share/html/Elements/SelectObject
+++ b/share/html/Elements/SelectObject
@@ -90,7 +90,7 @@ $ObjectType = "RT::$ObjectType" unless $ObjectType =~ /::/;
 $Class    ||= "select-" . CSSClass("\L$1") if $ObjectType =~ /RT::(.+)$/;
 
 my $cache_key = join "---", "SelectObject", $ObjectType,
-    $session{'CurrentUser'}->Id, $CheckRight || "", $ShowAll;
+    $session{'CurrentUser'}->Id, $CheckRight || "", $ShowAll, $Default || "";
 
 if ( defined $session{$cache_key} && ref $session{$cache_key} eq 'ARRAY') {
     delete $session{$cache_key};

commit 844cc08c2b445e74e39024eeda53b3e13cc0da06
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Feb 9 02:13:51 2018 +0800

    always add valid default value to cached object list
    
    Previous logic tried to do the same thing, but it didn't consider the
    fact that "$collection->Next" also does right check, of which the name
    could be different from $CheckRight.
    
    E.g. when looping through an RT::Queue collection, RT excludes queues
    that current user doesn't have "SeeQueue" right granted on(defined in
    RT::Queues::AddRecord). But in /Elements/SelectQueue, we usually check
    "CreateTicket" right instead.
    
    This commit fixes this so even current user doesn't have SeeQueue on a
    queue, as long as the queue is the default value, we add it to the
    selection box.
    
    Thus, we can always have a select box with expected default value.

diff --git a/share/html/Elements/SelectObject b/share/html/Elements/SelectObject
index 9d8642fd5..91d6b732d 100644
--- a/share/html/Elements/SelectObject
+++ b/share/html/Elements/SelectObject
@@ -107,20 +107,17 @@ if ( not defined $session{$cache_key} and not $Lite ) {
     $m->callback( CallbackName => 'ModifyCollection', ARGSRef => \%ARGS,
                   Collection => $collection, ObjectType => $ObjectType );
 
+    my ( $default_id, $default_entry, %added );
     if ( $Default ) {
         my $object = $ObjectType->new($session{'CurrentUser'});
         $object->Load( $Default );
-        unless ( $ShowAll
-                 or not $CheckRight
-                 or $session{CurrentUser}->HasRight( Object => $object, Right => $CheckRight ) )
-        {
-            if ( $object->id ) {
-                push @{$session{$cache_key}{objects}}, {
-                    Id          => $object->id,
-                    Name        => '#' . $object->id,
-                    Description => '#' . $object->id,
-                };
-            }
+        if ( $object->id ) {
+            $default_id = $object->id;
+            $default_entry = {
+                Id          => $object->id,
+                Name        => '#' . $object->id,
+                Description => '#' . $object->id,
+            };
         }
     }
 
@@ -134,8 +131,11 @@ if ( not defined $session{$cache_key} and not $Lite ) {
                 Name        => $object->Name,
                 Description => $object->_Accessible("Description" => "read") ? $object->Description : undef,
             };
+            $added{$object->id} = 1;
         }
     }
+
+    unshift @{ $session{$cache_key}{objects} }, $default_entry if $default_id && !$added{$default_id};
     $session{$cache_key}{lastupdated} = time();
 }
 </%init>

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


More information about the rt-commit mailing list