From bdbdf0cbea4300b397a634370df4b4a1ede87612 Mon Sep 17 00:00:00 2001 From: sunnavy Date: Tue, 12 Mar 2024 10:16:30 -0400 Subject: [PATCH] Load the first catalog current user can create assets in on asset create page Previously if current user can't create assets on the default catalog(either $DefaultCatalog or the first catalog they can see), they would get the "Permission Denied" error directly and couldn't pick catalogs at all. This commit tries a bit harder to find a catalog current user can create assets in, before returning the "Permission Denied" error. --- share/html/Asset/Create.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/share/html/Asset/Create.html b/share/html/Asset/Create.html index 5042609cf59..db69fd3c311 100644 --- a/share/html/Asset/Create.html +++ b/share/html/Asset/Create.html @@ -110,6 +110,19 @@ my $asset = RT::Asset->new( $session{CurrentUser} ); my $catalog = LoadDefaultCatalog( $Catalog || '' ); +if ( !$Catalog && ( !$catalog->id || !$catalog->CurrentUserHasRight('CreateAsset') ) ) { + my $cache_key = SetObjectSessionCache( + ObjectType => 'Catalog', + CheckRight => 'CreateAsset', + CacheNeedsUpdate => RT::Catalog->CacheNeedsUpdate, + ShowAll => 0, + ); + + if ( $session{$cache_key}{objects}[0] ) { + $catalog->Load( $session{$cache_key}{objects}[0]->{Id} ); + } +} + Abort(loc("Unable to find catalog '[_1]'", $Catalog)) unless $catalog->id;