Return HTTP 400 when creating Project with nonexistent user

This commit is contained in:
Cole Helbling 2021-04-26 11:28:42 -07:00
parent 85e299d3d7
commit 47e19ba22c
No known key found for this signature in database
GPG key ID: B37E0F2371016A4C
3 changed files with 16 additions and 2 deletions

View file

@ -170,6 +170,16 @@ paths:
description: when set to true the project is displayed in the web interface description: when set to true the project is displayed in the web interface
type: boolean type: boolean
responses: responses:
'400':
description: bad request
content:
application/json:
schema:
type: object
properties:
error:
description: error message
type: string
'403': '403':
description: request unauthorized description: request unauthorized
content: content:

View file

@ -135,7 +135,7 @@ sub updateProject {
my $owner = $project->owner; my $owner = $project->owner;
if ($c->check_user_roles('admin') and defined $c->stash->{params}->{owner}) { if ($c->check_user_roles('admin') and defined $c->stash->{params}->{owner}) {
$owner = trim $c->stash->{params}->{owner}; $owner = trim $c->stash->{params}->{owner};
error($c, "The user name $owner does not exist.") badRequest($c, "The user name $owner does not exist.")
unless defined $c->model('DB::Users')->find($owner); unless defined $c->model('DB::Users')->find($owner);
} }

View file

@ -11,7 +11,7 @@ our @ISA = qw(Exporter);
our @EXPORT = qw( our @EXPORT = qw(
getBuild getPreviousBuild getNextBuild getPreviousSuccessfulBuild getBuild getPreviousBuild getNextBuild getPreviousSuccessfulBuild
searchBuildsAndEvalsForJobset searchBuildsAndEvalsForJobset
error notFound gone accessDenied error notFound gone accessDenied badRequest
forceLogin requireUser requireProjectOwner requireRestartPrivileges requireAdmin requirePost isAdmin isProjectOwner forceLogin requireUser requireProjectOwner requireRestartPrivileges requireAdmin requirePost isAdmin isProjectOwner
requireBumpPrivileges requireBumpPrivileges
requireCancelBuildPrivileges requireCancelBuildPrivileges
@ -155,6 +155,10 @@ sub accessDenied {
error($c, $msg, 403); error($c, $msg, 403);
} }
sub badRequest {
my ($c, $msg) = @_;
error($c, $msg, 400);
}
sub backToReferer { sub backToReferer {
my ($c) = @_; my ($c) = @_;