From dddfb2203f9e88cda64274f5ddda4c4b3eac2258 Mon Sep 17 00:00:00 2001 From: sunnavy Date: Fri, 8 Dec 2023 09:52:31 -0500 Subject: [PATCH] Support inline edit for assets --- etc/RT_Config.pm.in | 9 +++ share/html/Asset/Display.html | 46 ++++++++++- share/html/Asset/Elements/EditPeopleInline | 93 ++++++++++++++++++++++ share/html/Asset/Elements/ShowSummary | 61 ++++++++++++-- share/html/Asset/Search/Bulk.html | 1 + share/html/Elements/CollectionAsTable/Row | 13 ++- share/html/Elements/CollectionList | 2 +- share/html/Elements/ColumnMap | 26 +++++- share/html/Elements/RT__Asset/ColumnMap | 6 +- share/html/Helpers/AssetUpdate | 79 ++++++++++++++++++ share/html/Helpers/CollectionListRow | 2 +- t/web/helpers-http-cache-headers.t | 20 ++++- 12 files changed, 343 insertions(+), 15 deletions(-) create mode 100644 share/html/Asset/Elements/EditPeopleInline create mode 100644 share/html/Helpers/AssetUpdate diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in index 31e31631686..fe528c51e7e 100644 --- a/etc/RT_Config.pm.in +++ b/etc/RT_Config.pm.in @@ -2593,6 +2593,15 @@ Grouping" are created by the L setting. 'Links' => 'hide', 'People' => 'link', }, + 'RT::Asset' => { + '_default' => 'click', + + 'Grouping Name' => 'link', + 'Another Grouping' => 'click', + 'Dates' => 'hide', + 'Links' => 'hide', + 'People' => 'link', + }, ); =back diff --git a/share/html/Asset/Display.html b/share/html/Asset/Display.html index 553fb4f66a4..b1035b45fef 100644 --- a/share/html/Asset/Display.html +++ b/share/html/Asset/Display.html @@ -53,7 +53,7 @@ <& /Elements/ListActions, actions => \@results &> -<& Elements/ShowSummary, AssetObj => $asset &> +<& Elements/ShowSummary, AssetObj => $asset, InlineEdit => $InlineEdit &> % $m->callback(CallbackName => 'AfterShowSummary', ARGSRef => \%ARGS, Asset => $asset); @@ -68,9 +68,53 @@ <%args> $id => undef +$InlineEdit => RT->Config->Get( 'InlineEdit', $session{CurrentUser} ) <%init> my @results; my $asset = LoadAsset($id); + +# fill ACL cache +$asset->CurrentUser->PrincipalObj->HasRights( Object => $asset ); + +my $SkipProcessing; + +$m->callback( CallbackName => 'BeforeProcessArguments', + AssetObj => $asset, + ActionsRef => \@results, ARGSRef => \%ARGS, + SkipProcessing => \$SkipProcessing ); + +my ($status, @msg) = $m->comp( + '/Elements/ValidateCustomFields', + Object => $asset, + CustomFields => $asset->CustomFields, + ARGSRef => \%ARGS, +); +unless ($status) { + push @results, @msg; + $SkipProcessing = 1; +} + +if ( !$SkipProcessing ) { + + push @results, ProcessAssetRoleMembers( $asset => %ARGS ); + push @results, ProcessRecordLinks( RecordObj => $asset, ARGSRef => \%ARGS ); + push @results, ProcessObjectCustomFieldUpdates( Object => $asset, ARGSRef => \%ARGS ); + + push @results, UpdateRecordObject( + Object => $asset, + AttributesRef => [ $asset->WritableAttributes ], + ARGSRef => \%ARGS, + ); + +} + $m->callback(CallbackName => 'BeforeDisplay', ARGSRef => \%ARGS, Asset => $asset, Results => \@results); + +MaybeRedirectForResults( + Actions => \@results, + Path => '/Asset/Display.html', + Anchor => $ARGS{'Anchor'}, + Arguments => { id => $asset->Id }, +); diff --git a/share/html/Asset/Elements/EditPeopleInline b/share/html/Asset/Elements/EditPeopleInline new file mode 100644 index 00000000000..b0a3fbaf6f4 --- /dev/null +++ b/share/html/Asset/Elements/EditPeopleInline @@ -0,0 +1,93 @@ +%# BEGIN BPS TAGGED BLOCK {{{ +%# +%# COPYRIGHT: +%# +%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC +%# +%# +%# (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 }}} + +% for my $role ($AssetObj->Roles( ACLOnly => 0 )) { +
+
<% $AssetObj->LabelForRole($role) %>
+ <& EditRoleMembers, Object => $AssetObj, Role => $role &> +
+% } + +
+
<&|/l&>Add a person
+
+
+ <& SelectRoleType, Object => $AssetObj, Name => "AddUserRoleMember-Role" &> +
+
+ " + class="form-control" + > +
+
+
+ +
+
<&|/l&>Add a group
+
+
+ <& SelectRoleType, Object => $AssetObj, Name => "AddGroupRoleMember-Role" &> +
+
+ " + class="form-control" + > +
+
+
+ +<& /Elements/EditCustomFields, Object => $AssetObj, Grouping => 'People', InTable => 1 &> +<%ARGS> +$AssetObj => undef + diff --git a/share/html/Asset/Elements/ShowSummary b/share/html/Asset/Elements/ShowSummary index 3aa12a3b22f..9ee3de3cdf5 100644 --- a/share/html/Asset/Elements/ShowSummary +++ b/share/html/Asset/Elements/ShowSummary @@ -47,6 +47,7 @@ %# END BPS TAGGED BLOCK }}} <%args> $AssetObj +$InlineEdit => 0 <%init> my @sections = ( @@ -56,9 +57,6 @@ my @sections = ( "Links", #loc ); -my $can_edit = $session{CurrentUser}->Privileged - && $AssetObj->CurrentUserHasRight("ModifyAsset"); - my %link; for my $section (@sections) { my $page = $section eq 'Basics' ? "Modify.html" : "Modify$section.html"; @@ -67,20 +65,71 @@ for my $section (@sections) { . "/Asset/$page?id=" . $AssetObj->id; } + +my $can_modify = $AssetObj->CurrentUserHasRight('ModifyAsset'); +my $can_modify_cf = $AssetObj->CurrentUserHasRight('ModifyCustomField'); + +$m->callback( CallbackName => 'ModifyRights', %ARGS, AssetObj => $AssetObj, ARGSRef => \%ARGS, + CanModify => \$can_modify, CanModifyCF => \$can_modify_cf ); + +my $edit_label = $m->interp->apply_escapes( loc("Edit"), 'h' ); +my $cancel_label = $m->interp->apply_escapes( loc("Cancel"), 'h' ); + +my %inline_edit_behavior; +if (RT->Config->Get('InlineEditPanelBehavior')) { + %inline_edit_behavior = %{ RT->Config->Get('InlineEditPanelBehavior')->{'RT::Asset'} || {} }; +} + +my $modify_inline + = '' + . qq{} + . '' + . '';