Commit 2b71995e authored by Lin Jen-Shin's avatar Lin Jen-Shin

Add shared_runners_minutes_limit to groups and users API

parent ffaccec7
......@@ -38,6 +38,14 @@ module API
expose :can_create_project?, as: :can_create_project
expose :two_factor_enabled?, as: :two_factor_enabled
expose :external
# EE-only
expose :namespace, using: 'API::Entities::UserNamespace'
end
# EE-only
class UserNamespace < Grape::Entity
expose :shared_runners_minutes_limit
end
class UserWithPrivateDetails < UserPublic
......@@ -181,6 +189,9 @@ module API
class GroupDetail < Group
expose :projects, using: Entities::Project
expose :shared_projects, using: Entities::Project
# EE-only
expose :shared_runners_minutes_limit
end
class RepoCommit < Grape::Entity
......
......@@ -17,6 +17,7 @@ module API
optional :membership_lock, type: Boolean, desc: 'Prevent adding new members to project membership within this group'
optional :ldap_cn, type: String, desc: 'LDAP Common Name'
optional :ldap_access, type: Integer, desc: 'A valid access level'
optional :shared_runners_minutes_limit, type: Integer, desc: 'Pipeline minutes quota for this group'
all_or_none_of :ldap_cn, :ldap_access
end
......@@ -118,8 +119,8 @@ module API
optional :name, type: String, desc: 'The name of the group'
optional :path, type: String, desc: 'The path of the group'
use :optional_params
at_least_one_of :name, :path, :description, :visibility,
:lfs_enabled, :request_access_enabled
at_least_one_of(*@declared_params.flatten - [:id])
end
put ':id' do
group = find_group!(params[:id])
......
......@@ -30,6 +30,11 @@ module API
optional :skip_confirmation, type: Boolean, default: false, desc: 'Flag indicating the account is confirmed'
optional :external, type: Boolean, desc: 'Flag indicating the user is an external user'
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
......@@ -137,10 +142,8 @@ module API
optional :name, type: String, desc: 'The name of the user'
optional :username, type: String, desc: 'The username of the user'
use :optional_attributes
at_least_one_of :email, :password, :name, :username, :skype, :linkedin,
:twitter, :website_url, :organization, :projects_limit,
:extern_uid, :provider, :bio, :location, :admin,
:can_create_group, :confirm, :external
at_least_one_of(*@declared_params.flatten - [:id])
end
put ":id" do
authenticated_as_admin!
......@@ -172,6 +175,10 @@ 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
......
......@@ -272,6 +272,14 @@ describe API::Groups do
expect(response).to have_http_status(404)
end
# EE
it 'updates the group for shared_runners_minutes_limit' do
put api("/groups/#{group1.id}", user1), shared_runners_minutes_limit: 133
expect(response).to have_http_status(200)
expect(json_response['shared_runners_minutes_limit']).to eq(133)
end
end
context 'when authenticated as the admin' do
......
......@@ -425,6 +425,15 @@ describe API::Users do
expect(user.reload.external?).to be_truthy
end
it "updates shared_runners_minutes_limit" do
put api("/users/#{user.id}", admin), { namespace_attributes: { shared_runners_minutes_limit: 133 } }
expect(response).to have_http_status(200)
expect(json_response.dig('namespace', 'shared_runners_minutes_limit'))
.to eq(133)
expect(user.reload.namespace.shared_runners_minutes_limit).to eq(133)
end
it "does not update admin status" do
put api("/users/#{admin_user.id}", admin), { can_create_group: false }
expect(response).to have_http_status(200)
......
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