GroupMembers.pm 4.16 KB
Newer Older
1
# BEGIN BPS TAGGED BLOCK {{{
Jesse Vincent's avatar
Jesse Vincent committed
2
#
3
# COPYRIGHT:
Jesse Vincent's avatar
Jesse Vincent committed
4
#
5
# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
Kevin Falcone's avatar
Kevin Falcone committed
6
#                                          <sales@bestpractical.com>
Jesse Vincent's avatar
Jesse Vincent committed
7
#
8
# (Except where explicitly superseded by other copyright notices)
Jesse Vincent's avatar
Jesse Vincent committed
9
10
#
#
11
# LICENSE:
Jesse Vincent's avatar
Jesse Vincent committed
12
#
13
14
15
# 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
16
# from www.gnu.org.
Jesse Vincent's avatar
Jesse Vincent committed
17
#
18
19
20
21
# 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.
Jesse Vincent's avatar
Jesse Vincent committed
22
#
23
24
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
Jesse Vincent's avatar
Jesse Vincent committed
25
26
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 or visit their web page on the internet at
Ruslan Zakirov's avatar
Ruslan Zakirov committed
27
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
Jesse Vincent's avatar
Jesse Vincent committed
28
29
#
#
30
# CONTRIBUTION SUBMISSION POLICY:
Jesse Vincent's avatar
Jesse Vincent committed
31
#
32
33
34
35
36
# (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.)
Jesse Vincent's avatar
Jesse Vincent committed
37
#
38
39
40
41
42
43
44
45
# 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.
Jesse Vincent's avatar
Jesse Vincent committed
46
#
47
# END BPS TAGGED BLOCK }}}
48

Jesse Vincent's avatar
rt.2.1  
Jesse Vincent committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
=head1 NAME

  RT::GroupMembers - a collection of RT::GroupMember objects

=head1 SYNOPSIS

  use RT::GroupMembers;

=head1 DESCRIPTION


=head1 METHODS



=cut

66
67
68

package RT::GroupMembers;

69
use strict;
70
71
use warnings;

72
73
use base 'RT::SearchBuilder';

74
75
use RT::GroupMember;

76
77
sub Table { 'GroupMembers'}

Jesse Vincent's avatar
rt.2.1  
Jesse Vincent committed
78

Jesse Vincent's avatar
Jesse Vincent committed
79
80
81

=head2 LimitToUsers

82
Limits this search object to users who are members of this group.
83
This is really useful when you want to have your UI separate out
84
groups from users for display purposes
Jesse Vincent's avatar
Jesse Vincent committed
85
86
87
88
89
90
91
92

=cut

sub LimitToUsers {
    my $self = shift;

    my $principals = $self->NewAlias('Principals');
    $self->Join( ALIAS1 => 'main', FIELD1 => 'MemberId',
93
                 ALIAS2 => $principals, FIELD2 =>'id');
Jesse Vincent's avatar
Jesse Vincent committed
94
95
96
97
98
99
100
101
102
103
104

    $self->Limit(       ALIAS => $principals,
                         FIELD => 'PrincipalType',
                         VALUE => 'User',
                         ENTRYAGGREGATOR => 'OR',
                         );
}




105
=head2 LimitToGroups
Jesse Vincent's avatar
Jesse Vincent committed
106

107
Limits this search object to Groups who are members of this group.
108
This is really useful when you want to have your UI separate out
109
groups from users for display purposes
Jesse Vincent's avatar
Jesse Vincent committed
110
111
112

=cut

113
sub LimitToGroups {
Jesse Vincent's avatar
Jesse Vincent committed
114
115
116
117
    my $self = shift;

    my $principals = $self->NewAlias('Principals');
    $self->Join( ALIAS1 => 'main', FIELD1 => 'MemberId',
118
                 ALIAS2 => $principals, FIELD2 =>'id');
Jesse Vincent's avatar
Jesse Vincent committed
119
120
121
122
123
124
125
126

    $self->Limit(       ALIAS => $principals,
                         FIELD => 'PrincipalType',
                         VALUE => 'Group',
                         ENTRYAGGREGATOR => 'OR',
                         );
}

Jesse Vincent's avatar
rt.2.1  
Jesse Vincent committed
127
128


129
=head2 LimitToMembersOfGroup PRINCIPAL_ID
Jesse Vincent's avatar
rt.2.1  
Jesse Vincent committed
130

131
132
133
Takes a Principal Id as its only argument. 
Limits the current search principals which are _directly_ members
of the group which has PRINCIPAL_ID as its principal id.
Jesse Vincent's avatar
rt.2.1  
Jesse Vincent committed
134
135
136

=cut

137
sub LimitToMembersOfGroup {
Jesse Vincent's avatar
rt.2.1  
Jesse Vincent committed
138
139
140
141
    my $self = shift;
    my $group = shift;

    return ($self->Limit( 
142
                         VALUE => $group,
Jesse Vincent's avatar
rt.2.1  
Jesse Vincent committed
143
144
                         FIELD => 'GroupId',
                         ENTRYAGGREGATOR => 'OR',
145
			             QUOTEVALUE => 0
Jesse Vincent's avatar
rt.2.1  
Jesse Vincent committed
146
147
148
149
                         ));

}

150
151
152
153
154
155
156
157
158
159
160
161
162
163


=head2 NewItem

Returns an empty new RT::GroupMember item

=cut

sub NewItem {
    my $self = shift;
    return(RT::GroupMember->new($self->CurrentUser));
}
RT::Base->_ImportOverlays();

Jesse Vincent's avatar
rt.2.1  
Jesse Vincent committed
164
1;