diff --git a/src/lib/Hydra/Controller/Release.pm b/src/lib/Hydra/Controller/Release.pm index d25c21da..3cd794e5 100644 --- a/src/lib/Hydra/Controller/Release.pm +++ b/src/lib/Hydra/Controller/Release.pm @@ -9,8 +9,12 @@ use Hydra::Helper::CatalystUtils; sub release : Chained('/') PathPart('release') CaptureArgs(2) { my ($self, $c, $projectName, $releaseName) = @_; - #$c->stash->{project} = $project; - #$c->stash->{release} = $view; + + $c->stash->{project} = $c->model('DB::Projects')->find($projectName) + or notFound($c, "Project $projectName doesn't exist."); + + $c->stash->{release} = $c->stash->{project}->releases->find({name => $releaseName}) + or notFound($c, "Release $releaseName doesn't exist."); } @@ -25,7 +29,7 @@ sub updateRelease { my $releaseName = trim $c->request->params->{name}; error($c, "Invalid release name: $releaseName") - unless $releaseName =~ /^[[:alpha:]][\w\-]*$/; + unless $releaseName =~ /^$relNameRE$/; $release->update( { name => $releaseName @@ -34,4 +38,33 @@ sub updateRelease { } +sub edit : Chained('release') PathPart('edit') Args(0) { + my ($self, $c) = @_; + requireProjectOwner($c, $c->stash->{project}); + $c->stash->{template} = 'edit-release.tt'; +} + + +sub submit : Chained('release') PathPart('submit') Args(0) { + my ($self, $c) = @_; + requireProjectOwner($c, $c->stash->{project}); + txn_do($c->model('DB')->schema, sub { + updateRelease($c, $c->stash->{release}); + }); + $c->res->redirect($c->uri_for($self->action_for("view"), + [$c->stash->{project}->name, $c->stash->{release}->name])); +} + + +sub delete : Chained('release') PathPart('delete') Args(0) { + my ($self, $c) = @_; + requireProjectOwner($c, $c->stash->{project}); + txn_do($c->model('DB')->schema, sub { + $c->stash->{release}->delete; + }); + $c->res->redirect($c->uri_for($c->controller('Project')->action_for('releases'), + [$c->stash->{project}->name])); +} + + 1; diff --git a/src/lib/Hydra/Controller/View.pm b/src/lib/Hydra/Controller/View.pm index b7de9c48..fd46aa1b 100644 --- a/src/lib/Hydra/Controller/View.pm +++ b/src/lib/Hydra/Controller/View.pm @@ -129,7 +129,8 @@ sub delete : Chained('view') PathPart('delete') Args(0) { txn_do($c->model('DB')->schema, sub { $c->stash->{view}->delete; }); - $c->res->redirect($c->uri_for($c->controller('Project')->action_for('view'), [$c->stash->{project}->name])); + $c->res->redirect($c->uri_for($c->controller('Project')->action_for('view'), + [$c->stash->{project}->name])); } diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index fffc66f2..edc13383 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -11,7 +11,7 @@ our @EXPORT = qw( error notFound requireLogin requireProjectOwner requireAdmin requirePost trim - $pathCompRE $relPathRE + $pathCompRE $relPathRE $relNameRE ); @@ -133,6 +133,7 @@ sub trim { # Security checking of filenames. Readonly::Scalar our $pathCompRE => "(?:[A-Za-z0-9-\+][A-Za-z0-9-\+\._]*)"; Readonly::Scalar our $relPathRE => "(?:$pathCompRE(?:\/$pathCompRE)*)"; +Readonly::Scalar our $relNameRE =>"(?:[A-Za-z0-9-][A-Za-z0-9-\.]*)"; 1; diff --git a/src/root/edit-release.tt b/src/root/edit-release.tt index 1461a92e..f63b1977 100644 --- a/src/root/edit-release.tt +++ b/src/root/edit-release.tt @@ -2,9 +2,9 @@ [% PROCESS common.tt %] [% USE HTML %] -