1 #$Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Scrip.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
5 RT::Scrip - an RT Scrip object
18 ok (require RT::TestHarness);
19 ok (require RT::Scrip);
32 $self->{'table'} = "Scrips";
33 return ($self->SUPER::_Init(@_));
40 my %Cols = ( ScripAction => 'read/write',
41 ScripCondition => 'read/write',
42 Stage => 'read/write',
43 Queue => 'read/write',
44 Template => 'read/write',
46 return($self->SUPER::_Accessible(@_, %Cols));
54 Creates a new entry in the Scrips table. Takes a paramhash with the attributes:
56 Queue A queue id or 0 for a global scrip
57 Template A template ID or name.
58 Behavior is undefined if you have multiple items with
60 ScripAction A ScripAction id or name
61 Behavior is undefined if you have multiple items with
63 ScripCondition A ScripCondition id or name
64 Behavior is undefined if you have multiple items with
67 Returns (retval, msg);
68 retval is 0 for failure or scrip id. msg is a textual description of what happened.
74 my %args = ( Queue => undef,
77 ScripCondition => undef,
78 Stage => 'TransactionCreate',
83 if ($args{'Queue'} == 0 ) {
84 unless ($self->CurrentUser->HasSystemRight('ModifyScrips')) {
85 return (0, 'Permission Denied');
89 my $QueueObj = new RT::Queue($self->CurrentUser);
90 $QueueObj->Load($args{'Queue'});
91 unless ($QueueObj->id()) {
92 return (0,'Invalid queue');
94 unless ($QueueObj->CurrentUserHasRight('ModifyScrips')) {
95 return (0, 'Permssion Denied');
99 #TODO +++ validate input
101 require RT::ScripAction;
102 my $action = new RT::ScripAction($self->CurrentUser);
103 $action->Load($args{'ScripAction'});
104 return (0, "Action ".$args{'ScripAction'}." not found") unless $action->Id;
106 require RT::Template;
107 my $template = new RT::Template($self->CurrentUser);
108 $template->Load($args{'Template'});
109 return (0, 'Template not found') unless $template->Id;
111 require RT::ScripCondition;
112 my $condition = new RT::ScripCondition($self->CurrentUser);
113 $condition->Load($args{'ScripCondition'});
115 unless ($condition->Id) {
116 return (0, 'Condition not found');
119 my $id = $self->SUPER::Create(Queue => $args{'Queue'},
120 Template => $template->Id,
121 ScripCondition => $condition->id,
122 Stage => $args{'Stage'},
123 ScripAction => $action->Id
125 return ($id, 'Scrip Created');
141 unless ($self->CurrentUserHasRight('ModifyScrips')) {
142 return (0, 'Permission Denied');
145 return ($self->SUPER::Delete(@_));
153 Retuns an RT::Queue object with this Scrip\'s queue
160 if (!$self->{'QueueObj'}) {
162 $self->{'QueueObj'} = RT::Queue->new($self->CurrentUser);
163 $self->{'QueueObj'}->Load($self->Queue);
165 return ($self->{'QueueObj'});
175 Retuns an RT::Action object with this Scrip\'s Action
182 unless (defined $self->{'ScripActionObj'}) {
183 require RT::ScripAction;
185 $self->{'ScripActionObj'} = RT::ScripAction->new($self->CurrentUser);
186 #TODO: why are we loading Actions with templates like this.
187 # two seperate methods might make more sense
188 $self->{'ScripActionObj'}->Load($self->ScripAction, $self->Template);
190 return ($self->{'ScripActionObj'});
196 # {{{ sub TemplateObj
199 Retuns an RT::Template object with this Scrip\'s Template
206 unless (defined $self->{'TemplateObj'}) {
207 require RT::Template;
208 $self->{'TemplateObj'} = RT::Template->new($self->CurrentUser);
209 $self->{'TemplateObj'}->Load($self->Template);
211 return ($self->{'TemplateObj'});
219 Calls the action object's prepare method
225 $self->ActionObj->Prepare(@_);
233 Calls the action object's commit method
239 $self->ActionObj->Commit(@_);
244 # {{{ sub ConditionObj
248 Retuns an RT::ScripCondition object with this Scrip's IsApplicable
255 unless (defined $self->{'ScripConditionObj'}) {
256 require RT::ScripCondition;
257 $self->{'ScripConditionObj'} = RT::ScripCondition->new($self->CurrentUser);
258 $self->{'ScripConditionObj'}->Load($self->ScripCondition);
260 return ($self->{'ScripConditionObj'});
265 # {{{ sub IsApplicable
269 Calls the Condition object\'s IsApplicable method
275 return ($self->ConditionObj->IsApplicable(@_));
283 $self->{'ActionObj'} = undef;
287 # {{{ ACL related methods
291 # does an acl check and then passes off the call
295 unless ($self->CurrentUserHasRight('ModifyScrips')) {
296 $RT::Logger->debug("CurrentUser can't modify Scrips for ".$self->Queue."\n");
297 return (0, 'Permission Denied');
299 return $self->__Set(@_);
305 # does an acl check and then passes off the call
309 unless ($self->CurrentUserHasRight('ShowScrips')) {
310 $RT::Logger->debug("CurrentUser can't modify Scrips for ".$self->__Value('Queue')."\n");
314 return $self->__Value(@_);
318 # {{{ sub CurrentUserHasRight
320 =head2 CurrentUserHasRight
322 Helper menthod for HasRight. Presets Principal to CurrentUser then
327 sub CurrentUserHasRight {
330 return ($self->HasRight( Principal => $self->CurrentUser->UserObj,
341 Takes a param-hash consisting of "Right" and "Principal" Principal is
342 an RT::User object or an RT::CurrentUser object. "Right" is a textual
343 Right string that applies to Scrips.
349 my %args = ( Right => undef,
353 if ((defined $self->SUPER::_Value('Queue')) and ($self->SUPER::_Value('Queue') != 0)) {
354 return ( $args{'Principal'}->HasQueueRight(
355 Right => $args{'Right'},
356 Queue => $self->SUPER::_Value('Queue'),
357 Principal => $args{'Principal'}
363 return( $args{'Principal'}->HasSystemRight( $args{'Right'}) );