1# BEGIN BPS TAGGED BLOCK {{{
2#
3# COPYRIGHT:
4#
5# This software is Copyright (c) 1996-2021 Best Practical Solutions, LLC
6#                                          <sales@bestpractical.com>
7#
8# (Except where explicitly superseded by other copyright notices)
9#
10#
11# LICENSE:
12#
13# This work is made available to you under the terms of Version 2 of
14# the GNU General Public License. A copy of that license should have
15# been provided with this software, but in any event can be snarfed
16# from www.gnu.org.
17#
18# This work is distributed in the hope that it will be useful, but
19# WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21# General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26# 02110-1301 or visit their web page on the internet at
27# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28#
29#
30# CONTRIBUTION SUBMISSION POLICY:
31#
32# (The following paragraph is not intended to limit the rights granted
33# to you to modify and distribute this software under the terms of
34# the GNU General Public License and is only of importance to you if
35# you choose to contribute your changes and enhancements to the
36# community by submitting them to Best Practical Solutions, LLC.)
37#
38# By intentionally submitting any modifications, corrections or
39# derivatives to this work, or any other work intended for use with
40# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41# you are the copyright holder for those contributions and you grant
42# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43# royalty-free, perpetual, license to use, copy, create derivative
44# works based on those contributions, and sublicense and distribute
45# those contributions and any derivatives thereof.
46#
47# END BPS TAGGED BLOCK }}}
48
49=head1 NAME
50
51  RT::ScripCondition - RT scrip conditional
52
53=head1 SYNOPSIS
54
55  use RT::ScripCondition;
56
57
58=head1 DESCRIPTION
59
60This module should never be called directly by client code. it's an internal module which
61should only be accessed through exported APIs in other modules.
62
63
64
65=head1 METHODS
66
67=cut
68
69
70package RT::ScripCondition;
71
72use strict;
73use warnings;
74
75use base 'RT::Record';
76
77
78sub Table {'ScripConditions'}
79
80sub _Accessible  {
81    my $self = shift;
82    my %Cols = ( Name  => 'read',
83                 Description => 'read',
84                 ApplicableTransTypes => 'read',
85                 ExecModule  => 'read',
86                 Argument  => 'read',
87                 Creator => 'read/auto',
88                 Created => 'read/auto',
89                 LastUpdatedBy => 'read/auto',
90                 LastUpdated => 'read/auto'
91               );
92    return($self->SUPER::_Accessible(@_, %Cols));
93}
94
95
96=head2 Create
97
98  Takes a hash. Creates a new Condition entry.
99  should be better documented.
100
101=cut
102
103sub Create  {
104    my $self = shift;
105    return($self->SUPER::Create(@_));
106}
107
108
109=head2 Delete
110
111No API available for deleting things just yet.
112
113=cut
114
115sub Delete {
116    my $self = shift;
117
118    unless ( $self->CurrentUser->HasRight( Object => RT->System, Right => 'ModifyScrips' ) ) {
119        return ( 0, $self->loc('Permission Denied') );
120    }
121
122    my $scrips = RT::Scrips->new( RT->SystemUser );
123    $scrips->Limit( FIELD => 'ScripCondition', VALUE => $self->id );
124    if ( $scrips->Count ) {
125        return ( 0, $self->loc('Condition is in use') );
126    }
127
128    return $self->SUPER::Delete(@_);
129}
130
131sub UsedBy {
132    my $self = shift;
133
134    my $scrips = RT::Scrips->new( $self->CurrentUser );
135    $scrips->Limit( FIELD => 'ScripCondition', VALUE => $self->Id );
136    return $scrips;
137}
138
139
140=head2 Load IDENTIFIER
141
142Loads a condition takes a name or ScripCondition id.
143
144=cut
145
146sub Load  {
147    my $self = shift;
148    my $identifier = shift;
149
150    unless (defined $identifier) {
151        return (undef);
152    }
153
154    if ($identifier !~ /\D/) {
155        return ($self->SUPER::LoadById($identifier));
156    }
157    else {
158        return ($self->LoadByCol('Name', $identifier));
159    }
160}
161
162
163=head2 LoadCondition  HASH
164
165takes a hash which has the following elements:  TransactionObj and TicketObj.
166Loads the Condition module in question.
167
168=cut
169
170
171sub LoadCondition  {
172    my $self = shift;
173    my %args = ( TransactionObj => undef,
174                 TicketObj => undef,
175                 @_ );
176
177    my $module = $self->ExecModule;
178    my $type = 'RT::Condition::' . $module;
179    $type->require or die "Require of $type condition module failed.\n$@\n";
180
181    return $self->{'Condition'} = $type->new(
182        ScripConditionObj => $self,
183        TicketObj => $args{'TicketObj'},
184        ScripObj => $args{'ScripObj'},
185        TransactionObj => $args{'TransactionObj'},
186        Argument => $self->Argument,
187        ApplicableTransTypes => $self->ApplicableTransTypes,
188        CurrentUser => $self->CurrentUser
189    );
190}
191
192
193
194
195=head2 Describe
196
197Helper method to call the condition module's Describe method.
198
199=cut
200
201sub Describe  {
202    my $self = shift;
203    return ($self->{'Condition'}->Describe());
204
205}
206
207
208=head2 IsApplicable
209
210Helper method to call the condition module's IsApplicable method.
211
212=cut
213
214sub IsApplicable  {
215    my $self = shift;
216    return ($self->{'Condition'}->IsApplicable());
217
218}
219
220
221
222=head2 id
223
224Returns the current value of id.
225(In the database, id is stored as int(11).)
226
227
228=cut
229
230
231=head2 Name
232
233Returns the current value of Name.
234(In the database, Name is stored as varchar(200).)
235
236
237
238=head2 SetName VALUE
239
240
241Set Name to VALUE.
242Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
243(In the database, Name will be stored as a varchar(200).)
244
245
246=cut
247
248
249=head2 Description
250
251Returns the current value of Description.
252(In the database, Description is stored as varchar(255).)
253
254
255
256=head2 SetDescription VALUE
257
258
259Set Description to VALUE.
260Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
261(In the database, Description will be stored as a varchar(255).)
262
263
264=cut
265
266
267=head2 ExecModule
268
269Returns the current value of ExecModule.
270(In the database, ExecModule is stored as varchar(60).)
271
272
273
274=head2 SetExecModule VALUE
275
276
277Set ExecModule to VALUE.
278Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
279(In the database, ExecModule will be stored as a varchar(60).)
280
281
282=cut
283
284
285=head2 Argument
286
287Returns the current value of Argument.
288(In the database, Argument is stored as varbinary(255).)
289
290
291
292=head2 SetArgument VALUE
293
294
295Set Argument to VALUE.
296Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
297(In the database, Argument will be stored as a varbinary(255).)
298
299
300=cut
301
302
303=head2 ApplicableTransTypes
304
305Returns the current value of ApplicableTransTypes.
306(In the database, ApplicableTransTypes is stored as varchar(60).)
307
308
309
310=head2 SetApplicableTransTypes VALUE
311
312
313Set ApplicableTransTypes to VALUE.
314Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
315(In the database, ApplicableTransTypes will be stored as a varchar(60).)
316
317
318=cut
319
320
321=head2 Creator
322
323Returns the current value of Creator.
324(In the database, Creator is stored as int(11).)
325
326
327=cut
328
329
330=head2 Created
331
332Returns the current value of Created.
333(In the database, Created is stored as datetime.)
334
335
336=cut
337
338
339=head2 LastUpdatedBy
340
341Returns the current value of LastUpdatedBy.
342(In the database, LastUpdatedBy is stored as int(11).)
343
344
345=cut
346
347
348=head2 LastUpdated
349
350Returns the current value of LastUpdated.
351(In the database, LastUpdated is stored as datetime.)
352
353
354=cut
355
356
357
358sub _CoreAccessible {
359    {
360
361        id =>
362                {read => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
363        Name =>
364                {read => 1, write => 1, sql_type => 12, length => 200,  is_blob => 0,  is_numeric => 0,  type => 'varchar(200)', default => ''},
365        Description =>
366                {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varchar(255)', default => ''},
367        ExecModule =>
368                {read => 1, write => 1, sql_type => 12, length => 60,  is_blob => 0,  is_numeric => 0,  type => 'varchar(60)', default => ''},
369        Argument =>
370                {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varbinary(255)', default => ''},
371        ApplicableTransTypes =>
372                {read => 1, write => 1, sql_type => 12, length => 60,  is_blob => 0,  is_numeric => 0,  type => 'varchar(60)', default => ''},
373        Creator =>
374                {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
375        Created =>
376                {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
377        LastUpdatedBy =>
378                {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
379        LastUpdated =>
380                {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
381
382 }
383};
384
385sub PreInflate {
386    my $class = shift;
387    my ($importer, $uid, $data) = @_;
388
389    $class->SUPER::PreInflate( $importer, $uid, $data );
390
391    return not $importer->SkipBy( "Name", $class, $uid, $data );
392}
393
394sub __DependsOn {
395    my $self = shift;
396    my %args = (
397        Shredder => undef,
398        Dependencies => undef,
399        @_,
400    );
401    my $deps = $args{'Dependencies'};
402
403# Scrips
404    my $objs = RT::Scrips->new( $self->CurrentUser );
405    $objs->Limit( FIELD => 'ScripCondition', VALUE => $self->Id );
406    $deps->_PushDependencies(
407        BaseObject => $self,
408        Flags => RT::Shredder::Constants::DEPENDS_ON,
409        TargetObjects => $objs,
410        Shredder => $args{'Shredder'}
411    );
412
413    return $self->SUPER::__DependsOn( %args );
414}
415
416RT::Base->_ImportOverlays();
417
4181;
419