[Rt-commit] rt branch, 5.0/remove-catalog-modal, created. rt-4.4.4-770-g7546e0518

Michel Rodriguez michel at bestpractical.com
Thu Feb 27 09:57:02 EST 2020


The branch, 5.0/remove-catalog-modal has been created
        at  7546e0518870245f7205d431cc6b2bcb276a89d3 (commit)

- Log -----------------------------------------------------------------
commit 996302c7d26571051349646cd28d9e815272f96f
Author: michel <michel at bestpractical.com>
Date:   Thu Feb 20 15:30:55 2020 +0100

    Select Catalog in Asset Create page.
    
    Allow Catalog to be selected in the create asset page, using defaults
    from configuration if none provided. Existing urls for asset creation
    will still work.

diff --git a/share/html/Admin/Assets/Catalogs/Modify.html b/share/html/Admin/Assets/Catalogs/Modify.html
index e27bc2fd3..2b82f50d3 100644
--- a/share/html/Admin/Assets/Catalogs/Modify.html
+++ b/share/html/Admin/Assets/Catalogs/Modify.html
@@ -51,6 +51,7 @@
 
 <form method="post" enctype="multipart/form-data" id="ModifyCatalog" action="Modify.html">
   <input type="hidden" name="id" value="<% $catalog->id %>">
+  <input type="hidden" name="CatalogChanged" value="0">
 
   <&| /Widgets/TitleBox, title => loc("Basics"), class => "catalog-basics" &>
     <& Elements/EditBasics, %ARGS, CatalogObj => $catalog &>
diff --git a/share/html/Asset/Create.html b/share/html/Asset/Create.html
index 12a3bd1f2..706f6bba7 100644
--- a/share/html/Asset/Create.html
+++ b/share/html/Asset/Create.html
@@ -51,16 +51,16 @@
 <& /Elements/ListActions, actions => \@results &>
 
 <span class="catalog <% CSSClass($catalog->Name) %>">
-  <form method="post" enctype="multipart/form-data" id="CreateAsset" action="Create.html">
+  <form method="post" enctype="multipart/form-data" id="CreateAsset" name="CreateAsset" action="Create.html">
     <input type="hidden" name="id" value="new">
-    <input type="hidden" name="Catalog" value="<% $catalog->id %>">
+    <input type="hidden" name="CatalogChanged" value="0" />
 
     <div id="Asset-Create-basics" class="asset-metadata form-row">
       <a name="basics"></a>
       <div class="col-md-6">
         <&| /Widgets/TitleBox, title => loc("Basics"), class => "asset-basics", title_class => "inverse" &>
-          <& Elements/EditBasics, %ARGS, AssetObj => $asset, CatalogObj => $catalog &>
-        </&>
+          <& Elements/EditBasics, %ARGS, AssetObj => $asset, CatalogObj => $catalog, AutoSubmit => 1 &>
+       </&>
       </div>
 
       <div class="col-md-6">
@@ -108,7 +108,12 @@ $Catalog => undef
 <%init>
 my $asset   = RT::Asset->new( $session{CurrentUser} );
 my $catalog = RT::Catalog->new( $session{CurrentUser} );
-$catalog->Load($Catalog);
+if ( $Catalog ) {
+    $catalog->Load($Catalog);
+}
+else {
+    $catalog = LoadDefaultCatalog( $ARGS{Catalog} || '' );
+}
 
 Abort(loc("Unable to find catalog '[_1]'", $Catalog))
     unless $catalog->id;
@@ -132,6 +137,10 @@ if ($id eq "new") {
         ARGSRef         => \%ARGS
     );
 
