Commit 6df02adc authored by Sebastian Ziebell's avatar Sebastian Ziebell
Browse files

API: status code 403 returned if new project would exceed limit

When the project limit is reached the user is not allowed to create new ones.
Instead of error code 404 the status code 403 (Forbidden) is returned with error
message via API.
parent bb2267b810ff
......@@ -155,7 +155,7 @@ def import?
def check_limit
unless creator.can_create_project?
errors[:base] << ("Your own projects limit is #{creator.projects_limit}! Please contact administrator to increase it")
errors[:limit_reached] << ("Your own projects limit is #{creator.projects_limit}! Please contact administrator to increase it")
end
rescue
errors[:base] << ("Can't check your ability to create project")
......
......@@ -58,6 +58,9 @@ def handle_project_member_errors(errors)
if @project.saved?
present @project, with: Entities::Project
else
if @project.errors[:limit_reached].present?
error!(@project.errors[:limit_reached], 403)
end
not_found!
end
end
......
......@@ -41,6 +41,11 @@
expect { post api("/projects", user) }.to_not change {Project.count}
end
it "should return a 400 error if name not given" do
post api("/projects", user)
response.status.should == 400
end
it "should respond with 201 on success" do
post api("/projects", user), name: 'foo'
response.status.should == 201
......@@ -51,6 +56,14 @@
response.status.should == 400
end
it "should return a 403 error if project limit reached" do
(1..user.projects_limit).each do |p|
post api("/projects", user), name: "foo#{p}"
end
post api("/projects", user), name: 'bar'
response.status.should == 403
end
it "should assign attributes to project" do
project = attributes_for(:project, {
description: Faker::Lorem.sentence,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment