import rt 3.8.7
[freeside.git] / rt / t / api / groups.t
1
2 use strict;
3 use warnings;
4 use RT;
5 use RT::Test tests => 28;
6
7
8 {
9
10 ok (require RT::Groups);
11
12
13 }
14
15 {
16
17 # next had bugs
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");
22
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");
28
29
30 }
31
32 {
33
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";
37
38 my $g = RT::Group->new($RT::SystemUser);
39 ($id, $msg) = $g->CreateUserDefinedGroup(Name => 'Membertests');
40 ok ($id, $msg);
41
42 my ($aid, $amsg) =$g->AddMember($u->id);
43 ok ($aid, $amsg);
44 ok($g->HasMember($u->PrincipalObj),"G has member u");
45
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");
51
52
53 }
54
55 {
56     no warnings qw/redefine once/;
57
58 my $q = RT::Queue->new($RT::SystemUser);
59 my ($id, $msg) =$q->Create( Name => 'GlobalACLTest');
60 ok ($id, $msg);
61
62 my $testuser = RT::User->new($RT::SystemUser);
63 ($id,$msg) = $testuser->Create(Name => 'JustAnAdminCc');
64 ok ($id,$msg);
65
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);
73 ok ($id,$msg);
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);
76 ok($id,$msg);
77 ok ($testuser->HasRight(Object => $q, Right => 'OwnTicket') , "The test user does have the right to own tickets now. thank god.");
78
79 $groups = RT::Groups->new($RT::SystemUser);
80 $groups->WithRight(Right => 'OwnTicket', Object => $q);
81 ok ($id,$msg);
82 is($groups->Count, 3);
83
84 my $RTxGroup = RT::Group->new($RT::SystemUser);
85 ($id, $msg) = $RTxGroup->CreateUserDefinedGroup( Name => 'RTxGroup', Description => "RTx extension group");
86 ok ($id,$msg);
87 is ($RTxGroup->id, $id, "group loaded");
88
89 my $RTxSysObj = {};
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);
94 $ace->Table('ACL');
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");
98
99 my $RTxObj = {};
100 bless $RTxObj, 'RTx::System::Record';
101 *RTx::System::Record::Id = sub { 4; };
102 *RTx::System::Record::id = *RTx::System::Record::Id;
103
104 $groups = RT::Groups->new($RT::SystemUser);
105 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxSysObj);
106 is($groups->Count, 1, "RTxGroupRight found for RTxSysObj");
107
108 $groups = RT::Groups->new($RT::SystemUser);
109 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj);
110 is($groups->Count, 0, "RTxGroupRight not found for RTxObj");
111
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");
115
116 $ace = RT::Record->new($RT::SystemUser);
117 $ace->Table('ACL');
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");
121
122 my $RTxObj2 = {};
123 bless $RTxObj2, 'RTx::System::Record';
124 *RTx::System::Record::Id = sub { 5; };
125
126 $groups = RT::Groups->new($RT::SystemUser);
127 $groups->WithRight(Right => 'RTxGroupRight', Object => $RTxObj2);
128 is($groups->Count, 1, "RTxGroupRight found for RTxObj2");
129
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");
133
134
135
136
137 }
138
139 1;