[Rt-commit] rt branch 5.0/add-scrip-copy-feature created. rt-5.0.4-64-g0fe62a035c

BPS Git Server git at git.bestpractical.com
Mon Jul 17 19:06:44 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/add-scrip-copy-feature has been created
        at  0fe62a035c0d9f4300ed509da99940697ead2474 (commit)

- Log -----------------------------------------------------------------
commit 0fe62a035c0d9f4300ed509da99940697ead2474
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Mon Jul 17 15:22:21 2023 -0300

    Add ability to copy a scrip to create new
    
    Previously, to copy the parameters from an existing scrip to a new one,
    you have to manually recreate each field.
    
    This commit adds a "Copy" link to the Modify page for a scrip.  Clicking
    the link will redirect user to the Create page with the parameters from
    the original scrip pre-filled.

diff --git a/share/html/Admin/Scrips/Create.html b/share/html/Admin/Scrips/Create.html
index a5e4b3de9d..73a41e8fd1 100644
--- a/share/html/Admin/Scrips/Create.html
+++ b/share/html/Admin/Scrips/Create.html
@@ -92,11 +92,45 @@
 $Queue => 0
 $Create => undef
 $Global => undef
+$id => undef
 </%ARGS>
 <%INIT>
 my @results;
 
 $ARGS{'Enabled'} = 1 unless $ARGS{'SetEnabled'};
+if ($id) {
+    my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
+    $scrip->Load($id);
+    if ($scrip) {
+
+        for my $item (qw/ScripCondition ScripAction Template /) {
+            $ARGS{$item} = $scrip->$item;
+        }
+
+        $ARGS{'Description'} = $scrip->Description;
+        while (1) {
+            # Make sure we don't have a scrip with the same name
+            $ARGS{'Description'}
+                = loc( 'Copy of [_1]', $ARGS{'Description'} );
+            last
+                unless RT::Scrip->new( $session{'CurrentUser'} )
+                ->LoadByCols( Description => $ARGS{'Description'} );
+        }
+
+        if ( $session{'CurrentUser'}
+            ->HasRight( Object => $RT::System, Right => 'ExecuteCode' ) )
+        {
+            for my $item (
+                qw/CustomIsApplicableCode CustomPrepareCode CustomCommitCode/)
+            {
+                $ARGS{$item} ||= $scrip->$item;
+            }
+        }
+
+        # Make sure scrip is disabled by default
+        $ARGS{'Enabled'} = 0;
+    }
+}
 
 my $queue_obj;
 if ( $Queue ) {
diff --git a/share/html/Admin/Scrips/Modify.html b/share/html/Admin/Scrips/Modify.html
index de2a9c6d7b..0d9c9bac32 100644
--- a/share/html/Admin/Scrips/Modify.html
+++ b/share/html/Admin/Scrips/Modify.html
@@ -93,6 +93,11 @@
 
 </&>
 
+  <div class="form-row">
+    <div class="col-12">
+      <& /Elements/Submit, Label => loc('Copy Scrip'), Name => 'Copy' &>
+    </div>
+  </div>
   <div class="form-row">
     <div class="col-12">
       <& /Elements/Submit, Label => loc('Save Changes'), Name => 'Update', Reset => 1 &>
@@ -101,6 +106,11 @@
 
 % if ($session{CurrentUser}->HasRight(Object => $RT::System, Right => 'ExecuteCode')) {
 <& Elements/EditCustomCode, %ARGS, Scrip => $scrip &>
+  <div class="form-row">
+    <div class="col-12">
+      <& /Elements/Submit, Label => loc('Copy Scrip'), Name => 'Copy' &>
+    </div>
+  </div>
   <div class="form-row">
     <div class="col-12">
       <& /Elements/Submit, Label => loc('Save Changes'), Name => 'Update', Reset => 1 &>
@@ -113,6 +123,7 @@
 $id     => undef
 $Update => undef
 $From   => undef
+$Copy => undef
 </%ARGS>
 <%INIT>
 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
@@ -145,6 +156,8 @@ if ( $Update ) {
             From => $From,
         },
     );
+} elsif ( $Copy ) {
+    RT::Interface::Web::Redirect( RT->Config->Get('WebURL') ."Admin/Scrips/Create.html?id=$id&Queue=$From" );
 }
 
 my $EnabledChecked = qq[checked="checked"];

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list