From a7d2f5382c718d12a49b099ba7d30ae300ccdd91 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 28 Nov 2008 00:16:01 +0000 Subject: [PATCH] --- src/Hydra/lib/Hydra/Controller/Root.pm | 41 ++++++++++++++++++++++++++ src/Hydra/root/edit-releaseset.tt | 21 +++++++++++-- src/Hydra/root/releasesets.tt | 2 ++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/Hydra/lib/Hydra/Controller/Root.pm b/src/Hydra/lib/Hydra/Controller/Root.pm index 59459703..a474a3ec 100644 --- a/src/Hydra/lib/Hydra/Controller/Root.pm +++ b/src/Hydra/lib/Hydra/Controller/Root.pm @@ -324,6 +324,13 @@ sub releases :Local { return $c->res->redirect($c->uri_for("/releases", $projectName, $releaseSet->name)); } + elsif ($subcommand eq "delete") { + $c->model('DB')->schema->txn_do(sub { + $releaseSet->delete; + }); + return $c->res->redirect($c->uri_for("/releasesets", $projectName)); + } + else { return error($c, "Unknown subcommand."); } } @@ -342,6 +349,40 @@ sub releases :Local { } +sub create_releaseset :Local { + my ($self, $c, $projectName, $subcommand) = @_; + + my $project = $c->model('DB::Projects')->find($projectName); + die "Project $projectName doesn't exist." if !defined $project; + $c->stash->{curProject} = $project; + + return requireLogin($c) if !$c->user_exists; + + return error($c, "Only the project owner or the administrator can perform this operation.") + unless $c->check_user_roles('admin') || $c->user->username eq $project->owner; + + if (defined $subcommand && $subcommand eq "submit") { + eval { + my $releaseSetName = $c->request->params->{name}; + $c->model('DB')->schema->txn_do(sub { + # Note: $releaseSetName is validated in updateProject, + # which will abort the transaction if the name isn't + # valid. + my $releaseSet = $project->releasesets->create({name => $releaseSetName}); + updateReleaseSet($c, $releaseSet); + return $c->res->redirect($c->uri_for("/releases", $projectName, $releaseSet->name)); + }); + }; + if ($@) { + return error($c, $@); + } + } + + $c->stash->{template} = 'edit-releaseset.tt'; + $c->stash->{create} = 1; +} + + sub release :Local { my ($self, $c, $projectName, $releaseSetName, $releaseId) = @_; $c->stash->{template} = 'release.tt'; diff --git a/src/Hydra/root/edit-releaseset.tt b/src/Hydra/root/edit-releaseset.tt index 802246ac..4d8dc1ae 100644 --- a/src/Hydra/root/edit-releaseset.tt +++ b/src/Hydra/root/edit-releaseset.tt @@ -1,8 +1,8 @@ -[% WRAPPER layout.tt title="Release Sets ‘$curProject.name:$releaseSet.name’" %] +[% WRAPPER layout.tt title=(create ? "New Release Set" : "Release Set ‘$curProject.name:$releaseSet.name’") %] [% PROCESS common.tt %] [% USE HTML %] -

Release Set [% curProject.name %]:[% releaseSet.name %]

+

[% IF create %]New Release Set[% ELSE %]Release Set [% curProject.name %]:[% releaseSet.name %][% END %]

[% BLOCK renderJob %] @@ -21,7 +21,7 @@ [% END %] -
+ @@ -84,4 +84,19 @@ +[% IF !create %] + + +

+ + + + +[% END %] + + [% END %] diff --git a/src/Hydra/root/releasesets.tt b/src/Hydra/root/releasesets.tt index f188c479..04aa011e 100644 --- a/src/Hydra/root/releasesets.tt +++ b/src/Hydra/root/releasesets.tt @@ -14,4 +14,6 @@ [% END %] +

[Create a new release set]

+ [% END %]