[Rt-commit] rt branch, 4.2/dont-recurse-groups-in-role-columnmap, updated. rt-4.1.8-564-g463f774

Alex Vandiver alexmv at bestpractical.com
Thu Jun 13 16:42:38 EDT 2013


The branch, 4.2/dont-recurse-groups-in-role-columnmap has been updated
       via  463f7749db69d5d6dd9f53c4eda6bd7180d129eb (commit)
       via  be9000f4ce2e3f4f2e2f5d53fecbd8856c872718 (commit)
       via  83d3e915ed4d4ef502ef484ebda72b51b1ac105d (commit)
       via  ab0ff3555c9e17ac519961bcf3fd539be2f5b42f (commit)
       via  0d42c22a6c2a58eb718eeeb067900d70c7cf3c4a (commit)
      from  740704a3a64d619c266d9b790b259cf50fbf9d31 (commit)

Summary of changes:
 lib/RT/Record/Role/Roles.pm                        | 20 ++++++---
 lib/RT/Ticket.pm                                   | 18 ++++----
 share/html/Elements/ColumnMap                      | 19 ++++++++
 share/html/Elements/RT__Ticket/ColumnMap           | 50 ++--------------------
 .../ShowGroupMembers => Elements/ShowPrincipal}    | 38 ++++++++--------
 share/html/Ticket/Elements/ShowGroupMembers        | 23 ++++------
 6 files changed, 75 insertions(+), 93 deletions(-)
 copy share/html/{Ticket/Elements/ShowGroupMembers => Elements/ShowPrincipal} (73%)

