Add cancel-build role
This commit is contained in:
parent
ce1e10c116
commit
841a47cabe
|
@ -504,7 +504,7 @@ sub restart : Chained('buildChain') PathPart Args(0) {
|
||||||
sub cancel : Chained('buildChain') PathPart Args(0) {
|
sub cancel : Chained('buildChain') PathPart Args(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
my $build = $c->stash->{build};
|
my $build = $c->stash->{build};
|
||||||
requireProjectOwner($c, $build->project);
|
requireCancelBuildPrivileges($c, $build->project);
|
||||||
my $n = cancelBuilds($c->model('DB')->schema, $c->model('DB::Builds')->search({ id => $build->id }));
|
my $n = cancelBuilds($c->model('DB')->schema, $c->model('DB::Builds')->search({ id => $build->id }));
|
||||||
error($c, "This build cannot be cancelled.") if $n != 1;
|
error($c, "This build cannot be cancelled.") if $n != 1;
|
||||||
$c->flash->{successMsg} = "Build has been cancelled.";
|
$c->flash->{successMsg} = "Build has been cancelled.";
|
||||||
|
|
|
@ -179,7 +179,7 @@ sub create_jobset : Chained('evalChain') PathPart('create-jobset') Args(0) {
|
||||||
|
|
||||||
sub cancel : Chained('evalChain') PathPart('cancel') Args(0) {
|
sub cancel : Chained('evalChain') PathPart('cancel') Args(0) {
|
||||||
my ($self, $c) = @_;
|
my ($self, $c) = @_;
|
||||||
requireProjectOwner($c, $c->stash->{eval}->project);
|
requireCancelBuildPrivileges($c, $c->stash->{eval}->project);
|
||||||
my $n = cancelBuilds($c->model('DB')->schema, $c->stash->{eval}->builds);
|
my $n = cancelBuilds($c->model('DB')->schema, $c->stash->{eval}->builds);
|
||||||
$c->flash->{successMsg} = "$n builds have been cancelled.";
|
$c->flash->{successMsg} = "$n builds have been cancelled.";
|
||||||
$c->res->redirect($c->uri_for($c->controller('JobsetEval')->action_for('view'), $c->req->captures));
|
$c->res->redirect($c->uri_for($c->controller('JobsetEval')->action_for('view'), $c->req->captures));
|
||||||
|
|
|
@ -14,6 +14,7 @@ our @EXPORT = qw(
|
||||||
error notFound gone accessDenied
|
error notFound gone accessDenied
|
||||||
forceLogin requireUser requireProjectOwner requireRestartPrivileges requireAdmin requirePost isAdmin isProjectOwner
|
forceLogin requireUser requireProjectOwner requireRestartPrivileges requireAdmin requirePost isAdmin isProjectOwner
|
||||||
requireBumpPrivileges
|
requireBumpPrivileges
|
||||||
|
requireCancelBuildPrivileges
|
||||||
trim
|
trim
|
||||||
getLatestFinishedEval getFirstEval
|
getLatestFinishedEval getFirstEval
|
||||||
paramToList
|
paramToList
|
||||||
|
@ -182,6 +183,27 @@ sub isProjectOwner {
|
||||||
defined $c->model('DB::ProjectMembers')->find({ project => $project, userName => $c->user->username }));
|
defined $c->model('DB::ProjectMembers')->find({ project => $project, userName => $c->user->username }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub hasCancelBuildRole {
|
||||||
|
my ($c) = @_;
|
||||||
|
return $c->user_exists && $c->check_user_roles('cancel-build');
|
||||||
|
}
|
||||||
|
|
||||||
|
sub mayCancelBuild {
|
||||||
|
my ($c, $project) = @_;
|
||||||
|
return
|
||||||
|
$c->user_exists &&
|
||||||
|
(isAdmin($c) ||
|
||||||
|
hasCancelBuildRole($c) ||
|
||||||
|
isProjectOwner($c, $project));
|
||||||
|
}
|
||||||
|
|
||||||
|
sub requireCancelBuildPrivileges {
|
||||||
|
my ($c, $project) = @_;
|
||||||
|
requireUser($c);
|
||||||
|
accessDenied($c, "Only the project members, administrators, and accounts with cancel-build privileges can perform this operation.")
|
||||||
|
unless mayCancelBuild($c, $project);
|
||||||
|
}
|
||||||
|
|
||||||
sub hasBumpJobsRole {
|
sub hasBumpJobsRole {
|
||||||
my ($c) = @_;
|
my ($c) = @_;
|
||||||
return $c->user_exists && $c->check_user_roles('bump-to-front');
|
return $c->user_exists && $c->check_user_roles('bump-to-front');
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
[% INCLUDE roleoption role="create-projects" %]
|
[% INCLUDE roleoption role="create-projects" %]
|
||||||
[% INCLUDE roleoption role="restart-jobs" %]
|
[% INCLUDE roleoption role="restart-jobs" %]
|
||||||
[% INCLUDE roleoption role="bump-to-front" %]
|
[% INCLUDE roleoption role="bump-to-front" %]
|
||||||
|
[% INCLUDE roleoption role="cancel-build" %]
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue