diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index dd6de1a7..a212697f 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -252,4 +252,49 @@ sub updateJobset { } +sub clone : Chained('jobset') PathPart('clone') Args(0) { + my ($self, $c) = @_; + + my $jobset = $c->stash->{jobset}; + requireProjectOwner($c, $jobset->project); + + $c->stash->{template} = 'clone-jobset.tt'; +} + +sub clone_submit : Chained('jobset') PathPart('clone/submit') Args(0) { + my ($self, $c) = @_; + + my $jobset = $c->stash->{jobset}; + requireProjectOwner($c, $jobset->project); + requirePost($c); + + my $newjobsetName = trim $c->request->params->{"newjobset"}; + error($c, "Invalid jobset name: $newjobsetName") unless $newjobsetName =~ /^[[:alpha:]][\w\-]*$/; + + my $newjobset; + txn_do($c->model('DB')->schema, sub { + $newjobset = $jobset->project->jobsets->create( + { name => $newjobsetName + , description => $jobset->description + , nixexprpath => $jobset->nixexprpath + , nixexprinput => $jobset->nixexprinput + , enabled => 0 + , enableemail => $jobset->enableemail + , emailoverride => $jobset->emailoverride + }); + + foreach my $input ($jobset->jobsetinputs) { + my $newinput = $newjobset->jobsetinputs->create({name => $input->name, type => $input->type}); + foreach my $inputalt ($input->jobsetinputalts) { + $newinput->jobsetinputalts->create({altnr => $inputalt->altnr, value => $inputalt->value}); + } + } + }); + + $c->res->redirect($c->uri_for($c->controller('Jobset')->action_for("edit"), [$jobset->project->name, $newjobsetName])); + +} + + + 1; diff --git a/src/root/clone-jobset.tt b/src/root/clone-jobset.tt new file mode 100644 index 00000000..209c52c7 --- /dev/null +++ b/src/root/clone-jobset.tt @@ -0,0 +1,18 @@ +[% WRAPPER layout.tt title="Clone Jobset" %] +[% PROCESS common.tt %] +[% USE HTML %] +[% edit=1 %] + +
+ +

Cloning jobset [% jobset.project.name %]:[% jobset.name %]

+

+ Name "") %] /> +

+

+ +

+ +
+ +[% END %] diff --git a/src/root/jobset.tt b/src/root/jobset.tt index 4e68c71d..12c10466 100644 --- a/src/root/jobset.tt +++ b/src/root/jobset.tt @@ -151,7 +151,13 @@ [% END %] [% END %]
-

Information[% IF !edit %] [Edit][% END %]

+

Information

+ + [% IF !edit && c.user_exists %] +

+ [ Edit | Clone ] +

+ [% END %] [% IF edit %]