3 use RT::Test nodata => 1, tests => 27;
6 'RTxGroupRight' => 'Just a right for testing rights',
10 my $g = RT::Group->new(RT->SystemUser);
11 my ($id, $msg) = $g->CreateUserDefinedGroup(Name => 'GroupsNotEqualTest');
12 ok ($id, "created group #". $g->id) or diag("error: $msg");
14 my $groups = RT::Groups->new(RT->SystemUser);
15 $groups->Limit( FIELD => 'id', OPERATOR => '!=', VALUE => $g->id );
16 $groups->LimitToUserDefinedGroups();
17 my $bug = grep $_->id == $g->id, @{$groups->ItemsArrayRef};
18 ok (!$bug, "didn't find group");
23 my $u = RT::User->new(RT->SystemUser);
24 my ($id, $msg) = $u->Create( Name => 'Membertests'. $$ );
25 ok ($id, 'created user') or diag "error: $msg";
27 my $g = RT::Group->new(RT->SystemUser);
28 ($id, $msg) = $g->CreateUserDefinedGroup(Name => 'Membertests');
31 my ($aid, $amsg) =$g->AddMember($u->id);
33 ok($g->HasMember($u->PrincipalObj),"G has member u");
35 my $groups = RT::Groups->new(RT->SystemUser);
36 $groups->LimitToUserDefinedGroups();
37 $groups->WithMember(PrincipalId => $u->id);
38 is ($groups->Count , 1,"found the 1 group - " . $groups->Count);
39 is ($groups->First->Id , $g->Id, "it's the right one");
42 no warnings qw/redefine once/;
44 my $q = RT::Queue->new(RT->SystemUser);
45 my ($id, $msg) =$q->Create( Name => 'GlobalACLTest');
48 my $testuser = RT::User->new(RT->SystemUser);
49 ($id,$msg) = $testuser->Create(Name => 'JustAnAdminCc');
52 my $global_admin_cc = RT::Group->new(RT->SystemUser);
53 $global_admin_cc->LoadSystemRoleGroup('AdminCc');
54 ok($global_admin_cc->id, "Found the global admincc group");
55 my $groups = RT::Groups->new(RT->SystemUser);
56 $groups->WithRight(Right => 'OwnTicket', Object => $q);
57 is($groups->Count, 1);
58 ($id, $msg) = $global_admin_cc->PrincipalObj->GrantRight(Right =>'OwnTicket', Object=> RT->System);
60 ok (!$testuser->HasRight(Object => $q, Right => 'OwnTicket') , "The test user does not have the right to own tickets in the test queue");
61 ($id, $msg) = $q->AddWatcher(Type => 'AdminCc', PrincipalId => $testuser->id);
63 ok ($testuser->HasRight(Object => $q, Right => 'OwnTicket') , "The test user does have the right to own tickets now. thank god.");
65 $groups = RT::Groups->new(RT->SystemUser);
66 $groups->WithRight(Right => 'OwnTicket', Object => $q);
68 is($groups->Count, 3);
70 my $RTxGroup = RT::Group->new(RT->SystemUser);
71 ($id, $msg) = $RTxGroup->CreateUserDefinedGroup( Name => 'RTxGroup', Description => "RTx extension group");
73 is ($RTxGroup->id, $id, "group loaded");
76 bless $RTxSysObj, 'RTx::System';
77 *RTx::System::Id = sub { 1; };
78 *RTx::System::id = *RTx::System::Id;
79 my $ace = RT::Record->new(RT->SystemUser);
81 $ace->_BuildTableAttributes unless ($RT::Record::_TABLE_ATTR->{ref($ace)});
82 ($id, $msg) = $ace->Create( PrincipalId => $RTxGroup->id, PrincipalType => 'Group', RightName => 'RTxGroupRight', ObjectType => 'RTx::System', ObjectId => 1);
83 ok ($id, "ACL for RTxSysObj created");
86 bless $RTxObj, 'RTx::System::Record';
87 *RTx::System::Record::Id = sub { 4; };
88 *RTx::System::Record::id = *RTx::System::Record::Id;
90 $groups = RT::Groups->new(RT->SystemUser);
91 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxSysObj);
92 is($groups->Count, 1, "RTxGroupRight found for RTxSysObj");
94 $groups = RT::Groups->new(RT->SystemUser);
95 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj);
96 is($groups->Count, 0, "RTxGroupRight not found for RTxObj");
98 $groups = RT::Groups->new(RT->SystemUser);
99 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj, EquivObjects => [ $RTxSysObj ]);
100 is($groups->Count, 1, "RTxGroupRight found for RTxObj using EquivObjects");
102 $ace = RT::Record->new(RT->SystemUser);
104 $ace->_BuildTableAttributes unless ($RT::Record::_TABLE_ATTR->{ref($ace)});
105 ($id, $msg) = $ace->Create( PrincipalId => $RTxGroup->id, PrincipalType => 'Group', RightName => 'RTxGroupRight', ObjectType => 'RTx::System::Record', ObjectId => 5 );
106 ok ($id, "ACL for RTxObj created");
109 bless $RTxObj2, 'RTx::System::Record';
110 *RTx::System::Record::Id = sub { 5; };
112 $groups = RT::Groups->new(RT->SystemUser);
113 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj2);
114 is($groups->Count, 1, "RTxGroupRight found for RTxObj2");
116 $groups = RT::Groups->new(RT->SystemUser);
117 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj2, EquivObjects => [ $RTxSysObj ]);
118 is($groups->Count, 1, "RTxGroupRight found for RTxObj2");