Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a restart-jobs role #526

Merged
merged 1 commit into from Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/Hydra/Controller/JobsetEval.pm
Expand Up @@ -188,7 +188,7 @@ sub cancel : Chained('evalChain') PathPart('cancel') Args(0) {

sub restart {
my ($self, $c, $condition) = @_;
requireProjectOwner($c, $c->stash->{eval}->project);
requireRestartPrivileges($c, $c->stash->{eval}->project);
my $builds = $c->stash->{eval}->builds->search({ finished => 1, buildstatus => $condition });
my $n = restartBuilds($c->model('DB')->schema, $builds);
$c->flash->{successMsg} = "$n builds have been restarted.";
Expand Down
24 changes: 21 additions & 3 deletions src/lib/Hydra/Helper/CatalystUtils.pm
Expand Up @@ -12,7 +12,7 @@ our @EXPORT = qw(
getBuild getPreviousBuild getNextBuild getPreviousSuccessfulBuild
searchBuildsAndEvalsForJobset
error notFound gone accessDenied
forceLogin requireUser requireProjectOwner requireAdmin requirePost isAdmin isProjectOwner
forceLogin requireUser requireProjectOwner requireRestartPrivileges requireAdmin requirePost isAdmin isProjectOwner
trim
getLatestFinishedEval getFirstEval
paramToList
Expand Down Expand Up @@ -172,7 +172,6 @@ sub requireUser {
forceLogin($c) if !$c->user_exists;
}


sub isProjectOwner {
my ($c, $project) = @_;
return
Expand All @@ -182,6 +181,26 @@ sub isProjectOwner {
defined $c->model('DB::ProjectMembers')->find({ project => $project, userName => $c->user->username }));
}

sub hasRestartJobsRole {
my ($c) = @_;
return $c->user_exists && $c->check_user_roles('restart-jobs');
}

sub mayRestartJobs {
my ($c, $project) = @_;
return
$c->user_exists &&
(isAdmin($c) ||
hasRestartJobsRole($c) ||
isProjectOwner($c, $project));
}

sub requireRestartPrivileges {
my ($c, $project) = @_;
requireUser($c);
accessDenied($c, "Only the project members, administrators, and accounts with restart-jobs privileges can perform this operation.")
unless mayRestartJobs($c, $project);
}

sub requireProjectOwner {
my ($c, $project) = @_;
Expand All @@ -196,7 +215,6 @@ sub isAdmin {
return $c->user_exists && $c->check_user_roles('admin');
}


sub requireAdmin {
my ($c) = @_;
requireUser($c);
Expand Down
1 change: 1 addition & 0 deletions src/root/user.tt
Expand Up @@ -80,6 +80,7 @@
<select multiple="multiple" name="roles" class="span3" [% IF !c.check_user_roles('admin') %]disabled="disabled"[% END %]>
[% INCLUDE roleoption role="admin" %]
[% INCLUDE roleoption role="create-projects" %]
[% INCLUDE roleoption role="restart-jobs" %]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this role will be created on save: https://github.com/NixOS/hydra/blob/master/src/lib/Hydra/Controller/User.pm#L217-L218 and also I see nowhere in the code which explicitly adds the existing roles to the DB.

</select>
</div>
</div>
Expand Down