1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
use strict;
use warnings;
use RT::Test tests => undef;
my ($baseurl, $m) = RT::Test->started_ok;
my $url = $m->rt_base_url;
# Create User
my $user = RT::User->new(RT->SystemUser);
my ($ret, $msg) = $user->LoadOrCreateByEmail('customer@example.com');
ok($ret, 'ACL test user creation');
$user->SetName('customer');
$user->SetPrivileged(1);
($ret, $msg) = $user->SetPassword('customer');
$user->PrincipalObj->GrantRight(Right => 'ModifySelf');
$user->PrincipalObj->GrantRight(Right => 'ModifyOwnDashboard', Object => $RT::System);
$user->PrincipalObj->GrantRight(Right => 'CreateOwnDashboard', Object => $RT::System);
$user->PrincipalObj->GrantRight(Right => 'SeeOwnDashboard', Object => $RT::System);
$user->PrincipalObj->GrantRight(Right => 'SeeGroup', Object => $RT::System);
my $currentuser = RT::CurrentUser->new($user);
ok $m->login(customer => 'customer'), "logged in";
$m->get_ok($url."Dashboards/Modify.html?Create=1");
# Create Dashboard
$m->follow_link_ok({ id => 'reports-dashboard_create' });
$m->form_name('ModifyDashboard');
$m->field("Name" => 'test dashboard');
$m->click_button(value => 'Create');
$m->content_contains("Saved dashboard test dashboard");
# Make sure dashboard exists
my $dashboard = RT::Dashboard->new($currentuser);
my ($id) = $m->content =~ /name="id" value="(\d+)"/;
ok($id, "got an ID, $id");
$dashboard->LoadById($id);
is($dashboard->Name, "test dashboard");
# Attempt subscription without right
$m->get_ok("/Dashboards/Subscription.html?id=$id");
$m->content_lacks('id="page-subscription"', "shouldn't have Subscription link since we don't have the SubscribeDashboard right");
$m->form_name('SubscribeDashboard');
$m->click_button(name => 'Save');
$m->content_contains("Permission Denied");
$m->warning_like(qr/Unable to subscribe to dashboard.*Permission Denied/, "got a permission denied warning when trying to subscribe to a dashboard");
# Make sure subscription doesn't exist
$user->Attributes->RedoSearch;
is($user->Attributes->Named('Subscription'), 0, "no subscriptions");
# Attempt subscription with right
$user->PrincipalObj->GrantRight(Right => 'SubscribeDashboard', Object => $RT::System);
$m->get_ok("/Dashboards/Subscription.html?id=$id");
$m->content_contains('id="page-subscription"', "subscription link should be visible");
$m->form_name('SubscribeDashboard');
$m->click_button(name => 'Save');
$m->content_lacks("Permission Denied");
$m->content_contains("Subscribed to dashboard test dashboard");
# Verify subscription exists
$user->Attributes->RedoSearch;
is($user->Attributes->Named('Subscription'), 1, "we have a subscription");
# Test recipients missing warning
$m->follow_link_ok({ id => 'page-subscription' });
$m->form_name('SubscribeDashboard');
$m->untick("Dashboard-Subscription-Users-".$user->id,1);
$m->click_button(name => 'Save');
$m->content_contains('customer removed from dashboard subscription recipients');
$m->content_contains("Warning: This dashboard has no recipients");
# Create new user to search for
my $search_user = RT::User->new(RT->SystemUser);
($ret, $msg) = $search_user->LoadOrCreateByEmail('customer2@example.com');
ok($ret, 'ACL test user creation');
$search_user->SetName('customer2');
# Search for customer2 user and subscribe
$m->form_name('SubscribeDashboard');
$m->field(UserString => 'customer');
$m->click_button(name => 'OnlySearchForPeople');
$m->content_contains('customer2@example.com');
# Subscribe customer2
$m->form_name('SubscribeDashboard');
$m->tick("Dashboard-Subscription-Users-".$search_user->id, 1);
$m->click_button(name => 'Save');
$m->content_contains('customer2 added to dashboard subscription recipients');
# Make sure customer2 is listed as a recipient
$m->follow_link_ok({ id => 'page-subscription' });
$m->content_contains('customer2@example.com');
# Disable user
$search_user->SetDisabled(1);
# Confirm they are not shown
$m->follow_link_ok({ id => 'page-subscription' });
$m->content_lacks('customer2@example.com');
# Create new group to search for
my $search_group = RT::Group->new(RT->SystemUser);
($ret, $msg) = $search_group->CreateUserDefinedGroup(Name => 'customers test group');
ok($ret, 'Test customers group creation');
# Search for group
$m->form_name('SubscribeDashboard');
$m->field(GroupString => 'customers');
$m->click_button(name => 'OnlySearchForGroup');
$m->content_contains('customers test group');
# Subscribe group
$m->form_name('SubscribeDashboard');
$m->tick("Dashboard-Subscription-Groups-".$search_group->id, 1);
$m->click_button(name => 'Save');
$m->content_contains('customers test group added to dashboard subscription recipients');
# Make sure customers group is listed as a recipient
$m->follow_link_ok({ id => 'page-subscription' });
$m->content_contains('customers test group');
# Disable user
$search_group->SetDisabled(1);
# Confirm they are not shown
$m->follow_link_ok({ id => 'page-subscription' });
$m->content_lacks('customers test group');
$search_group->SetDisabled(0);
$m->follow_link_ok({ id => 'page-subscription' });
# Unsubscribe group
$m->form_name('SubscribeDashboard');
$m->untick("Dashboard-Subscription-Groups-".$search_group->id, 1);
$m->click_button(name => 'Save');
$m->content_contains('customers test group removed from dashboard subscription recipients');
# Make sure customers group is no longer listed as a recipient
$m->follow_link_ok({ id => 'page-subscription' });
$m->content_lacks('customers test group');
done_testing;
|