[Jifty-commit] r4182 - in apps/CASPlus/trunk: lib/CASPlus lib/CASPlus/Action

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Oct 2 12:03:18 EDT 2007


Author: sterling
Date: Tue Oct  2 12:03:17 2007
New Revision: 4182

Added:
   apps/CASPlus/trunk/lib/CASPlus/Action/RecalculateRoles.pm
Modified:
   apps/CASPlus/trunk/   (props changed)
   apps/CASPlus/trunk/lib/CASPlus/View.pm

Log:
 r12773 at dynpc145:  andrew | 2007-10-02 10:31:21 -0500
 Added a tool for manual recalculation of the user role cache.


Added: apps/CASPlus/trunk/lib/CASPlus/Action/RecalculateRoles.pm
==============================================================================
--- (empty file)
+++ apps/CASPlus/trunk/lib/CASPlus/Action/RecalculateRoles.pm	Tue Oct  2 12:03:17 2007
@@ -0,0 +1,75 @@
+use strict;
+use warnings;
+
+package CASPlus::Action::RecalculateRoles;
+use Jifty::Param::Schema;
+
+use CASPlus::Action schema {
+    param 'user' => 
+        label is 'Recalculate for',
+        render as 'Text',
+        valid_values are defer {
+            my $users = CASPlus::Model::UserCollection->new;
+            $users->unlimit;
+            [{
+                display_from => 'username',
+                value_from   => 'id',
+                collection   => $users,
+            }];
+        },
+        autocompleter is \&autocomplete_user,
+        is mandatory;
+};
+
+use CASPlus::Util::Relationship;
+
+sub take_action {
+    my $self = shift;
+    my $id = $self->argument_value('user');
+
+    my $user = CASPlus::Model::User->new;
+    $user->load($id);
+
+    unless ($user->id) {
+        $self->result->error("Cannot load user for ID $id");
+        return;
+    }
+
+    my $profile = $user->profile;
+    unless ($profile and $profile->id) {
+        $self->result->error("Cannot recalculate ID $id, there is no profile associated with that user account.");
+        return;
+    }
+
+    CASPlus::Util::Relationship->recalculate_role_cache_for_object(
+        $user->profile,
+    );
+
+    $self->result->message("Recalculated the roles for user ".$user->username);
+    return 1;
+}
+
+sub autocomplete_user {
+    my $self = shift;
+    my $value = shift;
+
+    my $users = CASPlus::Model::UserCollection->new;
+    $users->unlimit;
+
+    if ($value) {
+        $users->limit(
+            column   => 'username',
+            operator => 'MATCHES',
+            value    => $value,
+        );
+    }
+
+    $users->set_page_info( per_page => 5 );
+
+    return (
+        map { { label => $_->username, value => $_->id } }
+           @{ $users->items_array_ref || [] }
+    );
+}
+
+1;

Modified: apps/CASPlus/trunk/lib/CASPlus/View.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/View.pm	(original)
+++ apps/CASPlus/trunk/lib/CASPlus/View.pm	Tue Oct  2 12:03:17 2007
@@ -65,50 +65,59 @@
     my $service = get('service') || undef;
     my $lt      = get 'lt';
 
-    form {
-        attr { method => 'POST', action => '/login' };
+    div {
+        { class is 'login' }
 
-        if ($service) {
-            outs(Jifty::Web::Form::Field->new(
-                render_as     => 'Hidden',
-                name          => 'service',
-                input_name    => 'service',
-                default_value => $service,
-            )->render);
-        }
+        div {
+            { class is 'login-form' }
 
-        outs(Jifty::Web::Form::Field->new(
-            render_as  => 'Text',
-            name       => 'username',
-            input_name => 'username',
-            label      => _('Username'),
-        )->render);
-
-        outs(Jifty::Web::Form::Field->new(
-            render_as  => 'Password',
-            name       => 'password',
-            input_name => 'password',
-            label      => _('Password'),
-        )->render);
-
-        if (Jifty->config->app('Login')->{'ShowLoginWarningCheckbox'}) {
-            outs(Jifty::Web::Form::Field->new(
-                render_as  => 'Checkbox',
-                name       => 'warn',
-                input_name => 'warn',
-                label      => _('Warn me when other services log me in.'),
-                hints      => _('You are a logging in to a service which may be used by multiple web sites. By checking this box you are asking to see a special message letting you know whenever another web site asks who you are.'),
-            )->render);
-        }
+            form {
+                attr { method => 'POST', action => '/login' };
 
-        outs(Jifty::Web::Form::Field->new(
-            render_as     => 'Hidden',
-            name          => 'lt',
-            input_name    => 'lt',
-            default_value => $lt->login_ticket,
-        )->render);
-        
-        form_submit(label => 'Login');
+                if ($service) {
+                    outs(Jifty::Web::Form::Field->new(
+                        render_as     => 'Hidden',
+                        name          => 'service',
+                        input_name    => 'service',
+                        default_value => $service,
+                    )->render);
+                }
+
+                outs(Jifty::Web::Form::Field->new(
+                    render_as  => 'Text',
+                    name       => 'username',
+                    input_name => 'username',
+                    label      => _('Username'),
+                )->render);
+
+                outs(Jifty::Web::Form::Field->new(
+                    render_as  => 'Password',
+                    name       => 'password',
+                    input_name => 'password',
+                    label      => _('Password'),
+                )->render);
+
+                if (Jifty->config->app('Login')->{'ShowLoginWarningCheckbox'}) {
+                    outs(Jifty::Web::Form::Field->new(
+                        render_as  => 'Checkbox',
+                        name       => 'warn',
+                        input_name => 'warn',
+                        label      => _('Warn me when other services log me in.'),
+                        hints      => _('You are a logging in to a service which may be used by multiple web sites. By checking this box you are asking to see a special message letting you know whenever another web site asks who you are.'),
+                    )->render);
+                }
+
+                outs(Jifty::Web::Form::Field->new(
+                    render_as     => 'Hidden',
+                    name          => 'lt',
+                    input_name    => 'lt',
+                    default_value => $lt->login_ticket,
+                )->render);
+                
+                form_submit(label => 'Login');
+            };
+
+        };
     };
 };
 
@@ -259,6 +268,17 @@
     };
 };
 
+template 'admin/users/recalculate' => page {
+    { title is 'Recalculate Roles' };
+
+    p { _('The roles for each user are cached. If you suspect this cache to be corrupt for a user, select that user and then recalculate.'); };
+
+    form {
+        render_action get 'action';
+        form_submit label => 'Recalculate';
+    };
+};
+
 use CASPlus::View::User;
 alias CASPlus::View::User under '/user';
 


More information about the Jifty-commit mailing list