fix mass-assignment error in user create API
This commit is contained in:
parent
770ec3359d
commit
c610206321
|
@ -23,7 +23,7 @@ module Gitlab
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
present @user, with: Entities::User
|
present @user, with: Entities::User
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create user. Available only for admin
|
# Create user. Available only for admin
|
||||||
#
|
#
|
||||||
# Parameters:
|
# Parameters:
|
||||||
|
@ -40,7 +40,7 @@ module Gitlab
|
||||||
post do
|
post do
|
||||||
authenticated_as_admin!
|
authenticated_as_admin!
|
||||||
attrs = attributes_for_keys [:email, :name, :password, :password_confirmation, :skype, :linkedin, :twitter, :projects_limit]
|
attrs = attributes_for_keys [:email, :name, :password, :password_confirmation, :skype, :linkedin, :twitter, :projects_limit]
|
||||||
user = User.new attrs
|
user = User.new attrs, as: :admin
|
||||||
if user.save
|
if user.save
|
||||||
present user, with: Entities::User
|
present user, with: Entities::User
|
||||||
else
|
else
|
||||||
|
|
|
@ -4,7 +4,7 @@ describe Gitlab::API do
|
||||||
include ApiHelpers
|
include ApiHelpers
|
||||||
|
|
||||||
let(:user) { Factory :user }
|
let(:user) { Factory :user }
|
||||||
let(:admin) {Factory :admin}
|
let(:admin) { Factory :admin }
|
||||||
let(:key) { Factory :key, user: user }
|
let(:key) { Factory :key, user: user }
|
||||||
|
|
||||||
describe "GET /users" do
|
describe "GET /users" do
|
||||||
|
@ -42,9 +42,9 @@ describe Gitlab::API do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create user" do
|
it "should create user" do
|
||||||
expect{
|
expect {
|
||||||
post api("/users", admin), Factory.attributes(:user)
|
post api("/users", admin), Factory.attributes(:user, projects_limit: 3)
|
||||||
}.to change{User.count}.by(1)
|
}.to change { User.count }.by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shouldn't available for non admin users" do
|
it "shouldn't available for non admin users" do
|
||||||
|
|
Loading…
Reference in a new issue