Commit d4d4a78f authored by Izaak Alpert's avatar Izaak Alpert

Update User api to respect default settings

-API now respects default_projects_limit, default_can_create_group, and default_can_create_team

Change-Id: I059d060d576df1050e5371e707381c5e8c608a7a
parent 694768e5
...@@ -198,6 +198,11 @@ class User < ActiveRecord::Base ...@@ -198,6 +198,11 @@ class User < ActiveRecord::Base
User.find_by_username(name_or_id) User.find_by_username(name_or_id)
end end
end end
def defaults
{ projects_limit: Gitlab.config.gitlab.default_projects_limit, can_create_group: Gitlab.config.gitlab.default_can_create_group, can_create_team: Gitlab.config.gitlab.default_can_create_team }
end
end end
# #
......
...@@ -46,7 +46,7 @@ module API ...@@ -46,7 +46,7 @@ module API
authenticated_as_admin! authenticated_as_admin!
required_attributes! [:email, :password, :name, :username] required_attributes! [:email, :password, :name, :username]
attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio] attrs = User.defaults.merge(attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio])
user = User.new attrs, as: :admin user = User.new attrs, as: :admin
if user.save if user.save
present user, with: Entities::User present user, with: Entities::User
......
...@@ -57,6 +57,17 @@ describe API::API do ...@@ -57,6 +57,17 @@ describe API::API do
response.status.should == 201 response.status.should == 201
end end
it "creating a user should respect default project limit" do
limit = 123456
Gitlab.config.gitlab.stub(:default_projects_limit).and_return(limit)
attr = attributes_for(:user )
expect {
post api("/users", admin), attr
}.to change { User.count }.by(1)
User.find_by_username(attr[:username]).projects_limit.should == limit
Gitlab.config.gitlab.unstub(:default_projects_limit)
end
it "should not create user with invalid email" do it "should not create user with invalid email" do
post api("/users", admin), { email: "invalid email", password: 'password' } post api("/users", admin), { email: "invalid email", password: 'password' }
response.status.should == 400 response.status.should == 400
......
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