Commit 6a0a4dfe authored by Lin Jen-Shin's avatar Lin Jen-Shin

Use delegate so that we set shared_runners_minutes_limit

from the user directly rather than from the namespace.
parent 2b71995e
......@@ -63,7 +63,7 @@ class User < ActiveRecord::Base
#
# Namespace for personal projects
has_one :namespace, -> { where type: nil }, dependent: :destroy, foreign_key: :owner_id
has_one :namespace, -> { where type: nil }, dependent: :destroy, foreign_key: :owner_id, autosave: true
# Profile
has_many :keys, -> do
......@@ -182,6 +182,8 @@ class User < ActiveRecord::Base
alias_attribute :private_token, :authentication_token
delegate :path, to: :namespace, allow_nil: true, prefix: true
delegate :shared_runners_minutes_limit, :shared_runners_minutes_limit=,
to: :namespace
accepts_nested_attributes_for :namespace
......
......@@ -40,11 +40,6 @@ module API
expose :external
# EE-only
expose :namespace, using: 'API::Entities::UserNamespace'
end
# EE-only
class UserNamespace < Grape::Entity
expose :shared_runners_minutes_limit
end
......
......@@ -32,11 +32,9 @@ module API
all_or_none_of :extern_uid, :provider
# EE
optional :namespace_attributes, type: Hash do
optional :shared_runners_minutes_limit, type: Integer, desc: 'Pipeline minutes quota for this user'
end
end
end
desc 'Get the list of users' do
success Entities::UserBasic
......@@ -175,10 +173,6 @@ module API
user_params[:password_expires_at] = Time.now if user_params[:password].present?
# EE
namespace_attributes = user_params[:namespace_attributes]
namespace_attributes[:id] = user.namespace_id if namespace_attributes
if user.update_attributes(user_params.except(:extern_uid, :provider))
present user, with: Entities::UserPublic
else
......
......@@ -426,10 +426,10 @@ describe API::Users do
end
it "updates shared_runners_minutes_limit" do
put api("/users/#{user.id}", admin), { namespace_attributes: { shared_runners_minutes_limit: 133 } }
put api("/users/#{user.id}", admin), { shared_runners_minutes_limit: 133 }
expect(response).to have_http_status(200)
expect(json_response.dig('namespace', 'shared_runners_minutes_limit'))
expect(json_response['shared_runners_minutes_limit'])
.to eq(133)
expect(user.reload.namespace.shared_runners_minutes_limit).to eq(133)
end
......
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