[Rt-commit] rt branch, 4.4/dashboard-subscription-user-group, repushed
Dustin Graves
dustin at bestpractical.com
Fri Dec 4 12:52:19 EST 2015
The branch 4.4/dashboard-subscription-user-group was deleted and repushed:
was 757298d5f1712f2604557e830360bbc2f807769a
now c254ca57cab47152cb2b8949035707db0a89fe52
1: 757298d ! 1: c254ca5 change dashboard subscription recipient input to robust user/group search
@@ -12,6 +12,8 @@
+use strict;
+use warnings;
+
++use List::MoreUtils 'uniq';
++
+our @Initial = (
+ # migrate old Recipient field to new Recipients format
+ sub {
@@ -22,27 +24,37 @@
+ $attrs->Limit( FIELD => 'Name', VALUE => 'Subscription' );
+
+ while ( my $attr = $attrs->Next ) {
++ my %fields = ( Recipients => { Users => [], Groups => [] } );
++
+ my $recipient = $attr->SubValue('Recipient');
-+ next unless $recipient;
-+
-+ my %fields = ( Recipients => { Users => [], Groups => [] } );
-+
-+ foreach (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 @users;
++
++ 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);
++ }
++
++ push @users, $user->id;
+ }
-+
-+ push @{ $fields{Recipients}->{Users} }, $user->id unless grep { $_ == $user->id } @{ $fields{Recipients}->{Users} };
++ } else { # blank recipient represents dashboard creator subscription
++ push @users, $attr->ObjectId;
+ }
+
++ @{ $fields{Recipients}->{Users} } = uniq @users;
++
+ my ($ok, $msg) = $attr->SetSubValues(%fields);
-+ $RT::Logger->error("Couldn't update subscription: $msg") unless $ok;
++ unless ($ok) {
++ $RT::Logger->error("Couldn't update subscription: $msg");
++ $RT::Logger->error("Aborting dashboard subscription recipient migration");
++ exit;
++ }
+
+ ($ok, $msg) = $attr->DeleteSubValue('Recipient');
+ $RT::Logger->error("Couldn't delete Recipient field from subscription: $msg") unless $ok;
@@ -261,8 +273,8 @@
+% if ($Users) {
+% while (my $u = $Users->Next ) {
+<li>
-+<input type="checkbox" class="checkbox" name="Dashboard-Subscription-User-<%$u->id%>" value="1" />
-+<input type="hidden" name="Dashboard-Subscription-User-<%$u->id%>" value="0" />
++<input type="checkbox" class="checkbox" name="Dashboard-Subscription-Users-<%$u->id%>" value="1" />
++<input type="hidden" name="Dashboard-Subscription-Users-<%$u->id%>" value="0" />
+<& '/Elements/ShowUser', User => $u, style=>'verbose' &>
+% }
+% }
@@ -270,8 +282,8 @@
+% if ($Groups) {
+% while (my $g = $Groups->Next ) {
+<li>
-+<input type="checkbox" class="checkbox" name="Dashboard-Subscription-Group-<%$g->id%>" value="1" />
-+<input type="hidden" name="Dashboard-Subscription-Group-<%$g->id%>" value="0" />
++<input type="checkbox" class="checkbox" name="Dashboard-Subscription-Groups-<%$g->id%>" value="1" />
++<input type="hidden" name="Dashboard-Subscription-Groups-<%$g->id%>" value="0" />
+<%$g->Name%> (<%$g->Description%>)
+</li>
+% }
@@ -293,8 +305,8 @@
+% my $current_user_id = $session{CurrentUser}->id;
+% my $current_user_subscribed = $recipients_users && grep { $_ == $current_user_id } @$recipients_users;
+<li>
-+<input type="checkbox" class="checkbox" name="Dashboard-Subscription-User-<%$current_user_id%>" value="1" <% $current_user_subscribed || $IsFirstSubscription ? 'checked' : '' %> />
-+<input type="hidden" name="Dashboard-Subscription-User-<%$current_user_id%>" value="0" />
++<input type="checkbox" class="checkbox" name="Dashboard-Subscription-Users-<%$current_user_id%>" value="1" <% $current_user_subscribed || $IsFirstSubscription ? 'checked' : '' %> />
++<input type="hidden" name="Dashboard-Subscription-Users-<%$current_user_id%>" value="0" />
+% if ( $session{CurrentUser}->HasRight( Right => 'AdminUsers', Object => $RT::System ) &&
+% $session{CurrentUser}->HasRight( Right => 'ShowConfigTab', Object =>$RT::System ) ) {
+<a href="<% RT->Config->Get('WebPath') %>/Admin/Users/Modify.html?id=<% $current_user_id %>">
@@ -311,8 +323,8 @@
+% $user->Load($user_id);
+% next unless $user->id;
+<li>
-+<input type="checkbox" class="checkbox" name="Dashboard-Subscription-User-<%$user_id%>" value="1" checked />
-+<input type="hidden" name="Dashboard-Subscription-User-<%$user_id%>" value="0" />
++<input type="checkbox" class="checkbox" name="Dashboard-Subscription-Users-<%$user_id%>" value="1" checked />
++<input type="hidden" name="Dashboard-Subscription-Users-<%$user_id%>" value="0" />
+% if ( $session{CurrentUser}->HasRight( Right => 'AdminUsers', Object => $RT::System ) &&
+% $session{CurrentUser}->HasRight( Right => 'ShowConfigTab', Object =>$RT::System ) ) {
+<a href="<% RT->Config->Get('WebPath') %>/Admin/Users/Modify.html?id=<% $user_id %>">
@@ -329,8 +341,8 @@
+% $group->Load($group_id);
+% next unless $group->id;
+<li>
-+<input type="checkbox" class="checkbox" name="Dashboard-Subscription-Group-<%$group_id%>" value="1" checked />
-+<input type="hidden" name="Dashboard-Subscription-Group-<%$group_id%>" value="0" />
++<input type="checkbox" class="checkbox" name="Dashboard-Subscription-Groups-<%$group_id%>" value="1" checked />
++<input type="hidden" name="Dashboard-Subscription-Groups-<%$group_id%>" value="0" />
+
+
+% if ( $session{CurrentUser}->HasRight( Right => 'AdminGroup', Object => $RT::System ) &&
@@ -394,9 +406,9 @@
+# update recipients
+for my $key (keys %ARGS) {
-+ next unless $key =~ /^Dashboard-Subscription-(User|Group)-(\d+)$/;
-+
-+ my ($mode, $type, $id) = ('', $1.'s', $2);
++ 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' ?
@@ -430,10 +442,10 @@
+
+ if ($add_keep_recipient and not $is_prev_recipient) { # Add User/Group
+ push @recipients, $id;
-+ push @results, loc("$type [_1] added to dashboard subscription recipients.", $record->Name);
++ 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("$type [_1] removed from dashboard subscription recipients.", $record->Name);
++ push @results, loc("[_1] removed from dashboard subscription recipients.", $record->Name);
}
- if ($ok) {
More information about the rt-commit
mailing list