summaryrefslogtreecommitdiff
path: root/rt/lib/RT/Attributes.pm
diff options
context:
space:
mode:
Diffstat (limited to 'rt/lib/RT/Attributes.pm')
-rw-r--r--rt/lib/RT/Attributes.pm177
1 files changed, 143 insertions, 34 deletions
diff --git a/rt/lib/RT/Attributes.pm b/rt/lib/RT/Attributes.pm
index 2be0130a9..fcbd0b1b4 100644
--- a/rt/lib/RT/Attributes.pm
+++ b/rt/lib/RT/Attributes.pm
@@ -2,7 +2,7 @@
#
# COPYRIGHT:
#
-# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
# <sales@bestpractical.com>
#
# (Except where explicitly superseded by other copyright notices)
@@ -46,22 +46,14 @@
#
# 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::Attributes -- Class Description
-
+RT::Attributes - collection of RT::Attribute objects
+
=head1 SYNOPSIS
- use RT::Attributes
+ use RT::Attributes;
+ my $Attributes = RT::Attributes->new($CurrentUser);
=head1 DESCRIPTION
@@ -70,54 +62,171 @@ use strict;
=cut
+
package RT::Attributes;
-use RT::SearchBuilder;
+use strict;
+use warnings;
+
+
use RT::Attribute;
-use vars qw( @ISA );
-@ISA= qw(RT::SearchBuilder);
+use base 'RT::SearchBuilder';
+sub Table { 'Attributes'}
-sub _Init {
+
+sub _DoSearch {
my $self = shift;
- $self->{'table'} = 'Attributes';
- $self->{'primary_key'} = 'id';
+ $self->SUPER::_DoSearch();
+# if _DoSearch doesn't fully succeed, 'must_redo_search' will be true
+# and call _BuildAccessTable then will result in a deep recursion
+ if ( $self->{'must_redo_search'} ) {
+ $RT::Logger->crit(
+"_DoSearch is not so successful as it still needs redo search, won't call _BuildAccessTable"
+ );
+ }
+ else {
+ $self->_BuildAccessTable();
+ }
+}
- return ( $self->SUPER::_Init(@_) );
+sub _BuildAccessTable {
+ my $self = shift;
+ delete $self->{'attr'};
+ while (my $attr = $self->Next) {
+ push @{$self->{'attr'}->{$attr->Name}}, $attr;
+ }
}
-=head2 NewItem
+sub _AttrHash {
+ my $self = shift;
+ $self->_DoSearch if ($self->{'must_redo_search'} && $self->{'is_limited'});
+ unless ($self->{'attr'}) {
+ $self->{'attr'}->{'__none'} = RT::Attribute->new($self->CurrentUser);
+ }
+ return ($self->{'attr'});
+}
-Returns an empty new RT::Attribute item
+=head2 Names
+
+Returns a list of the Names of all attributes for this object.
=cut
-sub NewItem {
+sub Names {
my $self = shift;
- return(RT::Attribute->new($self->CurrentUser));
+ my @keys = keys %{$self->_AttrHash};
+ return(@keys);
+
+
}
-RT::Base->_ImportOverlays();
-=head1 SEE ALSO
+=head2 Named STRING
+
+Returns an array of all the RT::Attribute objects with the name STRING
+
+=cut
+
+sub Named {
+ my $self = shift;
+ my $name = shift;
+ my @attributes;
+ if ($self->_AttrHash) {
+ @attributes = @{($self->_AttrHash->{$name}||[])};
+ }
+ return (@attributes);
+}
+
+=head2 WithId ID
+
+Returns the RT::Attribute objects with the id ID
-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.
+XXX TODO XXX THIS NEEDS A BETTER ACL CHECK
-These overlay files can contain new subs or subs to replace existing subs in this module.
+=cut
+
+sub WithId {
+ my $self = shift;
+ my $id = shift;
+
+ my $attr = RT::Attribute->new($self->CurrentUser);
+ $attr->LoadByCols( id => $id );
+ return($attr);
+}
+
+=head2 DeleteEntry { Name => Content => , id => }
+
+Deletes attributes with
+ the matching name
+ and the matching content or id
+
+If Content and id are both undefined, delete all attributes with
+the matching name.
+
+=cut
+
+
+sub DeleteEntry {
+ my $self = shift;
+ my %args = (
+ Name => undef,
+ Content => undef,
+ id => undef,
+ @_
+ );
+ my $found = 0;
+ foreach my $attr ( $self->Named( $args{'Name'} ) ) {
+ if ( ( !defined $args{'id'} and !defined $args{'Content'} )
+ or ( defined $args{'id'} and $attr->id eq $args{'id'} )
+ or ( defined $args{'Content'} and $attr->Content eq $args{'Content'} ) )
+ {
+ my ($id, $msg) = $attr->Delete;
+ return ($id, $msg) unless $id;
+ $found = 1;
+ }
+ }
+ return (0, "No entry found") unless $found;
+ $self->RedoSearch;
+ # XXX: above string must work but because of bug in DBIx::SB it doesn't,
+ # to reproduce delete string below and run t/api/attribute-tests.t
+ $self->_DoSearch;
+ return (1, $self->loc('Attribute Deleted'));
+}
-Each of these files should begin with the line
- no warnings qw(redefine);
-so that perl does not kick and scream when you redefine a subroutine or variable in your overlay.
+=head2 LimitToObject $object
-RT::Attributes_Overlay, RT::Attributes_Vendor, RT::Attributes_Local
+Limit the Attributes to rights for the object $object. It needs to be an RT::Record class.
=cut
+sub LimitToObject {
+ my $self = shift;
+ my $obj = shift;
+ unless (eval { $obj->id} ){
+ return undef;
+ }
+ $self->Limit(FIELD => 'ObjectType', OPERATOR=> '=', VALUE => ref($obj), ENTRYAGGREGATOR => 'OR');
+ $self->Limit(FIELD => 'ObjectId', OPERATOR=> '=', VALUE => $obj->id, ENTRYAGGREGATOR => 'OR', QUOTEVALUE => 0);
+
+}
+
+
+
+=head2 NewItem
+
+Returns an empty new RT::Attribute item
+
+=cut
+
+sub NewItem {
+ my $self = shift;
+ return(RT::Attribute->new($self->CurrentUser));
+}
+RT::Base->_ImportOverlays();
1;