]> ruin.nu Git - ndwebbie.git/commitdiff
Give an error message when an ajax action isn't allowed
authorMichael Andreen <harv@ruin.nu>
Mon, 21 Jul 2008 11:59:53 +0000 (13:59 +0200)
committerMichael Andreen <harv@ruin.nu>
Mon, 21 Jul 2008 11:59:53 +0000 (13:59 +0200)
lib/NDWeb/Controller/JSRPC.pm
root/src/jsrpc/access_denied.tt2 [new file with mode: 0644]
root/static/js/raid.js

index 41c7c3d6ebf4df47ce0dd08edb2159e367b99959..b1aeba7bb76915a518158f2ca2928d64a22b1c8d 100644 (file)
@@ -187,6 +187,12 @@ sub listTargets : Local {
        $c->forward('/listTargets');
 }
 
+sub access_denied : Local {
+       my ($self, $c) = @_;
+
+       $c->stash(template => 'jsrcp/access_denied.tt2');
+}
+
 sub assertTarget : Private {
        my ($self, $c, $raid, $from, $target, $wave) = @_;
        my $dbh = $c->model;
@@ -207,6 +213,16 @@ sub assertTarget : Private {
 sub end : ActionClass('RenderView') {
        my ($self,$c) = @_;
        $c->res->content_type('application/xml');
+
+       if (scalar @{ $c->error } ){
+               if ($c->error->[0] =~ m/Can't call method "id" on an undefined value at/){
+                       $c->stash->{template} = 'jsrpc/access_denied.tt2';
+                       $c->clear_errors;
+               }elsif ($c->error->[0] =~ m/Missing roles: /){
+                       $c->stash->{template} = 'jsrpc/access_denied.tt2';
+                       $c->clear_errors;
+               }
+       }
 }
 
 =head1 AUTHOR
diff --git a/root/src/jsrpc/access_denied.tt2 b/root/src/jsrpc/access_denied.tt2
new file mode 100644 (file)
index 0000000..f4bec36
--- /dev/null
@@ -0,0 +1 @@
+<noaccess>Access deined, you might not be logged in anymore.</noaccess>
index 89a06b6c05c6bfd9f7354f83a62ab2ae7011df13..a2dbc2cdc77781346ad3e41b5264a231a147db68 100644 (file)
@@ -57,6 +57,9 @@ function parseUpdate(xml){
        if ($('targetlist',xml).text()){
                $('#targets').empty().html($('targetlist',xml).text());
        }
+       if ($('noaccess',xml).text()){
+               alert($('noaccess',xml).text());
+       }
 }