-# $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Group.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
-# Copyright 2000 Jesse Vincent <jesse@fsck.com>
-# Released under the terms of the GNU Public License
+# BEGIN BPS TAGGED BLOCK {{{
#
+# COPYRIGHT:
#
+# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+# <sales@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 }}}
+
+# Autogenerated by DBIx::SearchBuilder factory (by <jesse@bestpractical.com>)
+# WARNING: THIS FILE IS AUTOGENERATED. ALL CHANGES TO THIS FILE WILL BE LOST.
+#
+# !! DO NOT EDIT THIS FILE !!
+#
+
+use strict;
+
=head1 NAME
- RT::Group - RT\'s group object
+RT::Group
-=head1 SYNOPSIS
- use RT::Group;
-my $group = new RT::Group($CurrentUser);
+=head1 SYNOPSIS
=head1 DESCRIPTION
-An RT group object.
+=head1 METHODS
-=head1 AUTHOR
+=cut
-Jesse Vincent, jesse@fsck.com
+package RT::Group;
+use RT::Record;
-=head1 SEE ALSO
-RT
+use vars qw( @ISA );
+@ISA= qw( RT::Record );
-=head1 METHODS
+sub _Init {
+ my $self = shift;
+ $self->Table('Groups');
+ $self->SUPER::_Init(@_);
+}
-=begin testing
-ok (require RT::TestHarness);
-ok (require RT::Group);
-=end testing
-=cut
+=head2 Create PARAMHASH
-package RT::Group;
-use RT::Record;
-use RT::GroupMember;
-use RT::ACE;
+Create takes a hash of values and creates a row in the database:
+
+ varchar(200) 'Name'.
+ varchar(255) 'Description'.
+ varchar(64) 'Domain'.
+ varchar(64) 'Type'.
+ int(11) 'Instance'.
+
+=cut
-use vars qw|@ISA|;
-@ISA= qw(RT::Record);
-# {{{ sub _Init
-sub _Init {
- my $self = shift;
- $self->{'table'} = "Groups";
- return ($self->SUPER::_Init(@_));
-}
-# }}}
-# {{{ sub _Accessible
-sub _Accessible {
+sub Create {
my $self = shift;
- my %Cols = (
- Name => 'read/write',
- Description => 'read/write',
- Pseudo => 'read'
- );
- return $self->SUPER::_Accessible(@_, %Cols);
+ my %args = (
+ Name => '',
+ Description => '',
+ Domain => '',
+ Type => '',
+ Instance => '',
+
+ @_);
+ $self->SUPER::Create(
+ Name => $args{'Name'},
+ Description => $args{'Description'},
+ Domain => $args{'Domain'},
+ Type => $args{'Type'},
+ Instance => $args{'Instance'},
+);
+
}
-# }}}
-# {{{ sub Load
-=head2 Load
-Load a group object from the database. Takes a single argument.
-If the argument is numerical, load by the column 'id'. Otherwise, load by
-the "Name" column which is the group's textual name
+=head2 id
-=cut
+Returns the current value of id.
+(In the database, id is stored as int(11).)
-sub Load {
- my $self = shift;
- my $identifier = shift || return undef;
-
- #if it's an int, load by id. otherwise, load by name.
- if ($identifier !~ /\D/) {
- $self->SUPER::LoadById($identifier);
- }
- else {
- $self->LoadByCol("Name",$identifier);
- }
-}
-# }}}
+=cut
-# {{{ sub Create
-=head2 Create
+=head2 Name
-Takes a paramhash with three named arguments: Name, Description and Pseudo.
-Pseudo is used internally by RT for certain special ACL decisions.
+Returns the current value of Name.
+(In the database, Name is stored as varchar(200).)
-=cut
-sub Create {
- my $self = shift;
- my %args = ( Name => undef,
- Description => undef,
- Pseudo => 0,
- @_);
-
- unless ($self->CurrentUser->HasSystemRight('AdminGroups')) {
- $RT::Logger->warning($self->CurrentUser->Name ." Tried to create a group without permission.");
- return(0, 'Permission Denied');
- }
-
- my $retval = $self->SUPER::Create(Name => $args{'Name'},
- Description => $args{'Description'},
- Pseudo => $args{'Pseudo'});
-
- return ($retval);
-}
-# }}}
+=head2 SetName VALUE
-# {{{ sub Delete
-=head2 Delete
+Set Name to VALUE.
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, Name will be stored as a varchar(200).)
-Delete this object
=cut
-sub Delete {
- my $self = shift;
-
- unless ($self->CurrentUser->HasSystemRight('AdminGroups')) {
- return (0, 'Permission Denied');
- }
-
- return($self->SUPER::Delete(@_));
-}
-# }}}
+=head2 Description
-# {{{ MembersObj
+Returns the current value of Description.
+(In the database, Description is stored as varchar(255).)
-=head2 MembersObj
-Returns an RT::GroupMembers object of this group's members.
-=cut
+=head2 SetDescription VALUE
-sub MembersObj {
- my $self = shift;
- unless (defined $self->{'members_obj'}) {
- use RT::GroupMembers;
- $self->{'members_obj'} = new RT::GroupMembers($self->CurrentUser);
-
- #If we don't have rights, don't include any results
- $self->{'members_obj'}->LimitToGroup($self->id);
-
- }
- return ($self->{'members_obj'});
-
-}
-# }}}
+Set Description to VALUE.
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, Description will be stored as a varchar(255).)
-# {{{ AddMember
-=head2 AddMember
+=cut
-AddMember adds a user to this group. It takes a user id.
-Returns a two value array. the first value is true on successful
-addition or 0 on failure. The second value is a textual status msg.
-=cut
+=head2 Domain
+
+Returns the current value of Domain.
+(In the database, Domain is stored as varchar(64).)
-sub AddMember {
- my $self = shift;
- my $new_member = shift;
-
- my $new_member_obj = new RT::User($self->CurrentUser);
- $new_member_obj->Load($new_member);
-
- unless ($self->CurrentUser->HasSystemRight('AdminGroups')) {
- #User has no permission to be doing this
- return(0, "Permission Denied");
- }
-
- unless ($new_member_obj->Id) {
- $RT::Logger->debug("Couldn't find user $new_member");
- return(0, "Couldn't find user");
- }
-
- if ($self->HasMember($new_member_obj->Id)) {
- #User is already a member of this group. no need to add it
- return(0, "Group already has member");
- }
-
- my $member_object = new RT::GroupMember($self->CurrentUser);
- $member_object->Create( UserId => $new_member_obj->Id,
- GroupId => $self->id );
- return(1, "Member added");
-}
-# }}}
-# {{{ HasMember
+=head2 SetDomain VALUE
-=head2 HasMember
-Takes a user Id and returns a GroupMember Id if that user is a member of
-this group.
-Returns undef if the user isn't a member of the group or if the current
-user doesn't have permission to find out. Arguably, it should differentiate
-between ACL failure and non membership.
+Set Domain to VALUE.
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, Domain will be stored as a varchar(64).)
+
=cut
-sub HasMember {
- my $self = shift;
- my $user_id = shift;
- #Try to cons up a member object using "LoadByCols"
+=head2 Type
- my $member_obj = new RT::GroupMember($self->CurrentUser);
- $member_obj->LoadByCols( UserId => $user_id, GroupId => $self->id);
+Returns the current value of Type.
+(In the database, Type is stored as varchar(64).)
- #If we have a member object
- if (defined $member_obj->id) {
- return ($member_obj->id);
- }
- #If Load returns no objects, we have an undef id.
- else {
- return(undef);
- }
-}
-# }}}
+=head2 SetType VALUE
-# {{{ DeleteMember
-=head2 DeleteMember
+Set Type to VALUE.
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, Type will be stored as a varchar(64).)
-Takes the user id of a member.
-If the current user has apropriate rights,
-removes that GroupMember from this group.
-Returns a two value array. the first value is true on successful
-addition or 0 on failure. The second value is a textual status msg.
=cut
-sub DeleteMember {
- my $self = shift;
- my $member = shift;
-
- unless ($self->CurrentUser->HasSystemRight('AdminGroups')) {
- #User has no permission to be doing this
- return(0,"Permission Denied");
- }
-
- my $member_user_obj = new RT::User($self->CurrentUser);
- $member_user_obj->Load($member);
-
- unless ($member_user_obj->Id) {
- $RT::Logger->debug("Couldn't find user $member");
- return(0, "User not found");
- }
-
- my $member_obj = new RT::GroupMember($self->CurrentUser);
- unless ($member_obj->LoadByCols ( UserId => $member_user_obj->Id,
- GroupId => $self->Id )) {
- return(0, "Couldn\'t load member"); #couldn\'t load member object
- }
-
- #If we couldn't load it, return undef.
- unless ($member_obj->Id()) {
- return (0, "Group has no such member");
- }
-
- #Now that we've checked ACLs and sanity, delete the groupmember
- my $val = $member_obj->Delete();
- if ($val) {
- return ($val, "Member deleted");
- }
- else {
- return (0, "Member not deleted");
- }
-}
-# }}}
+=head2 Instance
+
+Returns the current value of Instance.
+(In the database, Instance is stored as int(11).)
+
-# {{{ ACL Related routines
-# {{{ GrantQueueRight
+=head2 SetInstance VALUE
-=head2 GrantQueueRight
-Grant a queue right to this group. Takes a paramhash of which the elements
-RightAppliesTo and RightName are important.
+Set Instance to VALUE.
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, Instance will be stored as a int(11).)
+
=cut
-sub GrantQueueRight {
-
- my $self = shift;
- my %args = ( RightScope => 'Queue',
- RightName => undef,
- RightAppliesTo => undef,
- PrincipalType => 'Group',
- PrincipalId => $self->Id,
- @_);
-
- #ACLs get checked in ACE.pm
-
- my $ace = new RT::ACE($self->CurrentUser);
-
- return ($ace->Create(%args));
-}
-# }}}
-# {{{ GrantSystemRight
+sub _CoreAccessible {
+ {
+
+ id =>
+ {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
+ Name =>
+ {read => 1, write => 1, sql_type => 12, length => 200, is_blob => 0, is_numeric => 0, type => 'varchar(200)', default => ''},
+ Description =>
+ {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
+ Domain =>
+ {read => 1, write => 1, sql_type => 12, length => 64, is_blob => 0, is_numeric => 0, type => 'varchar(64)', default => ''},
+ Type =>
+ {read => 1, write => 1, sql_type => 12, length => 64, is_blob => 0, is_numeric => 0, type => 'varchar(64)', default => ''},
+ Instance =>
+ {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
-=head2 GrantSystemRight
+ }
+};
-Grant a system right to this group.
-The only element that's important to set is RightName.
+RT::Base->_ImportOverlays();
-=cut
-sub GrantSystemRight {
-
- my $self = shift;
- my %args = ( RightScope => 'System',
- RightName => undef,
- RightAppliesTo => 0,
- PrincipalType => 'Group',
- PrincipalId => $self->Id,
- @_);
-
- # ACLS get checked in ACE.pm
-
- my $ace = new RT::ACE($self->CurrentUser);
- return ($ace->Create(%args));
-}
+=head1 SEE ALSO
+This class allows "overlay" methods to be placed
+into the following files _Overlay is for a System overlay by the original author,
+_Vendor is for 3rd-party vendor add-ons, while _Local is for site-local customizations.
-# }}}
+These overlay files can contain new subs or subs to replace existing subs in this module.
+Each of these files should begin with the line
-# {{{ sub _Set
-sub _Set {
- my $self = shift;
+ no warnings qw(redefine);
- unless ($self->CurrentUser->HasSystemRight('AdminGroups')) {
- return (0, 'Permission Denied');
- }
+so that perl does not kick and scream when you redefine a subroutine or variable in your overlay.
- return ($self->SUPER::_Set(@_));
+RT::Group_Overlay, RT::Group_Vendor, RT::Group_Local
-}
-# }}}
+=cut
+
+
+1;