+    if ( $ARGS{CatalogChanged} ) {
+        $skip_create = 1;
+    }
+
     $m->callback(
         CallbackName    => 'BeforeCreate',
         AssetObj        => $asset,
diff --git a/share/html/Asset/Elements/EditBasics b/share/html/Asset/Elements/EditBasics
index 798d98261..e4ba222b5 100644
--- a/share/html/Asset/Elements/EditBasics
+++ b/share/html/Asset/Elements/EditBasics
@@ -45,16 +45,14 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-% if ($AssetObj->id) {
   <div class="form-row asset-catalog">
     <div class="label col-md-3">
       <&|/l&>Catalog</&>:
     </div>
     <div class="value col-md-9">
-      <& /Asset/Elements/SelectCatalog, Default => $current{Catalog} &>
+      <& /Asset/Elements/SelectCatalog, Default => $current{Catalog}, AutoSubmit => $AutoSubmit &>
     </div>
   </div>
-% }
   <div class="form-row asset-name">
     <div class="label col-md-3">
       <&|/l&>Name</&>:
@@ -95,8 +93,10 @@
 <%args>
 $AssetObj
 $CatalogObj => undef
+$AutoSubmit => 0
 </%args>
 <%init>
 my %current = map { $_ => ($ARGS{$_} || $AssetObj->$_ || '') }
                   $AssetObj->WritableAttributes;
+$CatalogObj ||= LoadDefaultCatalog($ARGS{'Catalog'} || ($AssetObj && $AssetObj->Catalog) || '' );
 </%init>
diff --git a/share/html/Asset/Elements/SelectCatalog b/share/html/Asset/Elements/SelectCatalog
index 76a73de21..871eec6c1 100644
--- a/share/html/Asset/Elements/SelectCatalog
+++ b/share/html/Asset/Elements/SelectCatalog
@@ -60,6 +60,7 @@ $ShowAll => 0
 $Default => undef
 $UpdateSession => 1
 $ShowNullOption => 0
+$AutoSubmit     => 0
 </%args>
 <%init>
 my $catalog_obj = LoadDefaultCatalog($Default || '');
@@ -67,4 +68,6 @@ if ( $UpdateSession && $catalog_obj->Id ){
     $session{'DefaultCatalog'} = $catalog_obj->Id;
     $Default = $catalog_obj->Id;
 }
+$ARGS{OnChange} = "jQuery(this).closest('form').find('input[name=CatalogChanged]').val(1);";
+$ARGS{OnChange} .= "jQuery(this).closest('form').submit();" if $AutoSubmit;
 </%init>

commit e07ee4d4a94546246088f51d98d8c66e196d2bfb
Author: michel <michel at bestpractical.com>
Date:   Wed Feb 26 15:37:12 2020 +0100

    Test catalog select on asset create page

diff --git a/lib/RT/Test/Assets.pm b/lib/RT/Test/Assets.pm
index 57dcbb524..193d15f64 100644
--- a/lib/RT/Test/Assets.pm
+++ b/lib/RT/Test/Assets.pm
@@ -80,6 +80,24 @@ sub create_catalog {
     }
 }
 
+sub load_or_create_catalog {
+    my $self = shift;
+    my %args = ( Disabled => 0, @_ );
+    my $obj = RT::Catalog->new( RT->SystemUser );
+    if ( $args{'Name'} ) {
+        $obj->LoadByCols( Name => $args{'Name'} );
+    } else {
+        die "Name is required";
+    }
+    unless ( $obj->id ) {
+        my ($val, $msg) = $obj->Create( %args );
+        die "$msg" unless $val;
+    }
+
+    return $obj;
+}
+
+
 sub create_asset {
     my %info  = @_;
     my $asset = RT::Asset->new( RT->SystemUser );
@@ -128,4 +146,15 @@ sub apply_cfs {
     return $success;
 }
 
+sub last_asset {
+    my $self = shift;
+    my $current = shift;
+    $current = $current ? RT::CurrentUser->new($current) : RT->SystemUser;
+    my $assets = RT::Assets->new( $current );
+    $assets->OrderBy( FIELD => 'id', ORDER => 'DESC' );
+    $assets->Limit( FIELD => 'id', OPERATOR => '>', VALUE => '0' );
+    $assets->RowsPerPage( 1 );
+    return $assets->First;
+}
+
 1;
diff --git a/t/web/asset_create.t b/t/web/asset_create.t
new file mode 100644
index 000000000..2ef015bd3
--- /dev/null
+++ b/t/web/asset_create.t
@@ -0,0 +1,85 @@
+use strict;
+use warnings;
+
+use RT::Test::Assets tests => undef;
+use RT::Lifecycle;
+
+# populate lifecycles
+my $lifecycles = RT->Config->Get('Lifecycles');
+RT->Config->Set(
+    Lifecycles => %{$lifecycles},
+    foo        => {
+        type => 'asset',
+        initial  => ['new'],
+        active   => ['tracked'],
+        inactive => ['retired'],
+        defaults => { on_create => 'new', },
+    },
+);
+RT::Lifecycle->FillCache();
+
+RT->Config->Set( DefaultCatalog => 'Default catalog' );
+
+# populate test catalogs and test user
+my $catalog_1 = RT::Test::Assets->load_or_create_catalog( Name => 'Default catalog' );
+ok( $catalog_1, 'created catalog 1' );
+my $catalog_2 = RT::Test::Assets::->load_or_create_catalog( Name => 'Another catalog' );
+ok( $catalog_2, 'created catalog 2 id:' . $catalog_2->id );
+my $user   = RT::Test::Assets->load_or_create_user(
+    Name     => 'user',
+    Password => 'password',
+);
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+ok $m->login;
+
+#set up lifecycle for catalog 2
+$catalog_2->SetLifecycle( 'foo');
+is( $catalog_2->Lifecycle, 'foo', 'catalog lifecycle changed to foo' );
+
+# set up custom field on catalog 2
+my $cf = RT::Test::Assets::create_cf( Name => 'test_cf', Catalog => $catalog_2->Name, Type => 'FreeformSingle' );
+$cf->AddToObject( $catalog_2 );
+ok( $cf, "custom field created (id:" . $cf->Id . ")" );
+my $cf_form_id    = 'Object-RT::Asset--CustomField-' . $cf->Id . '-Value';
+my $cf_test_value = "some string for test_cf $$";
+
+# load initial asset create page without specifying catalog
+# should have default catalog with no custom fields
+note('load create asset page with defaults');
+$m->get_ok('/Asset/Create.html?');
+
+ok( !$m->form_name('CreateAsset')->find_input($cf_form_id), 'custom field not present' );
+is( $m->form_name('CreateAsset')->value('Catalog'), $catalog_1->id, 'Catalog selection dropdown populated and pre-selected' );
+is( $m->form_name('CreateAsset')->value('Status'), 'new', 'Status selection dropdown populated and pre-selected' );
+
+$m->get_ok( '/Asset/Create.html', 'go to asset create page with no catalog id' );
+ok( !$m->form_name('CreateAsset')->find_input($cf_form_id), 'custom field not present' );
+is( $m->form_name('CreateAsset')->value('Catalog'), $catalog_1->id, 'Catalog selection dropdown populated and pre-selected' );
+is( $m->form_name('CreateAsset')->value('Status'), 'new', 'Status selection dropdown populated and pre-selected' );
+
+# test asset creation on reload from selected catalog, specifying catalog with custom fields
+note('reload asset create page with selected catalog');
+$m->get_ok( '/Asset/Create.html?Catalog=' . $catalog_2->id, 'go to asset create page' );
+
+is( $m->form_name('CreateAsset')->value('Catalog'), $catalog_2->id, 'Catalog selection dropdown populated and pre-selected' );
+ok( $m->form_name('CreateAsset')->find_input($cf_form_id), 'custom field present' );
+is( $m->form_name('CreateAsset')->value($cf_form_id), '', 'custom field present and empty' );
+
+my $form         = $m->form_name('CreateAsset');
+my $status_input = $form->find_input('Status');
+is_deeply(
+    [ $status_input->possible_values ],
+    [ 'new', 'tracked', 'retired' ],
+    'status selectbox shows custom lifecycle for queue'
+);
+note('submit populated form');
+$m->submit_form( fields => { Name => 'asset foo', 'Catalog' => $catalog_2->id, $cf_form_id => $cf_test_value } );
+$m->text_contains( 'test_cf',      'custom field populated in display' );
+$m->text_contains( $cf_test_value, 'custom field populated in display' );
+
+my $asset = RT::Test::Assets->last_asset;
+ok( $asset->id, 'asset is created' );
+is( $asset->CatalogObj->id, $catalog_2->id, 'asset created with correct catalog' );
+
+done_testing();

commit 6c8534b927e07da969fa7a2303c1234c851c6875
Author: michel <michel at bestpractical.com>
Date:   Thu Feb 27 09:24:23 2020 +0100

    Remove select catalog modal popup on asset creation.

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 5ce829c46..d37d95216 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -216,7 +216,7 @@ sub BuildMainNav {
 
     if ($current_user->HasRight( Right => 'ShowAssetsMenu', Object => RT->System )) {
         my $assets = $top->child( "assets", title => loc("Assets"), path => "/Asset/Search/" );
-        $assets->child( "create", title => loc("Create"), path => "/Asset/CreateInCatalog.html" );
+        $assets->child( "create", title => loc("Create"), path => "/Asset/Create.html" );
         $assets->child( "search", title => loc("Search"), path => "/Asset/Search/" );
     }
 
diff --git a/lib/RT/Test/Assets.pm b/lib/RT/Test/Assets.pm
index 193d15f64..c36e51a21 100644
--- a/lib/RT/Test/Assets.pm
+++ b/lib/RT/Test/Assets.pm
@@ -97,7 +97,6 @@ sub load_or_create_catalog {
     return $obj;
 }
 
-
 sub create_asset {
     my %info  = @_;
     my $asset = RT::Asset->new( RT->SystemUser );
diff --git a/share/html/Asset/CreateInCatalog.html b/share/html/Asset/CreateInCatalog.html
deleted file mode 100644
index af0131843..000000000
--- a/share/html/Asset/CreateInCatalog.html
+++ /dev/null
@@ -1,51 +0,0 @@
-%# 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 }}}
-<& /Elements/Header,
-    Title => loc("Create new asset") &>
-<& /Elements/Tabs &>
-<& /Asset/Elements/CreateInCatalog &>
diff --git a/share/html/Asset/Elements/CreateAsset b/share/html/Asset/Elements/CreateAsset
index b57b1c13e..07c914c24 100644
--- a/share/html/Asset/Elements/CreateAsset
+++ b/share/html/Asset/Elements/CreateAsset
@@ -45,8 +45,8 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<form action="<% RT->Config->Get('WebPath') %>/Asset/CreateInCatalog.html">
+<form action="<% RT->Config->Get('WebPath') %>/Asset/Create.html">
   <div class="create-asset-button">
-    <input type="submit" class="btn btn-primary asset-create-modal" value="<&|/l&>Create new asset</&>" />
+    <input type="submit" class="btn btn-primary" value="<&|/l&>Create new asset 1</&>" />
   </div>
 </form>
diff --git a/share/html/Asset/Elements/CreateInCatalog b/share/html/Asset/Elements/CreateInCatalog
deleted file mode 100644
index 58f966a20..000000000
--- a/share/html/Asset/Elements/CreateInCatalog
+++ /dev/null
@@ -1,62 +0,0 @@
-%# 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 }}}
-<form action="<% RT->Config->Get("WebPath") %>/Asset/Create.html" id="AssetCreateInCatalog">
-  <div class="form-row">
-    <div class="col-md-12 text-center">
-      <&|/l&>Select a catalog for your new asset.</&>
-      <div class="d-inline-block">
-        <& /Asset/Elements/SelectCatalog &>
-      </div>
-    </div>
-  </div>
-  <div class="form-row">
-    <div class="col-md-12">
-      <& /Elements/Submit, Label => loc("Go"), Caption => loc("This will take you to the Create Asset page.") &>
-    </div>
-  </div>
-</form>
diff --git a/share/html/Asset/Helpers/CreateInCatalog b/share/html/Asset/Helpers/CreateInCatalog
deleted file mode 100644
index 66c261a02..000000000
--- a/share/html/Asset/Helpers/CreateInCatalog
+++ /dev/null
@@ -1,61 +0,0 @@
-%# 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 }}}
-<div class="modal-dialog modal-dialog-centered" role="document">
-  <div class="modal-content">
-    <div class="modal-header">
-      <h5 class="modal-title"><&|/l&>Create Asset</&></h5>
-      <a href="javascript:void(0)" class="close" data-dismiss="modal" aria-label="Close">
-        <span aria-hidden="true">×</span>
-      </a>
-    </div>
-    <div class="modal-body">
-        <& /Asset/Elements/CreateInCatalog &>
-    </div>
-  </div>
-</div>
-% $m->abort;
diff --git a/share/static/js/assets.js b/share/static/js/assets.js
index 3131d269e..a70a4dcd6 100644
--- a/share/static/js/assets.js
+++ b/share/static/js/assets.js
@@ -46,11 +46,4 @@ jQuery(function() {
             showModal
         );
     });
-    jQuery("#assets-create, .asset-create-modal").click(function(ev){
-        ev.preventDefault();
-        jQuery.get(
-            RT.Config.WebHomePath + "/Asset/Helpers/CreateInCatalog",
-            showModal
-        );
-    });
 });

commit 7546e0518870245f7205d431cc6b2bcb276a89d3
Author: michel <michel at bestpractical.com>
Date:   Thu Feb 27 14:37:25 2020 +0100

    Fixed tests to pass without modal catalog choice.

diff --git a/t/assets/web.t b/t/assets/web.t
index 2753128e1..8e6f75fda 100644
--- a/t/assets/web.t
+++ b/t/assets/web.t
@@ -33,10 +33,10 @@ ok $m->login, "Logged in agent";
 diag "Create basic asset (no CFs)";
 {
     $m->follow_link_ok({ id => "assets-create" }, "Asset create link");
-    $m->submit_form_ok({ with_fields => { Catalog => $catalog->id } }, "Picked a catalog");
     $m->submit_form_ok({
         with_fields => {
             id          => 'new',
+            Catalog     => $catalog->id,
             Name        => 'Thinkpad T420s',
             Description => 'A laptop',
         },

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


More information about the rt-commit mailing list