[Rt-commit] rt branch, 4.4/select-object-always-include-valid-default, created. rt-4.4.2-74-gdf9796b13
? sunnavy
sunnavy at bestpractical.com
Thu Feb 8 20:07:57 EST 2018
The branch, 4.4/select-object-always-include-valid-default has been created
at df9796b13db57ec20f4eb0129a68a5f16425b137 (commit)
- Log -----------------------------------------------------------------
commit df9796b13db57ec20f4eb0129a68a5f16425b137
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Feb 9 08:08:05 2018 +0800
always add valid default value to select box
Previous logic tried to do the same thing, but it had 2 issue:
* Default value was respected *only* when building the cache
If a new default value comes in later, it won't be handled like the
first one at all, since the built cache will be used directly.
* 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 the issues by refactoring and moving the Default value
handler from building-cache block. It also avoids duplicated values and
deletes old buggy caches.
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 7a4ecdfc9..70fa518c2 100644
--- a/share/html/Elements/SelectObject
+++ b/share/html/Elements/SelectObject
@@ -55,7 +55,7 @@
% if ($ShowNullOption) {
<option value=""><% $DefaultLabel %></option>
% }
-% for my $object (@{$session{$cache_key}{objects}}) {
+% for my $object ($default_entry || (), @{$session{$cache_key}{objects}}) {
<option value="<% ($NamedValues ? $object->{Name} : $object->{Id}) %>"\
% if ($object->{Id} eq ($Default||'') || $object->{Name} eq ($Default||'')) {
selected="selected"\
@@ -99,6 +99,9 @@ if ( defined $session{$cache_key} && defined $CacheNeedsUpdate &&
$session{$cache_key}{lastupdated} <= $CacheNeedsUpdate ) {
delete $session{$cache_key};
}
+if ( defined $session{$cache_key} && !$session{$cache_key}{id} ) {
+ delete $session{$cache_key};
+}
if ( not defined $session{$cache_key} and not $Lite ) {
my $collection = "${ObjectType}s"->new($session{'CurrentUser'});
@@ -107,23 +110,7 @@ if ( not defined $session{$cache_key} and not $Lite ) {
$m->callback( CallbackName => 'ModifyCollection', ARGSRef => \%ARGS,
Collection => $collection, ObjectType => $ObjectType );
- 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,
- };
- }
- }
- }
-
+ $session{$cache_key}{id} = {};
while (my $object = $collection->Next) {
if ($ShowAll
or not $CheckRight
@@ -134,8 +121,23 @@ if ( not defined $session{$cache_key} and not $Lite ) {
Name => $object->Name,
Description => $object->_Accessible("Description" => "read") ? $object->Description : undef,
};
+ $session{$cache_key}{id}{ $object->id } = 1;
}
}
$session{$cache_key}{lastupdated} = time();
}
+
+my $default_entry;
+if ( $Default && !$Lite ) {
+ my $object = $ObjectType->new( $session{'CurrentUser'} );
+ $object->Load( $Default );
+ if ( $object->id && !$session{$cache_key}{id}{ $object->id } ) {
+ $default_entry = $session{$cache_key}{default}{ $object->id } ||= {
+ Id => $object->id,
+ Name => '#' . $object->id,
+ Description => '#' . $object->id,
+ };
+ }
+}
+
</%init>
-----------------------------------------------------------------------
More information about the rt-commit
mailing list