rt 4.0.23
[freeside.git] / rt / share / html / Admin / Elements / EditScrips
index be208d6..127677d 100755 (executable)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -89,28 +89,42 @@ if ( $id ) {
 
 if ($QueueObj->id) {
     $Scrips->LimitToQueue($id);
+    $Format ||= RT->Config->Get('AdminSearchResultFormat')->{'Scrips'};
 }
 else {
     $Scrips->LimitToGlobal();
+    $Format ||= RT->Config->Get('AdminSearchResultFormat')->{'GlobalScrips'};
 }
 
-# {{{ deal with modifying and deleting existing scrips
+# deal with modifying and deleting existing scrips
 # we still support DeleteScrip-id format but array is preferred
+
+my @not_deleted;
 foreach my $id ( grep $_, @DeleteScrip, map /^DeleteScrip-(\d+)/, keys %ARGS ) {
     my $scrip = RT::Scrip->new($session{'CurrentUser'});
     $scrip->Load( $id );
-    my ($retval, $msg) = $scrip->Delete;
-    if ($retval) {
-        push @actions, loc("Scrip deleted");
-    }
-    else {
-        push @actions, $msg;
+    my $a = $scrip->FirstAttribute('Immutable');
+    if ( defined($a) and $a->Content ) {
+        # then disable the scrip instead of deleting it
+        my ($retval, $msg) = $scrip->SetStage('Disabled');
+        if ( $retval ) {
+            push @actions, loc("Scrip disabled (cannot delete system scrips)");
+        } else {
+            push @actions, $msg;
+            push @not_deleted, $id;
+        }
+    } else { # not an immutable scrip
+        my ($retval, $msg) = $scrip->Delete;
+        if ($retval) {
+            push @actions, loc("Scrip deleted");
+        }
+        else {
+            push @actions, $msg;
+            push @not_deleted, $id;
+        }
     }
 }
-# }}}
-
-$Format ||= RT->Config->Get('AdminSearchResultFormat')->{'Scrips'};
-
+$DECODED_ARGS->{DeleteScrip} = \@not_deleted;
 </%init>
 
 <%ARGS>