first pass RT4 merge, RT#13852
[freeside.git] / rt / t / web / rights1.t
1 #!/usr/bin/perl -w
2 use strict;
3 use HTTP::Cookies;
4
5 use RT::Test nodata => 1, tests => 31;
6 my ($baseurl, $agent) = RT::Test->started_ok;
7
8 # Create a user with basically no rights, to start.
9 my $user_obj = RT::User->new(RT->SystemUser);
10 my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('customer-'.$$.'@example.com');
11 ok($ret, 'ACL test user creation');
12 $user_obj->SetName('customer-'.$$);
13 $user_obj->SetPrivileged(1);
14 ($ret, $msg) = $user_obj->SetPassword('customer');
15 ok($ret, "ACL test password set. $msg");
16
17 # Now test the web interface, making sure objects come and go as
18 # required.
19
20
21 my $cookie_jar = HTTP::Cookies->new;
22
23 # give the agent a place to stash the cookies
24
25 $agent->cookie_jar($cookie_jar);
26
27 # get the top page
28 $agent->login( $user_obj->Name, 'customer');
29
30 # Test for absence of Configure and Preferences tabs.
31 ok(!$agent->find_link( url => "$RT::WebPath/Admin/",
32                        text => 'Configuration'), "No config tab" );
33 ok(!$agent->find_link( url => "$RT::WebPath/User/Prefs.html",
34                        text => 'Preferences'), "No prefs pane" );
35
36 # Now test for their presence, one at a time.  Sleep for a bit after
37 # ACL changes, thanks to the 10s ACL cache.
38 my ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ShowConfigTab', Object => RT->System);
39
40 ok($grantid,$grantmsg);
41
42 $agent->reload;
43
44 $agent->content_contains('Logout', "Reloaded page successfully");
45 ok($agent->find_link( url => "$RT::WebPath/Admin/",
46                        text => 'Configuration'), "Found config tab" );
47 my ($revokeid,$revokemsg) =$user_obj->PrincipalObj->RevokeRight(Right => 'ShowConfigTab');
48 ok ($revokeid,$revokemsg);
49 ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf');
50 ok ($grantid,$grantmsg);
51 $agent->reload();
52 $agent->content_contains('Logout', "Reloaded page successfully");
53 ok($agent->find_link( 
54                        id => 'preferences-settings' ), "Found prefs pane" );
55 ($revokeid,$revokemsg) = $user_obj->PrincipalObj->RevokeRight(Right => 'ModifySelf');
56 ok ($revokeid,$revokemsg);
57 # Good.  Now load the search page and test Load/Save Search.
58 $agent->follow_link( url => "$RT::WebPath/Search/Build.html",
59                      text => 'Tickets');
60 is($agent->status, 200, "Fetched search builder page");
61 $agent->content_lacks("Load saved search", "No search loading box");
62 $agent->content_lacks("Saved searches", "No saved searches box");
63
64 ($grantid,$grantmsg) = $user_obj->PrincipalObj->GrantRight(Right => 'LoadSavedSearch');
65 ok($grantid,$grantmsg);
66 $agent->reload();
67 $agent->content_contains("Load saved search", "Search loading box exists");
68 $agent->content_unlike(qr/input\s+type=['"]submit['"][^>]+name=['"]SavedSearchSave['"]/i,
69    "Still no saved searches box");
70
71 ($grantid,$grantmsg) =$user_obj->PrincipalObj->GrantRight(Right => 'CreateSavedSearch');
72 ok ($grantid,$grantmsg);
73 $agent->reload();
74 $agent->content_contains("Load saved search", "Search loading box still exists");
75 $agent->content_like(qr/input\s+type=['"]submit['"][^>]+name=['"]SavedSearchSave['"]/i,
76    "Saved searches box exists");
77
78 # Create a group, and a queue, so we can test limited user visibility
79 # via SelectOwner.
80
81 my $queue_obj = RT::Queue->new(RT->SystemUser);
82 ($ret, $msg) = $queue_obj->Create(Name => 'CustomerQueue-'.$$, 
83                                   Description => 'queue for SelectOwner testing');
84 ok($ret, "SelectOwner test queue creation. $msg");
85 my $group_obj = RT::Group->new(RT->SystemUser);
86 ($ret, $msg) = $group_obj->CreateUserDefinedGroup(Name => 'CustomerGroup-'.$$,
87                               Description => 'group for SelectOwner testing');
88 ok($ret, "SelectOwner test group creation. $msg");
89
90 # Add our customer to the customer group, and give it queue rights.
91 ($ret, $msg) = $group_obj->AddMember($user_obj->PrincipalObj->Id());
92 ok($ret, "Added customer to its group. $msg");
93 ($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'OwnTicket',
94                                      Object => $queue_obj);
95                                      
96 ok($grantid,$grantmsg);
97 ($grantid,$grantmsg) =$group_obj->PrincipalObj->GrantRight(Right => 'SeeQueue',
98                                      Object => $queue_obj);
99 ok ($grantid,$grantmsg);
100 # Now.  When we look at the search page we should be able to see
101 # ourself in the list of possible owners.
102
103 $agent->reload();
104 ok($agent->form_name('BuildQuery'), "Yep, form is still there");
105 my $input = $agent->current_form->find_input('ValueOfActor');
106 ok(grep(/customer-$$/, $input->value_names()), "Found self in the actor listing");
107