[Rt-commit] rt branch, 4.4/dashboard-subscription-user-group, repushed
Dustin Graves
dustin at bestpractical.com
Fri Dec 11 14:56:44 EST 2015
The branch 4.4/dashboard-subscription-user-group was deleted and repushed:
was 00fbc49051c3c532d681d822d852e3ba53bf2ac3
now 4113f4c65136af2badcba93bec31dba06a7b3135
1: 44f4599 ! 1: 4113f4c change dashboard subscription recipient input to robust user/group search
@@ -31,15 +31,13 @@
+
+ if ($recipient) {
+ for ( RT::EmailParser->ParseEmailAddress($recipient) ) {
-+ my $addr = $_->address;
-+
-+ my $user = RT::User->new(RT->SystemUser);
-+ $user->LoadByEmail($addr);
-+
-+ unless ($user->id) { # we need to create user
-+ my $principal = RT::System->CanonicalizePrincipal(User => $addr);
-+ $user->Load($principal->Object->id);
-+ }
++ my ( $email, $name ) = ( $_->address, $_->name );
++
++ $user->LoadOrCreateByEmail(
++ EmailAddress => $email,
++ RealName => $name,
++ Comments => 'Autocreated when added as a dashboard subscription recipient',
++ );
+
+ push @users, $user->id;
+ }
@@ -266,42 +264,56 @@
+</tr>
+</table>
+
-+% if ($UserString || $GroupString) {
-+<strong><&|/l&>Search Results</&>:</strong>
-+<ul>
-+
-+% if ($Users) {
-+% while (my $u = $Users->Next ) {
-+<li>
++<br/>
++<&|/l&>Add New Recipients</&>:
++<table>
++
++% if ( $Users && $Users->Count ) {
++<tr><td></td><td>
++<&|/l&>User</&>
++</tr></td>
++% while ( my $u = $Users->Next ) {
++<tr><td>
+<input type="checkbox" class="checkbox" name="Dashboard-Subscription-Users-<%$u->id%>" value="1" />
++</td><td>
+<input type="hidden" name="Dashboard-Subscription-Users-<%$u->id%>" value="0" />
+<& '/Elements/ShowUser', User => $u, style=>'verbose' &>
-+% }
-+% }
-+
-+% if ($Groups) {
-+% while (my $g = $Groups->Next ) {
-+<li>
++</td></tr>
++% }
++% }
++
++% if ( $Groups && $Groups->Count ) {
++<tr><td></td><td>
++<&|/l&>Group</&>
++</tr></td>
++% while ( my $g = $Groups->Next ) {
++<tr><td>
+<input type="checkbox" class="checkbox" name="Dashboard-Subscription-Groups-<%$g->id%>" value="1" />
++</td><td>
+<input type="hidden" name="Dashboard-Subscription-Groups-<%$g->id%>" value="0" />
+<%$g->Name%> (<%$g->Description%>)
-+</li>
-+% }
-+% }
-+
-+% unless (($Users && $Users->Count) || ($Groups && $Groups->Count)) {
-+<li><i><&|/l&>none</&></i></li>
-+% }
-+
-+</ul>
-+% }
++</td></tr>
++% }
++% }
++
++<tr><td></td><td>
++<&|/l&>Email</&>
++</tr></td>
++
++% for my $i (1 .. 3) {
++<tr><td></td><td>
++<& /Elements/EmailInput, Name => 'Dashboard-Subscription-Email-' . $i, Size => '20' &>
++</td></tr>
++% }
++
++</table>
+
+</td>
+<td class="current-recipients">
+
-+<strong><&|/l&>Current Recipients</&>:</strong>
++<&|/l&>Current Recipients</&>:
++
+<ul>
-+
+% my $current_user_id = $session{CurrentUser}->id;
+% my $current_user_subscribed = $recipients_users && grep { $_ == $current_user_id } @$recipients_users;
+<li>
@@ -392,6 +404,14 @@
</tr>
</table>
@@
+ </form>
+
+ <%INIT>
++use List::MoreUtils 'uniq';
+
+ my ($title, @results);
+ my $Loaded = 0;
+@@
Dow => 'Monday',
Dom => 1,
Rows => 20,
@@ -404,30 +424,9 @@
if defined($ARGS{$field}) || $ARGS{$field.'-Magic'};
}
-+# update recipients
-+for my $key (keys %ARGS) {
-+ next unless $key =~ /^Dashboard-Subscription-(Users|Groups)-(\d+)$/;
-+
-+ my ($mode, $type, $id) = ('', $1, $2);
-+
-+ # find out proper value for user/group checkbox
-+ my $add_keep_recipient = ref $ARGS{$key} eq 'ARRAY' ?
-+ grep { $_ } @{ $ARGS{$key} } :
-+ $ARGS{$key};
-+
-+ my $record; # hold user/group object
-+ if ($type eq 'Users') {
-+ my $user = RT::User->new($session{CurrentUser});
-+ $user->Load( $id );
-+ $record = $user;
-+ } elsif ($type eq 'Groups') {
-+ my $group = RT::Group->new($session{CurrentUser});
-+ $group->Load( $id );
-+ $record = $group;
-+ }
-
--# this'll be defined on submit
--if (defined $ARGS{Save}) {
+-
+ # this'll be defined on submit
+ if (defined $ARGS{Save}) {
- my $ok = 1;
-
- # validation
@@ -436,16 +435,62 @@
- if (@addresses == 0) {
- push @results, loc('Recipient must be an email address');
- $ok = 0;
-- }
-+ my @recipients = @{ $fields{Recipients}->{$type} };
-+ my $is_prev_recipient = grep { $_ == $id } @recipients;
-+
-+ if ($add_keep_recipient and not $is_prev_recipient) { # Add User/Group
-+ push @recipients, $id;
-+ push @results, loc("[_1] added to dashboard subscription recipients.", $record->Name);
-+ } elsif (not $add_keep_recipient and $is_prev_recipient) { # Remove User/Group
-+ @recipients = grep { $_ != $id } @recipients;
-+ push @results, loc("[_1] removed from dashboard subscription recipients.", $record->Name);
++ # update recipients
++ for my $key (keys %ARGS) {
++ my $val = $ARGS{$key};
++ if ( $key =~ /^Dashboard-Subscription-Email-\d+$/ && $val ) {
++ my @recipients = @{ $fields{Recipients}->{Users} };
++
++ for ( RT::EmailParser->ParseEmailAddress( $val ) ) {
++ my ( $email, $name ) = ( $_->address, $_->name );
++
++ my $user = RT::User->new($session{CurrentUser});
++ $user->LoadOrCreateByEmail(
++ EmailAddress => $email,
++ RealName => $name,
++ Comments => 'Autocreated when added as a dashboard subscription recipient',
++ );
++
++ my $is_prev_recipient = grep { $_ == $user->id } @recipients;
++ if ( not $is_prev_recipient ) {
++ push @recipients, $user->id;
++ push @results, loc("[_1] added to dashboard subscription recipients", $email);
++ }
++ }
++ @{ $fields{Recipients}->{Users} } = uniq @recipients;
++
++ } elsif ($key =~ /^Dashboard-Subscription-(Users|Groups)-(\d+)$/) {
++ my ($mode, $type, $id) = ('', $1, $2);
++ my @recipients = @{ $fields{Recipients}->{$type} };
++
++ # find out proper value for user/group checkbox
++ my $add_keep_recipient = ref $ARGS{$key} eq 'ARRAY' ?
++ grep { $_ } @{ $ARGS{$key} } :
++ $ARGS{$key};
++
++ my $record; # hold user/group object
++ if ($type eq 'Users') {
++ my $user = RT::User->new($session{CurrentUser});
++ $user->Load( $id );
++ $record = $user;
++ } elsif ($type eq 'Groups') {
++ my $group = RT::Group->new($session{CurrentUser});
++ $group->Load( $id );
++ $record = $group;
++ }
++
++ my $is_prev_recipient = grep { $_ == $id } @recipients;
++
++ if ($add_keep_recipient and not $is_prev_recipient) { # Add User/Group
++ push @recipients, $id;
++ push @results, loc("[_1] added to dashboard subscription recipients", $record->Name);
++ } elsif (not $add_keep_recipient and $is_prev_recipient) { # Remove User/Group
++ @recipients = grep { $_ != $id } @recipients;
++ push @results, loc("[_1] removed from dashboard subscription recipients", $record->Name);
++ }
++
++ @{ $fields{Recipients}->{$type} } = uniq @recipients;
+ }
}
- if ($ok) {
@@ -454,20 +499,14 @@
- $id = delete $fields{'DashboardId'}; # immutable
- ($ok, $msg) = $SubscriptionObj->SetSubValues(%fields);
- $fields{'DashboardId'} = $id;
-+ use List::MoreUtils 'uniq';
-+ @{ $fields{Recipients}->{$type} } = uniq @recipients;
-+}
-
-- $msg = loc("Subscription updated") if $ok;
-- push @results, $msg;
-+# this'll be defined on submit
-+if (defined $ARGS{Save}) {
+ # update
+ if ($SubscriptionObj) {
+ $id = delete $fields{'DashboardId'}; # immutable
+ ($ok, $msg) = $SubscriptionObj->SetSubValues(%fields);
+ $fields{'DashboardId'} = $id;
-+
+
+- $msg = loc("Subscription updated") if $ok;
+- push @results, $msg;
+ $msg = loc("Subscription updated") if $ok;
+ push @results, $msg;
+ }
@@ -551,5 +590,191 @@
+
+td.current-recipients {
+ vertical-align: top;
++ padding-left: 50px;
+}
+diff --git a/t/web/dashboards-basics.t b/t/web/dashboards-basics.t
+--- a/t/web/dashboards-basics.t
++++ b/t/web/dashboards-basics.t
+@@
+ use strict;
+ use warnings;
+
+-use RT::Test tests => 122;
++use RT::Test tests => 105;
+ my ($baseurl, $m) = RT::Test->started_ok;
+
+ my $url = $m->rt_base_url;
+@@
+ 'only dashboard queries show up' );
+ $m->content_contains("dashboard test", "ticket subject");
+
+-$m->get_ok("/Dashboards/Subscription.html?id=$id");
+-$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");
+-
+-$user_obj->Attributes->RedoSearch;
+-is($user_obj->Attributes->Named('Subscription'), 0, "no subscriptions");
+-
+-$user_obj->PrincipalObj->GrantRight(Right => 'SubscribeDashboard', Object => $RT::System);
+-
+-$m->get_ok("/Dashboards/Modify.html?id=$id");
+-$m->follow_link_ok({text => "Subscription"});
+-$m->content_contains("Subscribe to dashboard different dashboard");
+-$m->content_contains("Unowned Tickets");
+-$m->content_contains("My Tickets");
+-$m->content_unlike( qr/Bookmarked Tickets.*Bookmarked Tickets/s,
+- 'only dashboard queries show up' );
+-
+-$m->form_name('SubscribeDashboard');
+-$m->click_button(name => 'Save');
+-$m->content_lacks("Permission Denied");
+-$m->content_contains("Subscribed to dashboard different dashboard");
+-
+-$user_obj->Attributes->RedoSearch;
+-is($user_obj->Attributes->Named('Subscription'), 1, "we have a subscription");
+-
+-$m->get_ok("/Dashboards/Modify.html?id=$id");
+-$m->follow_link_ok({text => "Subscription"});
+-$m->content_contains("Modify the subscription to dashboard different dashboard");
+-
+ $m->get_ok("/Dashboards/Modify.html?id=$id&Delete=1");
+ $m->content_contains("Permission Denied", "unable to delete dashboard because we lack DeleteOwnDashboard");
+
+
+diff --git a/t/web/dashboards-subscription.t b/t/web/dashboards-subscription.t
+new file mode 100644
+--- /dev/null
++++ b/t/web/dashboards-subscription.t
+@@
++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 at 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 => 'home-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 at 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 at 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 at 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');
++
++# 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');
++
++undef $m;
++done_testing;
2: a198c0a < -: ------- move dashboard subscription tests into own test file and expand scope of tests
3: 00fbc49 < -: ------- incremental improvements
More information about the rt-commit
mailing list