[Rt-commit] rt branch 5.0/statement-timeout3 created. rt-5.0.3-147-g8a37a037a8

BPS Git Server git at git.bestpractical.com
Fri Dec 23 15:25:36 UTC 2022


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/statement-timeout3 has been created
        at  8a37a037a8ebcecc036cdbb74c871eb066111515 (commit)

- Log -----------------------------------------------------------------
commit 8a37a037a8ebcecc036cdbb74c871eb066111515
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 16 16:28:55 2022 -0500

    Provide a simple framework for showing user messages
    
    During processing, messages can be stashed in notes,
    then Footer writes any messages to the page at the end
    for growl to then show to the user.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 2c06b49972..5b63911441 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2914,7 +2914,7 @@ sub SimpleQuery {
 
     # Show end user something if query failed.
     if ($HTML::Mason::Commands::m) {
-        $HTML::Mason::Commands::m->notes( 'SQLError' => 1 );
+        $HTML::Mason::Commands::m->notes( 'Message:SQLTimeout' => 1 );
     }
     return $ret;
 }
diff --git a/lib/RT/System.pm b/lib/RT/System.pm
index b07ea86abf..a3cda3e504 100644
--- a/lib/RT/System.pm
+++ b/lib/RT/System.pm
@@ -448,6 +448,38 @@ sub ExternalStorageURLFor {
     return $self->ExternalStorage->DownloadURLFor($Object);
 }
 
+# Catalog of message codes and user messages
+our %USER_MESSAGES;
+%USER_MESSAGES = (
+    'SQLTimeout' => 'Your query exceeded the maximum run time and was stopped. Try modifying your query to improve the performance or contact your RT admin.',
+);
+
+=head1 UserMessages
+
+Returns a hash with keys of message codes and values with corresonding user
+messages.
+
+To add messages, create entries in C<%USER_MESSAGES> with an appropriate
+message code as the key.
+
+To trigger display of that message, add an entry to notes, prefixed with
+C<Message:>, like:
+
+    if ( $something_happened ) {
+        $HTML::Mason::Commands::m->notes('Message:SQLTimeout' => 1 );
+    }
+
+For the web UI, C<Elements/Footer> will pick that up and display the message
+to the user in the browser.
+
+=cut
+
+sub UserMessages {
+    my $self = shift;
+    # Return a copy to avoid it from changing by accident.
+    return { %USER_MESSAGES };
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/share/html/Elements/Footer b/share/html/Elements/Footer
index bbf3126586..0de4f1972b 100644
--- a/share/html/Elements/Footer
+++ b/share/html/Elements/Footer
@@ -78,15 +78,28 @@
 </pre>
 % }
     </div>
-% if ( $m->notes('SQLError') ) {
-    <script type="text/javascript">
-    jQuery( function() {
-      jQuery.jGrowl(<% loc('Page content might be inaccurate because of SQL error. Please contact your admin, they can find more details in the logs.') |j %>, { sticky: true, themeState: 'none' });
-    } );
-    </script>
-% }
+<script type="text/javascript">
+RT.UserMessages = <% JSON( \%UserMessages ) |n%>;
+</script>
   </body>
 </html>
+<%init>
+my %UserMessages;
+
+# Check for any messages from the page processing stashed in notes.
+# We'll write them to the page so growl can find and display them.
+
+foreach my $note ( keys %{ $m->notes } ) {
+    if ( my ($message) = $note =~ /^Message\:(\w+)/ ) {
+        if ( my $user_message = RT->System->UserMessages->{$message} ) {
+            $UserMessages{$message} = loc( $user_message );
+        }
+        else {
+            RT->Logger->warning("Couldn't find user message for $message");
+        }
+    }
+}
+</%init>
 <%ARGS>
 $Debug => 0
 $Menu => 1
diff --git a/share/static/js/util.js b/share/static/js/util.js
index 25ba76a20e..89cdb658c7 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -1246,3 +1246,11 @@ function toggleTransactionDetails () {
 
     return false;
 }
+
+// Use Growl to show any UserMessages written to the page
+jQuery( function() {
+    var userMessages = RT.UserMessages;
+    for (var key in userMessages) {
+        jQuery.jGrowl(userMessages[key], { sticky: true, themeState: 'none' });
+    }
+} );

commit 4513ac1d42817a4b8dc330ea10a447b3bed07100
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Nov 23 05:42:01 2022 +0800

    Show end users a hint about SQL error

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 6f29cb2856..2c06b49972 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2907,6 +2907,18 @@ sub _CanonilizeObjectCustomFieldValue {
     }
 }
 
+sub SimpleQuery {
+    my $self = shift;
+    my $ret  = $self->SUPER::SimpleQuery(@_);
+    return $ret if $ret;
+
+    # Show end user something if query failed.
+    if ($HTML::Mason::Commands::m) {
+        $HTML::Mason::Commands::m->notes( 'SQLError' => 1 );
+    }
+    return $ret;
+}
+
 __PACKAGE__->FinalizeDatabaseType;
 
 RT::Base->_ImportOverlays();
diff --git a/share/html/Elements/Footer b/share/html/Elements/Footer
index 556efcc950..bbf3126586 100644
--- a/share/html/Elements/Footer
+++ b/share/html/Elements/Footer
@@ -78,6 +78,13 @@
 </pre>
 % }
     </div>
+% if ( $m->notes('SQLError') ) {
+    <script type="text/javascript">
+    jQuery( function() {
+      jQuery.jGrowl(<% loc('Page content might be inaccurate because of SQL error. Please contact your admin, they can find more details in the logs.') |j %>, { sticky: true, themeState: 'none' });
+    } );
+    </script>
+% }
   </body>
 </html>
 <%ARGS>

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list