[Rt-commit] r6001 - in rtir/branches/2.1-EXPERIMENTAL: . lib/RT/Condition

ruz at bestpractical.com ruz at bestpractical.com
Tue Sep 19 23:37:04 EDT 2006


Author: ruz
Date: Tue Sep 19 23:37:03 2006
New Revision: 6001

Added:
   rtir/branches/2.1-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituencyGroup.pm
   rtir/branches/2.1-EXPERIMENTAL/lib/RT/Condition/RTIR_RequireConstituencyGroupChange.pm
Modified:
   rtir/branches/2.1-EXPERIMENTAL/   (props changed)

Log:
 r1593 at cubic-pc:  cubic | 2006-09-20 07:44:15 +0400
 Constituency
 * manage admin cc groups when constituency changes


Added: rtir/branches/2.1-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituencyGroup.pm
==============================================================================
--- (empty file)
+++ rtir/branches/2.1-EXPERIMENTAL/lib/RT/Action/RTIR_SetConstituencyGroup.pm	Tue Sep 19 23:37:03 2006
@@ -0,0 +1,91 @@
+package RT::Action::RTIR_SetConstituencyGroup;
+
+use strict;
+use warnings;
+
+use base 'RT::Action::RTIR';
+
+=head2 Prepare
+
+Always run this.
+
+=cut
+
+
+sub Prepare { return 1 }
+
+=head2 Commit
+
+Set the Constituency custom field.
+
+=cut
+
+sub Commit {
+    my $self = shift;
+    my $ticket = $self->TicketObj;
+    my $admincc_group = $ticket->AdminCc;
+    unless ( $admincc_group && $admincc_group->id ) {
+        $RT::Logger->crit("Couldn't load AdminCc group of ticket #". $ticket->id);
+        return 0;
+    }
+    my $groups = $admincc_group->GroupMembersObj( Recursively => 0 );
+    $groups->LimitToUserDefinedGroups;
+    $groups->Limit( FIELD => 'Name', OPERATOR => 'STARTSWITH', VALUE => 'DutyTeam ' );
+
+    my $constituency = $ticket->FirstCustomFieldValue('_RTIR_Constituency') || '';
+    my $required_group_there = 0;
+    while ( my $group = $groups->Next ) {
+        if ( lc $group->Name eq 'dutyteam '. $constituency ) {
+            $required_group_there = 1;
+        } else {
+            my ($status, $msg) = $ticket->DeleteWatcher(
+                Type        => 'AdminCc',
+                PrincipalId => $group->id,
+            );
+            $RT::Logger->error("Couldn't delete admin cc: $msg") unless $status;
+        }
+    }
+    unless ( $required_group_there && $constituency ) {
+        my $group = RT::Group->new( $RT::SystemUser );
+        $group->LoadUserDefinedGroup('DutyTeam '. $constituency);
+        unless ( $group->id ) {
+            $RT::Logger->warning("Couldn't load group 'DutyTeam ". $constituency ."'");
+            # return success as if there is no custom group for the constituency
+            # then it means that no custom ACLs should be applied
+            return 1;
+        }
+        my ($status, $msg) = $ticket->AddWatcher(
+            Type        => 'AdminCc',
+            PrincipalId => $group->id,
+        );
+        $RT::Logger->error("Couldn't add admin cc: $msg") unless $status;
+    }
+    return 1;
+}
+
+{ my @constituencies;
+
+sub ConstituencyValues {
+    my $self = shift;
+    my $value = shift or return 0;
+    unless ( @constituencies ) {
+        my $cf = RT::CustomField->new( $RT::SystemUser );
+        $cf->Load('_RTIR_Constituency');
+        unless ( $cf->id ) {
+            $RT::Logger->crit("Couldn't load constituency field");
+            return 0;
+        }
+        @constituencies = map $_->Name, @{ $cf->Values->ItemsArrayRef };
+    }
+    return @constituencies;
+}
+
+}
+
+eval "require RT::Action::RTIR_SetConstituencyGroup_Vendor";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetConstituencyGroup_Vendor.pm});
+eval "require RT::Action::RTIR_SetConstituencyGroup_Local";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetConstituencyGroup_Local.pm});
+
+1;
+

Added: rtir/branches/2.1-EXPERIMENTAL/lib/RT/Condition/RTIR_RequireConstituencyGroupChange.pm
==============================================================================
--- (empty file)
+++ rtir/branches/2.1-EXPERIMENTAL/lib/RT/Condition/RTIR_RequireConstituencyGroupChange.pm	Tue Sep 19 23:37:03 2006
@@ -0,0 +1,38 @@
+package RT::Condition::RTIR_RequireConstituencyGroupChange;
+
+use strict;
+use warnings;
+
+use base 'RT::Condition::RTIR';
+use RT::CustomField;
+
+=head2 IsApplicable
+
+If a child had a Due Date change or changes parents.
+
+=cut
+
+sub IsApplicable {
+    my $self = shift;
+
+    my $type = $self->TransactionObj->Type;
+    return 1 if $type eq 'Create';
+    if ( $type eq 'CustomField' ) {
+        my $cf = RT::CustomField->new( $RT::SystemUser );
+        $cf->Load('_RTIR_Constituency');
+        unless ( $cf->id ) {
+            $RT::Logger->error("Couldn't load the 'Costituency' field");
+            return 0;
+        }
+        return 1 if $cf->id == $self->TransactionObj->Field;
+    }
+
+    return 0;
+}
+
+eval "require RT::Condition::RTIR_RequireConstituencyGroupChange_Vendor";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Condition/RTIR_RequireConstituencyGroupChange_Vendor.pm});
+eval "require RT::Condition::RTIR_RequireConstituencyGroupChange_Local";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Condition/RTIR_RequireConstituencyGroupChange_Local.pm});
+
+1;


More information about the Rt-commit mailing list