- Log -----------------------------------------------------------------
commit 0d42c22a6c2a58eb718eeeb067900d70c7cf3c4a
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Jun 13 16:06:57 2013 -0400

    Ensure that RT::Ticket has a method for every role group
    
    Roles are in the singular declension; thus support and encourage
    ->Requestor for consistency.

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index bcfcfcbe..2bbc861 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -851,20 +851,25 @@ sub CcAddresses {
 
 
 
-=head2 Requestors
+=head2 Requestor
 
 Takes nothing.
 Returns this ticket's Requestors as an RT::Group object
 
 =cut
 
-sub Requestors {
+sub Requestor {
     my $self = shift;
     return RT::Group->new($self->CurrentUser)
         unless $self->CurrentUserHasRight('ShowTicket');
     return $self->RoleGroup( 'Requestor' );
 }
 
+sub Requestors {
+    my $self = shift;
+    return $self->Requestor;
+}
+
 
 
 =head2 Cc

commit ab0ff3555c9e17ac519961bcf3fd539be2f5b42f
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Jun 13 16:07:49 2013 -0400

    Allow RoleGroup to apply an ACL before returning a loaded Group
    
    This turns ->AdminCc and friends into simple wrappers around the
    respective RoleGroup methods, so they can be used interchancably.  This
    nudges tickets slightly closer to being able to have configurable role
    groups.

diff --git a/lib/RT/Record/Role/Roles.pm b/lib/RT/Record/Role/Roles.pm
index 31692f5..eb35b7a 100644
--- a/lib/RT/Record/Role/Roles.pm
+++ b/lib/RT/Record/Role/Roles.pm
@@ -129,6 +129,12 @@ Optional.  A numeric value indicating the position of this role when sorted
 ascending with other roles in a list.  Roles with the same sort order are
 ordered alphabetically by name within themselves.
 
+=item RequiresACL
+
+Optional.  The name of the right the current user of the object must
+have to see the members of the group.  If this right is not met,
+L</RoleGroup> will return an unloaded group.  Defaults to no right.
+
 =back
 
 =cut
@@ -296,11 +302,15 @@ sub RoleGroup {
     my $name  = shift;
     my $group = RT::Group->new( $self->CurrentUser );
 
-    if ($self->HasRole($name)) {
-        $group->LoadRoleGroup(
-            Object  => $self,
-            Name    => $name,
-        );
+    my $role = $self->Role($name);
+    if ($role) {
+        my $right = $role->{RequiresACL};
+        if (not $right or $self->CurrentUserHasRight( $right ) ) {
+            $group->LoadRoleGroup(
+                Object  => $self,
+                Name    => $name,
+            );
+        }
     }
     return $group;
 }
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 2bbc861..416669b 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -107,6 +107,7 @@ for my $role (sort keys %ROLES) {
     RT::Ticket->RegisterRole(
         Name            => $role,
         EquivClasses    => ['RT::Queue'],
+        RequiresACL     => 'ShowTicket',
         ( $role eq "Owner" ? ( Column => "Owner")   : () ),
         ( $role !~ /Cc/    ? ( ACLOnlyInEquiv => 1) : () ),
     );
@@ -860,8 +861,6 @@ Returns this ticket's Requestors as an RT::Group object
 
 sub Requestor {
     my $self = shift;
-    return RT::Group->new($self->CurrentUser)
-        unless $self->CurrentUserHasRight('ShowTicket');
     return $self->RoleGroup( 'Requestor' );
 }
 
@@ -882,9 +881,6 @@ If the user doesn't have "ShowTicket" permission, returns an empty group
 
 sub Cc {
     my $self = shift;
-
-    return RT::Group->new($self->CurrentUser)
-        unless $self->CurrentUserHasRight('ShowTicket');
     return $self->RoleGroup( 'Cc' );
 }
 
@@ -900,9 +896,6 @@ If the user doesn't have "ShowTicket" permission, returns an empty group
 
 sub AdminCc {
     my $self = shift;
-
-    return RT::Group->new($self->CurrentUser)
-        unless $self->CurrentUserHasRight('ShowTicket');
     return $self->RoleGroup( 'AdminCc' );
 }
 

commit 83d3e915ed4d4ef502ef484ebda72b51b1ac105d
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Jun 13 16:14:10 2013 -0400

    Move $linkUsers into an element so it can be used externally
    
    Multiple locations, particularly where role groups are involved, may
    wish to enumerate and link group and user contents.

diff --git a/share/html/Elements/RT__Ticket/ColumnMap b/share/html/Elements/RT__Ticket/ColumnMap
index 6d930d1..8d33c5d 100644
--- a/share/html/Elements/RT__Ticket/ColumnMap
+++ b/share/html/Elements/RT__Ticket/ColumnMap
@@ -81,36 +81,14 @@ my $LinkCallback = sub {
     }
 };
 
-my $linkUsers;
-$linkUsers = sub {
-    my ($what, $more) = @_;
-    if ($what->isa("RT::Group")) {
-        # Link the users (non-recursively)
-        my @ret = map {$linkUsers->($_->[1], $more), ", "}
-            sort {$a->[0] cmp $b->[0]}
-            map {+[($_->EmailAddress||''), $_]}
-            @{ $what->UserMembersObj( Recursively => 0 )->ItemsArrayRef };
-
-        # But don't link the groups
-        push @ret, map {+("Group: $_", ",")}
-            sort map {$_->Name} @{ $what->GroupMembersObj( Recursively => 0)->ItemsArrayRef };
-
-        pop @ret; # Remove ending ", "
-        return @ret;
-    } else {
-        my @ret = \($m->scomp("/Elements/ShowUser", User => $what));
-        push @ret, $more->($what) if $more;
-        return @ret;
-    }
-};
 my $trustSub = sub {
     my $user = shift;
     require RT::Crypt::GnuPG;
     my %key = RT::Crypt::GnuPG::GetKeyInfo($user->EmailAddress);
     if (!defined $key{'info'}) {
-        return ' ' . loc("(no pubkey!)");
+        return $m->interp->apply_escapes(' ' . loc("(no pubkey!)"), "h");
     } elsif ($key{'info'}{'TrustLevel'} == 0) {
-        return ' ' . loc("(untrusted!)");
+        return $m->interp->apply_escapes(' ' . loc("(untrusted!)"), "h");
     }
 };
 
@@ -133,7 +111,7 @@ $COLUMN_MAP = {
     Owner => {
         title     => 'Owner', # loc
         attribute => 'Owner',
-        value     => sub { return $linkUsers->($_[0]->OwnerObj) }
+        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->OwnerObj ) ) }
     },
     Status => {
         title     => 'Status', # loc
@@ -217,17 +195,17 @@ $COLUMN_MAP = {
     Requestors => {
         title     => 'Requestors', # loc
         attribute => 'Requestor.EmailAddress',
-        value     => sub { return $linkUsers->( $_[0]->Requestors ) }
+        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->Requestor ) ) }
     },
     Cc => {
         title     => 'Cc', # loc
         attribute => 'Cc.EmailAddress',
-        value     => sub { return $linkUsers->( $_[0]->Cc ) }
+        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->Cc ) ) }
     },
     AdminCc => {
         title     => 'AdminCc', # loc
         attribute => 'AdminCc.EmailAddress',
-        value     => sub { return $linkUsers->( $_[0]->AdminCc ) }
+        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->AdminCc ) ) }
     },
     StartsRelative => {
         title     => 'Starts', # loc
@@ -299,7 +277,7 @@ $COLUMN_MAP = {
     KeyRequestors => {
         title     => 'Requestors', # loc
         attribute => 'Requestor.EmailAddress',
-        value     => sub { return $linkUsers->($_[0]->Requestors, $trustSub); }
+        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->RoleGroup("Requestor"), PostUser => $trustSub ) ) }
     },
     KeyOwnerName => {
         title     => 'Owner', # loc
@@ -321,7 +299,7 @@ $COLUMN_MAP = {
     KeyOwner => {
         title     => 'Owner', # loc
         attribute => 'Owner',
-        value     => sub { return $linkUsers->($_[0]->OwnerObj, $trustSub); }
+        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->RoleGroup("Owner"), PostUser => $trustSub ) ) }
     },
 
     # Everything from LINKTYPEMAP
