From 1e00e6a93fd9796487cc515ad602ab864b70db3c Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 30 Jul 2010 16:26:40 -0700 Subject: [PATCH] Complete refactor, to handle defaulting to www_view. --- lib/WebGUI/Asset.pm | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 38a2a6874..a110ab973 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -571,23 +571,21 @@ URL. =head3 $fragment -A URL. If this URL is missing, then output from the view method is returned. -If the fragment does not match this Asset's URL, then it returns undef. +Any leftover part of the requested URL. =cut sub dispatch { my ($self, $fragment) = @_; - if (my $func = $self->session->form->param('func')) { - return undef if $fragment && $fragment ne $self->getUrl; - if (my $sub = $self->can('www_'.$func)) { - return $sub->(); - } - } - if (! $fragment ) { - return $self->www_view; - } - return undef; + return undef if defined $fragment; + my $state = $self->get('state'); + ##Only allow interaction with assets in certain states + return if $state ne 'published' && $state ne 'archived' && !$self->session->var->isAdminOn; + my $func = $self->session->form->param('func') || 'view'; + my $sub = $self->can('www_'.$func) || $self->can('www_view'); + return undef unless $sub; + my $output = $sub->(); + return $output; }