[Rt-commit] r8485 - in rt/branches/3.7-EXPERIMENTAL-TUNIS: lib/RT
thayes at bestpractical.com
thayes at bestpractical.com
Thu Aug 9 16:46:42 EDT 2007
Author: thayes
Date: Thu Aug 9 16:46:41 2007
New Revision: 8485
Added:
rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/TicketLocking.pm
Modified:
rt/branches/3.7-EXPERIMENTAL-TUNIS/ (props changed)
rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm
rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket_Overlay.pm
Log:
r8691 at toth: toth | 2007-08-09 16:45:27 -0400
* Moved locking methods from Ticket.pm to new TicketLocking.pm
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm Thu Aug 9 16:46:41 2007
@@ -140,7 +140,7 @@
Resolved => '',
Disabled => '0',
- @_);
+ @_);
$self->SUPER::Create(
EffectiveId => $args{'EffectiveId'},
Queue => $args{'Queue'},
@@ -221,89 +221,13 @@
=cut
sub QueueObj {
- my $self = shift;
- my $Queue = RT::Queue->new($self->CurrentUser);
- $Queue->Load($self->__Value('Queue'));
- return($Queue);
+ my $self = shift;
+ my $Queue = RT::Queue->new($self->CurrentUser);
+ $Queue->Load($self->__Value('Queue'));
+ return($Queue);
}
-my @Types = qw(Auto Take Hard);
-sub Locked {
- my $ticket =shift;
- return $ticket->FirstAttribute('RT_Lock');
-}
-
-sub Lock {
- my $ticket = shift;
- my $type = shift || 'Auto';
-
- if ( my $lock = $ticket->Locked() ) {
- return undef if $lock->Content->{'User'} != $ticket->CurrentUser->id;
- my $LockType = $lock->Content->{'Type'};
- my $priority;
- my $LockPriority;
- for(my $i = 0; $i < scalar @Types; $i++) {
- $priority = $i if (lc $Types[$i]) eq (lc $type);
- $LockPriority = $i if (lc $Types[$i]) eq (lc $LockType);
- }
- return undef if $priority <= $LockPriority;
- } else {
- $ticket->Unlock($type); #Remove any existing locks (because this one has greater priority)
- $ticket->SetAttribute(
- Name => 'RT_Lock',
- Content => {
- User => $ticket->CurrentUser->id,
- Timestamp => time(),
- Type => $type
- }
- );
- }
-}
-
-
-sub Unlock {
- my $ticket = shift;
- my $type = shift || 'Auto';
-
- my $lock = $ticket->RT::Ticket::Locked();
- return undef unless $lock;
- return undef unless $lock->Content->{User} == $ticket->CurrentUser->id;
-
- my $LockType = $lock->Content->{'Type'};
- my $priority;
- my $LockPriority;
- for(my $i = 0; $i < scalar @Types; $i++) {
- $priority = $i if (lc $Types[$i]) eq (lc $type);
- $LockPriority = $i if (lc $Types[$i]) eq (lc $LockType);
- }
- return undef if $priority < $LockPriority;
- $ticket->DeleteAttribute('RT_Lock');
- return $lock;
-}
-
-
-sub BreakLock {
- my $ticket = shift;
- my $lock = $ticket->RT::Ticket::Locked();
- return undef unless $lock;
- $ticket->DeleteAttribute('RT_Lock');
-}
-
-
-
-sub RemoveUserLocks {
- my $user = shift;
-
- return undef unless $user;
-
- my $attribs = RT::Attributes->new($user);
- $attribs->Limit(FIELD => 'Creator', OPERATOR=> '=', VALUE => $user->id(), ENTRYAGGREGATOR => 'AND');
- my @attributes = $attribs->Named('RT_Lock');
- foreach my $lock (@attributes) {
- $lock->Delete();
- }
-}
=head2 Type
@@ -670,55 +594,55 @@
{
id =>
- {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
+ {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
EffectiveId =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
Queue =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
Type =>
- {read => 1, write => 1, sql_type => 12, length => 16, is_blob => 0, is_numeric => 0, type => 'varchar(16)', default => ''},
+ {read => 1, write => 1, sql_type => 12, length => 16, is_blob => 0, is_numeric => 0, type => 'varchar(16)', default => ''},
IssueStatement =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
Resolution =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
Owner =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
Subject =>
- {read => 1, write => 1, sql_type => 12, length => 200, is_blob => 0, is_numeric => 0, type => 'varchar(200)', default => '[no subject]'},
+ {read => 1, write => 1, sql_type => 12, length => 200, is_blob => 0, is_numeric => 0, type => 'varchar(200)', default => '[no subject]'},
InitialPriority =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
FinalPriority =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
Priority =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
TimeEstimated =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
TimeWorked =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
Status =>
- {read => 1, write => 1, sql_type => 12, length => 10, is_blob => 0, is_numeric => 0, type => 'varchar(10)', default => ''},
+ {read => 1, write => 1, sql_type => 12, length => 10, is_blob => 0, is_numeric => 0, type => 'varchar(10)', default => ''},
TimeLeft =>
- {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
Told =>
- {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
+ {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
Starts =>
- {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
+ {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
Started =>
- {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
+ {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
Due =>
- {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
+ {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
Resolved =>
- {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
+ {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
LastUpdatedBy =>
- {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
LastUpdated =>
- {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
+ {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
Creator =>
- {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
+ {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
Created =>
- {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
+ {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
Disabled =>
- {read => 1, write => 1, sql_type => 5, length => 6, is_blob => 0, is_numeric => 1, type => 'smallint(6)', default => '0'},
+ {read => 1, write => 1, sql_type => 5, length => 6, is_blob => 0, is_numeric => 1, type => 'smallint(6)', default => '0'},
}
};
Added: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/TicketLocking.pm
==============================================================================
--- (empty file)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/TicketLocking.pm Thu Aug 9 16:46:41 2007
@@ -0,0 +1,136 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
+# <jesse 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/copyleft/gpl.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::Ticket;
+
+my @Types = qw(Auto Take Hard);
+
+sub Locked {
+ my $ticket = shift;
+ my $lock = $ticket->FirstAttribute('RT_Lock');
+ if($lock) {
+ my $duration = time() - $lock->Content->{'Timestamp'};
+ my $expiry = RT->Config->Get('LockExpiry');
+ unless($duration < $expiry) {
+ $ticket->DeleteAttribute('RT_Lock');
+ undef $lock;
+ }
+ }
+ return $lock;
+}
+
+sub Lock {
+ my $ticket = shift;
+ my $type = shift || 'Auto';
+
+ if ( my $lock = $ticket->Locked() ) {
+ return undef if $lock->Content->{'User'} != $ticket->CurrentUser->id;
+ my $LockType = $lock->Content->{'Type'};
+ my $priority;
+ my $LockPriority;
+ for(my $i = 0; $i < scalar @Types; $i++) {
+ $priority = $i if (lc $Types[$i]) eq (lc $type);
+ $LockPriority = $i if (lc $Types[$i]) eq (lc $LockType);
+ }
+ return undef if $priority <= $LockPriority;
+ } else {
+ $ticket->Unlock($type); #Remove any existing locks (because this one has greater priority)
+ $ticket->SetAttribute(
+ Name => 'RT_Lock',
+ Content => {
+ User => $ticket->CurrentUser->id,
+ Timestamp => time(),
+ Type => $type
+ }
+ );
+ }
+}
+
+
+sub Unlock {
+ my $ticket = shift;
+ my $type = shift || 'Auto';
+
+ my $lock = $ticket->RT::Ticket::Locked();
+ return undef unless $lock;
+ return undef unless $lock->Content->{User} == $ticket->CurrentUser->id;
+
+ my $LockType = $lock->Content->{'Type'};
+ my $priority;
+ my $LockPriority;
+ for(my $i = 0; $i < scalar @Types; $i++) {
+ $priority = $i if (lc $Types[$i]) eq (lc $type);
+ $LockPriority = $i if (lc $Types[$i]) eq (lc $LockType);
+ }
+ return undef if $priority < $LockPriority;
+ $ticket->DeleteAttribute('RT_Lock');
+ return $lock;
+}
+
+
+sub BreakLock {
+ my $ticket = shift;
+ my $lock = $ticket->RT::Ticket::Locked();
+ return undef unless $lock;
+ $ticket->DeleteAttribute('RT_Lock');
+}
+
+
+
+sub RemoveUserLocks {
+ my $user = shift;
+
+ return undef unless $user;
+
+ my $attribs = RT::Attributes->new($user);
+ $attribs->Limit(FIELD => 'Creator', OPERATOR=> '=', VALUE => $user->id(), ENTRYAGGREGATOR => 'AND');
+ my @attributes = $attribs->Named('RT_Lock');
+ foreach my $lock (@attributes) {
+ $lock->Delete();
+ }
+}
Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket_Overlay.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket_Overlay.pm Thu Aug 9 16:46:41 2007
@@ -81,6 +81,7 @@
use RT::URI::fsck_com_rt;
use RT::URI;
use MIME::Entity;
+use RT::TicketLocking;
# {{{ LINKTYPEMAP
@@ -91,11 +92,11 @@
MemberOf => { Type => 'MemberOf',
Mode => 'Target', },
Parents => { Type => 'MemberOf',
- Mode => 'Target', },
+ Mode => 'Target', },
Members => { Type => 'MemberOf',
Mode => 'Base', },
Children => { Type => 'MemberOf',
- Mode => 'Base', },
+ Mode => 'Base', },
HasMember => { Type => 'MemberOf',
Mode => 'Base', },
RefersTo => { Type => 'RefersTo',
@@ -904,18 +905,18 @@
EffectiveId => $EffectiveId,
Queue => $QueueObj->Id,
Owner => $Owner->Id,
- Subject => $args{'Subject'}, # loc
- InitialPriority => $args{'InitialPriority'}, # loc
- FinalPriority => $args{'FinalPriority'}, # loc
- Priority => $args{'InitialPriority'}, # loc
- Status => $args{'Status'}, # loc
- TimeWorked => $args{'TimeWorked'}, # loc
- Type => $args{'Type'}, # loc
- Created => $args{'Created'}, # loc
- Told => $args{'Told'}, # loc
- LastUpdated => $args{'Updated'}, # loc
- Resolved => $args{'Resolved'}, # loc
- Due => $args{'Due'}, # loc
+ Subject => $args{'Subject'}, # loc
+ InitialPriority => $args{'InitialPriority'}, # loc
+ FinalPriority => $args{'FinalPriority'}, # loc
+ Priority => $args{'InitialPriority'}, # loc
+ Status => $args{'Status'}, # loc
+ TimeWorked => $args{'TimeWorked'}, # loc
+ Type => $args{'Type'}, # loc
+ Created => $args{'Created'}, # loc
+ Told => $args{'Told'}, # loc
+ LastUpdated => $args{'Updated'}, # loc
+ Resolved => $args{'Resolved'}, # loc
+ Due => $args{'Due'}, # loc
);
# If the ticket didn't have an id
@@ -1588,8 +1589,8 @@
# no ACL check since this is used in acl decisions
# unless ($self->CurrentUserHasRight('ShowTicket')) {
- # return(undef);
- # }
+ # return(undef);
+ # }
#Tickets won't yet have owners when they're being created.
unless ( $self->OwnerObj->id ) {
@@ -2366,7 +2367,7 @@
$uri_obj->FromURI( $args{'URI'} );
unless ( $uri_obj->Resolver && $uri_obj->Scheme ) {
- my $msg = $self->loc( "Couldn't resolve '[_1]' into a URI.", $args{'URI'} );
+ my $msg = $self->loc( "Couldn't resolve '[_1]' into a URI.", $args{'URI'} );
$RT::Logger->warning( "$msg\n" );
return( 0, $msg );
}
@@ -2902,10 +2903,10 @@
my %args;
if (@_ == 1) {
- $args{Status} = shift;
+ $args{Status} = shift;
}
else {
- %args = (@_);
+ %args = (@_);
}
#Check ACL
@@ -3034,7 +3035,7 @@
# }}}
-
+
# {{{ Actions + Routines dealing with transactions
# {{{ sub SetTold and _SetTold
@@ -3146,10 +3147,10 @@
require RT::Scrips;
RT::Scrips->new($RT::SystemUser)->Apply(
- Stage => 'TransactionBatch',
- TicketObj => $self,
- TransactionObj => $batch->[0],
- Type => join(',', (map { $_->Type } @{$batch}) )
+ Stage => 'TransactionBatch',
+ TicketObj => $self,
+ TransactionObj => $batch->[0],
+ Type => join(',', (map { $_->Type } @{$batch}) )
);
}
More information about the Rt-commit
mailing list