diff --git a/share/html/Elements/ShowPrincipal b/share/html/Elements/ShowPrincipal
new file mode 100644
index 0000000..b8e7ddd
--- /dev/null
+++ b/share/html/Elements/ShowPrincipal
@@ -0,0 +1,71 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
+%#                                          <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+%# Released under the terms of version 2 of the GNU Public License
+<%args>
+$Object
+$PostUser => undef
+$Separator => ", "
+</%args>
+<%init>
+if ($Object->isa("RT::Group")) {
+    # Link the users (non-recursively)
+    my @ret = map {$m->scomp("ShowPrincipal", Object => $_->[1], PostUser => $PostUser)}
+        sort {$a->[0] cmp $b->[0]}
+        map {+[($_->EmailAddress||''), $_]}
+        @{ $Object->UserMembersObj( Recursively => 0 )->ItemsArrayRef };
+
+    # But don't link the groups
+    push @ret, sort map {$m->interp->apply_escapes( loc("Group: [_1]", $_->Name), 'h' )}
+        @{ $Object->GroupMembersObj( Recursively => 0)->ItemsArrayRef };
+
+    $m->out( join($Separator, @ret) );
+} else {
+    $m->comp("/Elements/ShowUser", User => $Object);
+    $m->out( $PostUser->($Object) ) if $PostUser;
+}
+</%init>

commit be9000f4ce2e3f4f2e2f5d53fecbd8856c872718
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Jun 13 16:14:26 2013 -0400

    Add role groups to ColumnMap computationally
    
    If a class ColumnMap does not explicitly define handlers for its role
    groups, compute and display them computationally.  Unfortunately, $Class
    is already in the form RT__Ticket and not RT::Ticket, and thus must be
    computationally transformed back.

diff --git a/share/html/Elements/ColumnMap b/share/html/Elements/ColumnMap
index 01ba3ab..c5f9f26 100644
--- a/share/html/Elements/ColumnMap
+++ b/share/html/Elements/ColumnMap
@@ -213,6 +213,25 @@ if (RT::Interface::Web->ComponentPathIsSafe($Class) and $m->comp_exists("/Elemen
     my $class_map = $m->comp("/Elements/$Class/ColumnMap", Attr => $Attr, Name => $Name, GenericMap => $COLUMN_MAP );
     return $class_map if defined $class_map;
 }
+
+# Check for roles, if not handled already
+$Class =~ s/_/:/g;
+if ($Class->DOES("RT::Record::Role::Roles")) {
+    my $ROLE_MAP = {};
+    for my $role ($Class->Roles) {
+        my $attrs = $Class->Role($role);
+        $ROLE_MAP->{$role} = {
+            title => $role,
+            attribute => $attrs->{Column} || "$role.EmailAddress",
+            value => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->RoleGroup($role) ) ) },
+        };
+        $ROLE_MAP->{$role . "s"} = $ROLE_MAP->{$role}
+            unless $attrs->{Single};
+    }
+    my $role_entry = GetColumnMapEntry( Map => $ROLE_MAP, Name => $Name, Attribute => $Attr );
+    return $role_entry if defined $role_entry;
+}
+
 return GetColumnMapEntry( Map => $COLUMN_MAP, Name => $Name, Attribute => $Attr );
 
 </%INIT>
