[Rt-commit] rt branch, 5.0/admin-rt-portal-layout-fix, updated. rt-5.0.0-4-ga4468b6fa3
Aaron Trevena
ast at bestpractical.com
Thu Sep 17 09:05:45 EDT 2020
The branch, 5.0/admin-rt-portal-layout-fix has been updated
via a4468b6fa367ac9a8c730c65e7179bc41de64c3f (commit)
from adb813d7bf029f8110cc15d32b1ebeea2e9c8982 (commit)
Summary of changes:
lib/RT/REST2/Resource/Ownership.pm | 172 +++++++++++++++++++++++++++++++++++++
1 file changed, 172 insertions(+)
create mode 100644 lib/RT/REST2/Resource/Ownership.pm
- Log -----------------------------------------------------------------
commit a4468b6fa367ac9a8c730c65e7179bc41de64c3f
Author: Aaron Trevena <ast at bestpractical.com>
Date: Thu Sep 17 14:05:08 2020 +0100
Initial simple implementation of take/untake/steal in REST 2.0
diff --git a/lib/RT/REST2/Resource/Ownership.pm b/lib/RT/REST2/Resource/Ownership.pm
new file mode 100644
index 0000000000..44119950cc
--- /dev/null
+++ b/lib/RT/REST2/Resource/Ownership.pm
@@ -0,0 +1,172 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2020 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::REST2::Resource::Ownership;
+use strict;
+use warnings;
+
+use Moose;
+use namespace::autoclean;
+use MIME::Base64;
+
+extends 'RT::REST2::Resource';
+use RT::REST2::Util qw( error_as_json );
+
+sub dispatch_rules {
+ Path::Dispatcher::Rule::Regex->new(
+ regex => qr{^/ticket/(\d+)/(take|untake|steal)$},
+ block => sub {
+ my ($match, $req) = @_;
+ my $ticket = RT::Ticket->new($req->env->{"rt.current_user"});
+ $ticket->Load($match->pos(1));
+ return { record => $ticket, type => $match->pos(2) },
+ },
+ );
+}
+
+has record => (
+ is => 'ro',
+ isa => 'RT::Record',
+ required => 1,
+);
+
+has type => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+);
+
+sub post_is_create { 1 }
+sub create_path_after_handler { 1 }
+sub allowed_methods { ['POST'] }
+sub charsets_provided { [ 'utf-8' ] }
+sub default_charset { 'utf-8' }
+sub content_types_provided { [ { 'application/json' => sub {} } ] }
+
+# Web::Machine uses 'application/octet-stream' as default content-type if
+# none provided. We accept empty POST so may receive empty content-type.
+sub content_types_accepted { [
+ { 'application/octet-stream' => 'change_ownership' },
+ { 'text/plain' => 'change_ownership' },
+ { 'text/html' => 'change_ownership' },
+ { 'application/x-www-form-urlencoded' => 'from_formdata' },
+ { 'multipart/form-data' => 'from_formdata' },
+ { 'application/json' => 'from_json' }
+] }
+
+# from_formdata/from_json allow specifying changing ownership
+# on behalf of given user.
+
+sub from_json {
+ my $self = shift;
+ # my $json_values = shift || JSON::decode_json( $self->request->content );
+ # $self->change_ownership({ user_id => $json_values->{acting_user} );
+ $self->change_ownership();
+}
+
+sub from_formdata {
+ my $self = shift;
+ # my $user_id = $self->request->parameters->{acting_user};
+ # $self->change_ownership({user_id => $user_id});
+ $self->change_ownership();
+}
+
+
+sub change_ownership {
+ my ($self, $args) = @_;
+
+ my $user = $self->record->CurrentUser;
+
+ # if ($args->{user_id}) {
+ # # load and validate user
+ # my $user_ok = 0;
+ # my $user_obj = RT::CurrentUser->new;
+ # $user_obj->Load($user_id);
+
+ # if ((!$user_obj->Id || $user_obj->Disabled) and length($user)) {
+ # my $check_user = RT::CurrentUser->new;
+ # $check_user->Load($user);
+ # if ($check_user->Id && $user_obj->Id == $check_user->Id) {
+ # $user_ok = 1;
+ # }
+ # }
+
+ # unless ($user_ok) {
+ # return error_as_json(
+ # $self->response,
+ # \400, "acting user $user_id not found or not valid");
+
+ # }
+ # }
+
+ my $ticket = $self->record;
+ my $action = ucfirst($self->type);
+ my ($status, $msg) = $ticket->$action();
+
+ unless ($status) {
+ return error_as_json(
+ $self->response,
+ \400, $msg);
+ }
+
+ $self->created_transaction($TransObj);
+ $self->response->body(JSON::to_json(\@results, { pretty => 1 }));
+
+ return 1;
+}
+
+sub create_path {
+ my $self = shift;
+ my $id = $self->record->Id;
+ return "/ticket/$id";
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
-----------------------------------------------------------------------
More information about the rt-commit
mailing list