[Rt-commit] rt branch, admin_ui, updated. f7d92cc4a63437c527a1951caa6ac60555882747
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Mon Nov 30 23:57:06 EST 2009
The branch, admin_ui has been updated
via f7d92cc4a63437c527a1951caa6ac60555882747 (commit)
via d65ee839626ab4a10aeb4d1d1a8e9ba1d7f214d3 (commit)
from 67abf7f7e8f93a9cc3abdd8aae591e801de62a45 (commit)
Summary of changes:
lib/RT/Action/{EditUserRights.pm => EditRights.pm} | 48 +-------
lib/RT/Action/EditUserRights.pm | 123 +-------------------
2 files changed, 6 insertions(+), 165 deletions(-)
copy lib/RT/Action/{EditUserRights.pm => EditRights.pm} (71%)
- Log -----------------------------------------------------------------
commit d65ee839626ab4a10aeb4d1d1a8e9ba1d7f214d3
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Dec 1 12:54:48 2009 +0800
move common stuff to EditRights
diff --git a/lib/RT/Action/EditUserRights.pm b/lib/RT/Action/EditRights.pm
similarity index 74%
copy from lib/RT/Action/EditUserRights.pm
copy to lib/RT/Action/EditRights.pm
index 51c62c5..7d17a33 100644
--- a/lib/RT/Action/EditUserRights.pm
+++ b/lib/RT/Action/EditRights.pm
@@ -2,44 +2,14 @@
use strict;
use warnings;
-package RT::Action::EditUserRights;
+package RT::Action::EditRights;
use base qw/RT::Action Jifty::Action/;
use Scalar::Defer;
sub arguments {
my $self = shift;
- return {} unless $self->object;
- my $args = {};
- $args->{object_id} = {
- render_as => 'hidden',
- default_value => $self->object->id,
- };
- $args->{object_type} = {
- render_as => 'hidden',
- default_value => ref $self->object,
- };
-
- my $privileged =
- RT::Model::Group->new( current_user => Jifty->web->current_user );
- $privileged->load_system_internal('privileged');
- my $users = $privileged->members;
-
- while ( my $user = $users->next ) {
- my $group =
- RT::Model::Group->new( current_user => Jifty->web->current_user );
- $group->load_acl_equivalence( $user->member );
-
- my $name = 'rights_' . $group->principal_id;
- $args->{$name} = {
- default_value => defer {
- $self->default_value($group->principal_id) },
- available_values => defer { $self->available_values },
- render_as => 'Checkboxes',
- multiple => 1,
- label => $user->member->object->real_name,
- };
- }
- return $args;
+ $self->log->fatal(
+ "Use one of the subclasses, EditUserRights or EditGroupRights" );
}
=head2 take_action
diff --git a/lib/RT/Action/EditUserRights.pm b/lib/RT/Action/EditUserRights.pm
index 51c62c5..3d6d5ef 100644
--- a/lib/RT/Action/EditUserRights.pm
+++ b/lib/RT/Action/EditUserRights.pm
@@ -3,7 +3,7 @@ use strict;
use warnings;
package RT::Action::EditUserRights;
-use base qw/RT::Action Jifty::Action/;
+use base qw/RT::Action::EditRights/;
use Scalar::Defer;
sub arguments {
@@ -42,126 +42,5 @@ sub arguments {
return $args;
}
-=head2 take_action
-
-=cut
-
-sub take_action {
- my $self = shift;
-
- my $object_type = $self->argument_value('object_type');
- return unless $object_type;
- if ( $object_type eq 'RT::System' ) {
- $self->object( RT->system );
- }
- elsif ( $RT::Model::ACE::OBJECT_TYPES{$object_type} ) {
- my $object =
- $object_type->new( current_user => Jifty->web->current_user );
- my $object_id = $self->argument_value('object_id');
- $object->load($object_id);
- unless ( $object->id ) {
- Jifty->log->error("couldn't load $object_type #$object_id");
- return;
- }
-
- $self->object($object);
- }
- else {
- Jifty->log->error("object type '$object_type' is incorrect");
- return;
- }
-
- for my $arg ( $self->argument_names ) {
- next
- unless ( $arg =~ /^rights_(\d+)$/ );
-
- my $principal_id = $1;
-
- my @rights;
- my $value = $self->argument_value($arg);
- if ( UNIVERSAL::isa( $self->argument_value($arg), 'ARRAY' ) ) {
- @rights = @$value;
- }
- else {
- @rights = $value;
- }
-
- @rights = grep $_, @rights;
- next unless @rights;
-
- my $principal =
- RT::Model::Principal->new( current_user => Jifty->web->current_user );
- $principal->load($principal_id);
-
- my $current_rights = $self->default_value($principal_id);
- my %current_rights = map { $_ => 1 } @$current_rights;
- my %rights = map { $_ => 1 } @rights;
-
- for my $right ( keys %current_rights ) {
- next if $rights{$right};
- my ( $val, $msg ) =
- $principal->revoke_right( object => $self->object, right => $right );
- Jifty->log->error($msg) unless $val;
- }
-
- for my $right ( keys %rights ) {
- next if $current_rights{$right};
- my ( $val, $msg ) =
- $principal->grant_right( object => $self->object, right => $right );
- Jifty->log->error($msg) unless $val;
- }
- }
-
- $self->report_success;
- return 1;
-}
-
-=head2 report_success
-
-=cut
-
-sub report_success {
- my $self = shift;
-
- # Your success message here
- $self->result->message('Success');
-}
-
-sub object {
- my $self = shift;
- if (@_) {
- $self->{object} = shift;
- }
- else {
- $self->{object};
- }
-}
-
-sub available_values {
- my $self = shift;
- my $object = $self->object;
- my $rights = $object->available_rights;
- return [ sort keys %$rights ];
-}
-
-sub default_value {
- my $self = shift;
- my $principal_id = shift;
-
- my $object = $self->object;
- my $acl_obj =
- RT::Model::ACECollection->new( current_user => Jifty->web->current_user );
- my $ACE = RT::Model::ACE->new( current_user => Jifty->web->current_user );
- $acl_obj->limit_to_object($object);
- $acl_obj->limit_to_principal( id => $principal_id );
- $acl_obj->order_by( column => 'right_name' );
-
- my @rights;
- while ( my $acl = $acl_obj->next ) {
- push @rights, $acl->right_name;
- }
- return [@rights];
-}
-
1;
commit f7d92cc4a63437c527a1951caa6ac60555882747
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Dec 1 12:56:53 2009 +0800
refactor a bit
diff --git a/lib/RT/Action/EditRights.pm b/lib/RT/Action/EditRights.pm
index 7d17a33..32b7c12 100644
--- a/lib/RT/Action/EditRights.pm
+++ b/lib/RT/Action/EditRights.pm
@@ -6,6 +6,8 @@ package RT::Action::EditRights;
use base qw/RT::Action Jifty::Action/;
use Scalar::Defer;
+__PACKAGE__->mk_accessors('object');
+
sub arguments {
my $self = shift;
$self->log->fatal(
@@ -97,16 +99,6 @@ sub report_success {
$self->result->message('Success');
}
-sub object {
- my $self = shift;
- if (@_) {
- $self->{object} = shift;
- }
- else {
- $self->{object};
- }
-}
-
sub available_values {
my $self = shift;
my $object = $self->object;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list