[Bps-public-commit] rt-extension-rest2 branch set-current-interface created. 1.14-7-gae63bd4
BPS Git Server
git at git.bestpractical.com
Wed Nov 24 18:51:19 UTC 2021
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-extension-rest2".
The branch, set-current-interface has been created
at ae63bd4e53540df67bbb08cffc527c222c0481f0 (commit)
- Log -----------------------------------------------------------------
commit ae63bd4e53540df67bbb08cffc527c222c0481f0
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Nov 22 22:43:12 2021 +0800
Set current interface if appliable
diff --git a/lib/RT/Extension/REST2/Dispatcher.pm b/lib/RT/Extension/REST2/Dispatcher.pm
index 166492e..b980a99 100644
--- a/lib/RT/Extension/REST2/Dispatcher.pm
+++ b/lib/RT/Extension/REST2/Dispatcher.pm
@@ -44,6 +44,7 @@ sub to_psgi_app {
return sub {
my $env = shift;
+ RT->SetCurrentInterface('REST2') if RT->can('SetCurrentInterface');
RT::ConnectToDatabase();
my $dispatch = $self->_dispatcher->dispatch($env->{PATH_INFO});
commit 9d38c7905c9eb59950b202294b106fbdbaaf0871
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Nov 22 22:41:13 2021 +0800
Create CleanupRequest middleware to really cleanup requests for REST2
Previously we added the cleanup functionality to to_psgi_app(initially
created as an alias of "to_app"), which never gets called. The call of
response_cb seems not quite right either as it doesn't expect a Plack
app as the first argument.
This commit wraps the functionality into a middleware and calls the more
complete version(RT::Interface::Web::Handler::CleanupRequest).
diff --git a/lib/RT/Extension/REST2.pm b/lib/RT/Extension/REST2.pm
index 5e0c8fc..6bfba12 100644
--- a/lib/RT/Extension/REST2.pm
+++ b/lib/RT/Extension/REST2.pm
@@ -1291,17 +1291,13 @@ handle them appropriately.
sub to_psgi_app {
my $self = shift;
my $res = $self->to_app(@_);
-
- return Plack::Util::response_cb($res, sub {
- my $res = shift;
- $self->CleanupRequest;
- });
}
sub to_app {
my $class = shift;
return builder {
+ enable '+RT::Extension::REST2::Middleware::CleanupRequest';
enable '+RT::Extension::REST2::Middleware::ErrorAsJSON';
enable '+RT::Extension::REST2::Middleware::Log';
enable '+RT::Extension::REST2::Middleware::Auth';
@@ -1326,24 +1322,6 @@ sub PSGIWrap {
};
}
-sub CleanupRequest {
-
- if ( $RT::Handle && $RT::Handle->TransactionDepth ) {
- $RT::Handle->ForceRollback;
- $RT::Logger->crit(
- "Transaction not committed. Usually indicates a software fault."
- . "Data loss may have occurred" );
- }
-
- # Clean out the ACL cache. the performance impact should be marginal.
- # Consistency is imprived, too.
- RT::Principal->InvalidateACLCache();
- DBIx::SearchBuilder::Record::Cachable->FlushCache
- if ( RT->Config->Get('WebFlushDbCacheEveryRequest')
- and UNIVERSAL::can(
- 'DBIx::SearchBuilder::Record::Cachable' => 'FlushCache' ) );
-}
-
=head1 AUTHOR
Best Practical Solutions, LLC <modules at bestpractical.com>
diff --git a/lib/RT/Extension/REST2/Middleware/CleanupRequest.pm b/lib/RT/Extension/REST2/Middleware/CleanupRequest.pm
new file mode 100644
index 0000000..bb3e529
--- /dev/null
+++ b/lib/RT/Extension/REST2/Middleware/CleanupRequest.pm
@@ -0,0 +1,64 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2021 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 }}}
+
+package RT::Extension::REST2::Middleware::CleanupRequest;
+
+use strict;
+use warnings;
+
+use base 'Plack::Middleware';
+
+sub call {
+ my ( $self, $env ) = @_;
+ my $res = $self->app->($env);
+ require RT::Interface::Web::Handler;
+ RT::Interface::Web::Handler->CleanupRequest;
+ return $res;
+}
+
+1;
-----------------------------------------------------------------------
hooks/post-receive
--
rt-extension-rest2
More information about the Bps-public-commit
mailing list