[Rt-commit] r18902 - in rt/3.999/trunk/lib/RT: .
ruz at bestpractical.com
ruz at bestpractical.com
Fri Mar 20 23:50:11 EDT 2009
Author: ruz
Date: Fri Mar 20 23:50:10 2009
New Revision: 18902
Added:
rt/3.999/trunk/lib/RT/IsPrincipal.pm
Modified:
rt/3.999/trunk/lib/RT/Model/Group.pm
rt/3.999/trunk/lib/RT/Model/User.pm
Log:
* add IsPrincipal role, not many methods, but should be more
Added: rt/3.999/trunk/lib/RT/IsPrincipal.pm
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/lib/RT/IsPrincipal.pm Fri Mar 20 23:50:10 2009
@@ -0,0 +1,68 @@
+package RT::IsPrincipal;
+
+use strict;
+use warnings;
+
+=head1 NAME
+
+RT::IsPrincipal - role for objects qualifying some principal
+
+=head1 DESCRIPTION
+
+This is role class with methods common to all principals, for
+example User or Group.
+
+=head1 METHODS
+
+=head2 disabled
+
+Returns true if this principal is disabled or false otherwise.
+
+=cut
+
+sub disabled {
+ return shift->principal->disabled;
+}
+
+=head2 principal
+
+Returns L<RT::Model::Principal/|"the principal object"> for this record.
+Each record which share this role must have one principal record. Returns
+undef on error.
+
+=cut
+
+sub principal {
+ my $self = shift;
+
+ unless ( $self->id ) {
+ Jifty->log->error("Couldn't get principal for not loaded object");
+ return undef;
+ }
+
+ my $res = RT::Model::Principal->new( current_user => $self->current_user );
+ $res->load_by_id( $self->id );
+ unless ( $res->id ) {
+ Jifty->log->fatal( 'No principal for '. ref($self) .' #' . $self->id );
+ return undef;
+ }
+# do we really want to check this? it's job for validator
+# elsif ( $res->type ne 'User' ) {
+# Jifty->log->fatal( 'User #' . $self->id . ' has principal of ' . $res->type . ' type' );
+# return undef;
+# }
+ return $res;
+}
+
+=head2 principal_id
+
+Returns id of the principal record for this object.
+
+=cut
+
+sub principal_id {
+ my $self = shift;
+ return $self->id;
+}
+
+1;
Modified: rt/3.999/trunk/lib/RT/Model/Group.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Model/Group.pm (original)
+++ rt/3.999/trunk/lib/RT/Model/Group.pm Fri Mar 20 23:50:10 2009
@@ -69,7 +69,7 @@
=cut
use Jifty::DBI::Schema;
-use base qw/RT::Record/;
+use base qw/RT::IsPrincipal RT::Record/;
use Jifty::DBI::Record schema {
column name => type is 'varchar(200)';
@@ -682,13 +682,6 @@
}
-
-sub disabled {
- my $self = shift;
- $self->principal->disabled(@_);
-}
-
-
=head2 members
Returns either an L<RT::Model::GroupMemberCollection> or L<RT::Model::CachedGroupMemberCollection>
@@ -1153,40 +1146,6 @@
}
-
-=head2 principal
-
-Returns the principal object for this user. returns an empty RT::Model::Principal
-if there's no principal object matching this user.
-The response is cached. principal should never ever change.
-
-
-=cut
-
-sub principal {
- my $self = shift;
- unless ( $self->{'principal'} && $self->{'principal'}->id ) {
- $self->{'principal'} = RT::Model::Principal->new( current_user => $self->current_user );
- $self->{'principal'}->load_by_cols(
- id => $self->id,
- type => 'Group'
- );
- }
- return $self->{'principal'};
-}
-
-=head2 principal_id
-
-Returns this user's principal_id
-
-=cut
-
-sub principal_id {
- my $self = shift;
- return $self->id;
-}
-
-
sub basic_columns {
( [ name => 'name' ], [ description => 'description' ], );
}
Modified: rt/3.999/trunk/lib/RT/Model/User.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Model/User.pm (original)
+++ rt/3.999/trunk/lib/RT/Model/User.pm Fri Mar 20 23:50:10 2009
@@ -50,7 +50,7 @@
package RT::Model::User;
-use base qw/RT::Record/;
+use base qw/RT::IsPrincipal RT::Record/;
=head1 NAME
@@ -582,7 +582,7 @@
}
-=head2 validateemail ADDRESS
+=head2 validate_email ADDRESS
Returns true if the email address entered is not in use by another user or is
undef or ''. Returns false if it's in use.
@@ -620,7 +620,7 @@
=item 'squelched' - returned only when Ticket argument is provided and
notifications to the user has been supressed for this ticket.
-=item 'daily' - retruned when user recieve daily messages digest instead
+=item 'daily' - returned when user recieve daily messages digest instead
of immediate delivery.
=item 'weekly' - previous, but weekly.
@@ -859,7 +859,7 @@
return $auth_string eq substr(Digest::MD5::md5_hex($str),0,16);
}
-=head2 sub set_disabled
+=head2 set_disabled
Toggles the user's disabled flag.
If this flag is
@@ -882,57 +882,6 @@
return $self->principal->set_disabled(@_);
}
-=head2 disabled
-
-Returns true if user is disabled or false otherwise
-
-=cut
-
-sub disabled {
- my $self = shift;
- return $self->principal->disabled(@_);
-}
-
-=head2 principal
-
-Returns the principal object for this user. returns an empty RT::Model::Principal
-if there's no principal object matching this user.
-The response is cached. principal should never ever change.
-
-
-=cut
-
-sub principal {
- my $self = shift;
-
- unless ( $self->id ) {
- Jifty->log->error("Couldn't get principal for not loaded object");
- return undef;
- }
-
- my $obj = RT::Model::Principal->new( current_user => $self->current_user );
- $obj->load_by_id( $self->id );
- unless ( $obj->id ) {
- Jifty->log->fatal( 'No principal for user #' . $self->id );
- return undef;
- } elsif ( $obj->type ne 'User' ) {
- Jifty->log->fatal( 'User #' . $self->id . ' has principal of ' . $obj->type . ' type' );
- return undef;
- }
- return $obj;
-}
-
-=head2 principal_id
-
-Returns this user's principal_id
-
-=cut
-
-sub principal_id {
- my $self = shift;
- return $self->id;
-}
-
=head2 has_group_right
Takes a paramhash which can contain
@@ -1160,8 +1109,6 @@
my $self = shift;
my @roles = @_ || ( 'cc', 'admin_cc' );
- Jifty->log->debug( 'WatcheQueues got user ' . $self->name );
-
my $watched_queues = RT::Model::QueueCollection->new( current_user => $self->current_user );
my $group_alias = $watched_queues->join(
@@ -1208,8 +1155,6 @@
value => $self->principal_id,
);
- Jifty->log->debug( "WatchedQueues got " . $watched_queues->count . " queues" );
-
return $watched_queues;
}
More information about the Rt-commit
mailing list