diff --git a/share/html/Elements/RT__Ticket/ColumnMap b/share/html/Elements/RT__Ticket/ColumnMap
index 8d33c5d..dcd6a9b 100644
--- a/share/html/Elements/RT__Ticket/ColumnMap
+++ b/share/html/Elements/RT__Ticket/ColumnMap
@@ -108,11 +108,6 @@ $COLUMN_MAP = {
         attribute => 'Owner',
         value     => sub { return $_[0]->OwnerObj->Name }
     },
-    Owner => {
-        title     => 'Owner', # loc
-        attribute => 'Owner',
-        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->OwnerObj ) ) }
-    },
     Status => {
         title     => 'Status', # loc
         attribute => 'Status',
@@ -192,21 +187,6 @@ $COLUMN_MAP = {
         title     => 'Time Estimated', # loc
         value     => sub { return $_[0]->TimeEstimated }
     },
-    Requestors => {
-        title     => 'Requestors', # loc
-        attribute => 'Requestor.EmailAddress',
-        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->Requestor ) ) }
-    },
-    Cc => {
-        title     => 'Cc', # loc
-        attribute => 'Cc.EmailAddress',
-        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->Cc ) ) }
-    },
-    AdminCc => {
-        title     => 'AdminCc', # loc
-        attribute => 'AdminCc.EmailAddress',
-        value     => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->AdminCc ) ) }
-    },
     StartsRelative => {
         title     => 'Starts', # loc
         attribute => 'Starts',

commit 463f7749db69d5d6dd9f53c4eda6bd7180d129eb
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Jun 13 16:03:00 2013 -0400

    Move ShowGroupMembers to new ShowPrincipal method
    
    Both accomplish identical purposes; happily ShowPrincipal gives
    sufficient rope to re-implement ShowGroupMembers.

diff --git a/share/html/Ticket/Elements/ShowGroupMembers b/share/html/Ticket/Elements/ShowGroupMembers
index 046a433..c2e1a1e 100644
--- a/share/html/Ticket/Elements/ShowGroupMembers
+++ b/share/html/Ticket/Elements/ShowGroupMembers
@@ -46,22 +46,15 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 %# Released under the terms of version 2 of the GNU Public License
-
-% my $Users = $Group->UserMembersObj( Recursively => $Recursively );
-% while ( my $user = $Users->Next ) {
-<& /Elements/ShowUser, User => $user, Ticket => $Ticket &>
-<& /Elements/ShowUserEmailFrequency, User => $user, Ticket => $Ticket &>
-% $m->callback( User => $user, Ticket => $Ticket, %ARGS, CallbackName => 'AboutThisUser' );
-<br />
-% }
-% my $Groups = $Group->GroupMembersObj( Recursively => $Recursively );
-% $Groups->LimitToUserDefinedGroups;
-% while (my $group = $Groups->Next) {
-<&|/l&>Group</&>: <% $group->Name %><br />
-% }
-
+<%init>
+my $post_user = sub {
+    my $user = shift;
+    $m->comp("/Elements/ShowUserEmailFrequency", User => $user, Ticket => $Ticket);
+    $m->callback( User => $user, Ticket => $Ticket, %ARGS, CallbackName => 'AboutThisUser' );
+};
+$m->comp("/Elements/ShowPrincipal", Object => $Group, Separator => "<br />", PostUser => $post_user);
+</%init>
 <%ARGS>
 $Group       => undef
-$Recursively => 0,
 $Ticket      => undef
 </%ARGS>

-----------------------------------------------------------------------


More information about the Rt-commit mailing list