5 use RT::Test tests => 28;
10 ok (require RT::Groups);
18 # Groups->Limit( FIELD => 'id', OPERATOR => '!=', VALUE => xx );
19 my $g = RT::Group->new($RT::SystemUser);
20 my ($id, $msg) = $g->CreateUserDefinedGroup(Name => 'GroupsNotEqualTest');
21 ok ($id, "created group #". $g->id) or diag("error: $msg");
23 my $groups = RT::Groups->new($RT::SystemUser);
24 $groups->Limit( FIELD => 'id', OPERATOR => '!=', VALUE => $g->id );
25 $groups->LimitToUserDefinedGroups();
26 my $bug = grep $_->id == $g->id, @{$groups->ItemsArrayRef};
27 ok (!$bug, "didn't find group");
34 my $u = RT::User->new($RT::SystemUser);
35 my ($id, $msg) = $u->Create( Name => 'Membertests'. $$ );
36 ok ($id, 'created user') or diag "error: $msg";
38 my $g = RT::Group->new($RT::SystemUser);
39 ($id, $msg) = $g->CreateUserDefinedGroup(Name => 'Membertests');
42 my ($aid, $amsg) =$g->AddMember($u->id);
44 ok($g->HasMember($u->PrincipalObj),"G has member u");
46 my $groups = RT::Groups->new($RT::SystemUser);
47 $groups->LimitToUserDefinedGroups();
48 $groups->WithMember(PrincipalId => $u->id);
49 is ($groups->Count , 1,"found the 1 group - " . $groups->Count);
50 is ($groups->First->Id , $g->Id, "it's the right one");
56 no warnings qw/redefine once/;
58 my $q = RT::Queue->new($RT::SystemUser);
59 my ($id, $msg) =$q->Create( Name => 'GlobalACLTest');
62 my $testuser = RT::User->new($RT::SystemUser);
63 ($id,$msg) = $testuser->Create(Name => 'JustAnAdminCc');
66 my $global_admin_cc = RT::Group->new($RT::SystemUser);
67 $global_admin_cc->LoadSystemRoleGroup('AdminCc');
68 ok($global_admin_cc->id, "Found the global admincc group");
69 my $groups = RT::Groups->new($RT::SystemUser);
70 $groups->WithRight(Right => 'OwnTicket', Object => $q);
71 is($groups->Count, 1);
72 ($id, $msg) = $global_admin_cc->PrincipalObj->GrantRight(Right =>'OwnTicket', Object=> $RT::System);
74 ok (!$testuser->HasRight(Object => $q, Right => 'OwnTicket') , "The test user does not have the right to own tickets in the test queue");
75 ($id, $msg) = $q->AddWatcher(Type => 'AdminCc', PrincipalId => $testuser->id);
77 ok ($testuser->HasRight(Object => $q, Right => 'OwnTicket') , "The test user does have the right to own tickets now. thank god.");
79 $groups = RT::Groups->new($RT::SystemUser);
80 $groups->WithRight(Right => 'OwnTicket', Object => $q);
82 is($groups->Count, 3);
84 my $RTxGroup = RT::Group->new($RT::SystemUser);
85 ($id, $msg) = $RTxGroup->CreateUserDefinedGroup( Name => 'RTxGroup', Description => "RTx extension group");
87 is ($RTxGroup->id, $id, "group loaded");
90 bless $RTxSysObj, 'RTx::System';
91 *RTx::System::Id = sub { 1; };
92 *RTx::System::id = *RTx::System::Id;
93 my $ace = RT::Record->new($RT::SystemUser);
95 $ace->_BuildTableAttributes unless ($RT::Record::_TABLE_ATTR->{ref($ace)});
96 ($id, $msg) = $ace->Create( PrincipalId => $RTxGroup->id, PrincipalType => 'Group', RightName => 'RTxGroupRight', ObjectType => 'RTx::System', ObjectId => 1);
97 ok ($id, "ACL for RTxSysObj created");
100 bless $RTxObj, 'RTx::System::Record';
101 *RTx::System::Record::Id = sub { 4; };
102 *RTx::System::Record::id = *RTx::System::Record::Id;
104 $groups = RT::Groups->new($RT::SystemUser);
105 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxSysObj);
106 is($groups->Count, 1, "RTxGroupRight found for RTxSysObj");
108 $groups = RT::Groups->new($RT::SystemUser);
109 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj);
110 is($groups->Count, 0, "RTxGroupRight not found for RTxObj");
112 $groups = RT::Groups->new($RT::SystemUser);
113 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj, EquivObjects => [ $RTxSysObj ]);
114 is($groups->Count, 1, "RTxGroupRight found for RTxObj using EquivObjects");
116 $ace = RT::Record->new($RT::SystemUser);
118 $ace->_BuildTableAttributes unless ($RT::Record::_TABLE_ATTR->{ref($ace)});
119 ($id, $msg) = $ace->Create( PrincipalId => $RTxGroup->id, PrincipalType => 'Group', RightName => 'RTxGroupRight', ObjectType => 'RTx::System::Record', ObjectId => 5 );
120 ok ($id, "ACL for RTxObj created");
123 bless $RTxObj2, 'RTx::System::Record';
124 *RTx::System::Record::Id = sub { 5; };
126 $groups = RT::Groups->new($RT::SystemUser);
127 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj2);
128 is($groups->Count, 1, "RTxGroupRight found for RTxObj2");
130 $groups = RT::Groups->new($RT::SystemUser);
131 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj2, EquivObjects => [ $RTxSysObj ]);
132 is($groups->Count, 1, "RTxGroupRight found for RTxObj2");