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 %] -