[Rt-commit] rt branch, 4.4/dashboard-subscription-user-group, updated. rt-4.4.0rc2-18-gbee35c2
Dustin Graves
dustin at bestpractical.com
Thu Dec 10 19:09:22 EST 2015
The branch, 4.4/dashboard-subscription-user-group has been updated
via bee35c2109882a7c5f2db4d602781558f16c9c43 (commit)
from a198c0a31bccaedf2254b276df0309918eaa5714 (commit)
Summary of changes:
etc/upgrade/4.4.1/content | 14 ++--
.../Dashboards/Elements/SubscriptionRecipients | 41 +++++----
share/html/Dashboards/Subscription.html | 96 +++++++++++++---------
3 files changed, 92 insertions(+), 59 deletions(-)
- Log -----------------------------------------------------------------
commit bee35c2109882a7c5f2db4d602781558f16c9c43
Author: Dustin Graves <dustin at bestpractical.com>
Date: Fri Dec 11 00:01:13 2015 +0000
addressing client feedback
diff --git a/etc/upgrade/4.4.1/content b/etc/upgrade/4.4.1/content
index 62cb087..0226993 100644
--- a/etc/upgrade/4.4.1/content
+++ b/etc/upgrade/4.4.1/content
@@ -20,15 +20,13 @@ our @Initial = (
if ($recipient) {
for ( RT::EmailParser->ParseEmailAddress($recipient) ) {
- my $addr = $_->address;
+ my ( $email, $name ) = ( $_->address, $_->name );
- 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);
- }
+ $user->LoadOrCreateByEmail(
+ EmailAddress => $email,
+ RealName => $name,
+ Comments => 'Autocreated when added as a dashboard subscription recipient',
+ );
push @users, $user->id;
}
diff --git a/share/html/Dashboards/Elements/SubscriptionRecipients b/share/html/Dashboards/Elements/SubscriptionRecipients
index 309fb12..8134912 100644
--- a/share/html/Dashboards/Elements/SubscriptionRecipients
+++ b/share/html/Dashboards/Elements/SubscriptionRecipients
@@ -114,36 +114,49 @@ if ($GroupString) {
</tr>
</table>
-% if ($UserString || $GroupString) {
-<strong><&|/l&>Search Results</&>:</strong>
-<ul>
+<strong><&|/l&>Add New Recipients</&>:</strong>
+<table>
-% if ($Users) {
-% while (my $u = $Users->Next ) {
-<li>
+% 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' &>
+</td></tr>
% }
% }
-% if ($Groups) {
-% while (my $g = $Groups->Next ) {
-<li>
+% 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>
+</td></tr>
% }
% }
-% unless (($Users && $Users->Count) || ($Groups && $Groups->Count)) {
-<li><i><&|/l&>none</&></i></li>
-% }
+<tr><td></td><td>
+<&|/l&>Email</&>
+</tr></td>
-</ul>
+% 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">
diff --git a/share/html/Dashboards/Subscription.html b/share/html/Dashboards/Subscription.html
index 72f1119..bc6ea7f 100644
--- a/share/html/Dashboards/Subscription.html
+++ b/share/html/Dashboards/Subscription.html
@@ -196,6 +196,7 @@
</form>
<%INIT>
+use List::MoreUtils 'uniq';
my ($title, @results);
my $Loaded = 0;
@@ -243,45 +244,66 @@ for my $field (keys %fields) {
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;
- }
-
- 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);
- }
-
- use List::MoreUtils 'uniq';
- @{ $fields{Recipients}->{$type} } = uniq @recipients;
-}
-
# this'll be defined on submit
if (defined $ARGS{Save}) {
+ # 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;
+ }
+ }
+
# update
if ($SubscriptionObj) {
$id = delete $fields{'DashboardId'}; # immutable
-----------------------------------------------------------------------
More information about the rt-commit
mailing list