Commit d4d4a78f834b409631b012aa555c0cb2c4e3166d
1 parent
694768e5
Exists in
master
and in
4 other branches
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
Showing
3 changed files
with
17 additions
and
1 deletions
Show diff stats
app/models/user.rb
@@ -198,6 +198,11 @@ class User < ActiveRecord::Base | @@ -198,6 +198,11 @@ class User < ActiveRecord::Base | ||
198 | User.find_by_username(name_or_id) | 198 | User.find_by_username(name_or_id) |
199 | end | 199 | end |
200 | end | 200 | end |
201 | + | ||
202 | + def defaults | ||
203 | + { 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 } | ||
204 | + end | ||
205 | + | ||
201 | end | 206 | end |
202 | 207 | ||
203 | # | 208 | # |
lib/api/users.rb
@@ -46,7 +46,7 @@ module API | @@ -46,7 +46,7 @@ module API | ||
46 | authenticated_as_admin! | 46 | authenticated_as_admin! |
47 | required_attributes! [:email, :password, :name, :username] | 47 | required_attributes! [:email, :password, :name, :username] |
48 | 48 | ||
49 | - attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio] | 49 | + attrs = User.defaults.merge(attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio]) |
50 | user = User.new attrs, as: :admin | 50 | user = User.new attrs, as: :admin |
51 | if user.save | 51 | if user.save |
52 | present user, with: Entities::User | 52 | present user, with: Entities::User |
spec/requests/api/users_spec.rb
@@ -57,6 +57,17 @@ describe API::API do | @@ -57,6 +57,17 @@ describe API::API do | ||
57 | response.status.should == 201 | 57 | response.status.should == 201 |
58 | end | 58 | end |
59 | 59 | ||
60 | + it "creating a user should respect default project limit" do | ||
61 | + limit = 123456 | ||
62 | + Gitlab.config.gitlab.stub(:default_projects_limit).and_return(limit) | ||
63 | + attr = attributes_for(:user ) | ||
64 | + expect { | ||
65 | + post api("/users", admin), attr | ||
66 | + }.to change { User.count }.by(1) | ||
67 | + User.find_by_username(attr[:username]).projects_limit.should == limit | ||
68 | + Gitlab.config.gitlab.unstub(:default_projects_limit) | ||
69 | + end | ||
70 | + | ||
60 | it "should not create user with invalid email" do | 71 | it "should not create user with invalid email" do |
61 | post api("/users", admin), { email: "invalid email", password: 'password' } | 72 | post api("/users", admin), { email: "invalid email", password: 'password' } |
62 | response.status.should == 400 | 73 | response.status.should == 400 |