Commit cc76d77b authored by Imre Farkas's avatar Imre Farkas Committed by Yorick Peterse

Move EE specific lines in API::Users

parent c4f94a99
# frozen_string_literal: true
module EE
module API
module Helpers
module UsersHelpers
extend ActiveSupport::Concern
prepended do
params :optional_params_ee do
optional :shared_runners_minutes_limit, type: Integer, desc: 'Pipeline minutes quota for this user'
optional :extra_shared_runners_minutes_limit, type: Integer, desc: '(admin-only) Extra pipeline minutes quota for this user'
end
params :optional_index_params_ee do
optional :skip_ldap, type: Grape::API::Boolean, default: false, desc: 'Skip LDAP users'
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe API::Users do
let(:user) { create(:user) }
let(:admin) { create(:admin) }
context 'extended audit events' do
describe "PUT /users/:id" do
it "creates audit event when updating user with new password" do
stub_licensed_features(extended_audit_events: true)
put api("/users/#{user.id}", admin), params: { password: '12345678' }
expect(AuditEvent.count).to eq(1)
end
end
end
context 'shared_runners_minutes_limit' do
describe "PUT /users/:id" do
context 'when user is an admin' do
it "updates shared_runners_minutes_limit" do
expect do
put api("/users/#{user.id}", admin), params: { shared_runners_minutes_limit: 133 }
end.to change { user.reload.shared_runners_minutes_limit }
.from(nil).to(133)
expect(response).to have_gitlab_http_status(200)
expect(json_response['shared_runners_minutes_limit']).to eq(133)
end
end
context 'when user is not an admin' do
it "cannot update their own shared_runners_minutes_limit" do
expect do
put api("/users/#{user.id}", user), params: { shared_runners_minutes_limit: 133 }
end.not_to change { user.reload.shared_runners_minutes_limit }
expect(response).to have_gitlab_http_status(403)
end
end
end
end
end
# frozen_string_literal: true
module API
module Helpers
module UsersHelpers
extend ActiveSupport::Concern
extend Grape::API::Helpers
params :optional_params_ee do
end
params :optional_index_params_ee do
end
end
end
end
API::Helpers::UsersHelpers.prepend(EE::API::Helpers::UsersHelpers)
......@@ -15,6 +15,8 @@ module API
authenticate_non_get!
end
helpers Helpers::UsersHelpers
helpers do
# rubocop: disable CodeReuse/ActiveRecord
def find_user_by_id(params)
......@@ -52,10 +54,7 @@ module API
optional :private_profile, type: Boolean, desc: 'Flag indicating the user has a private profile'
all_or_none_of :extern_uid, :provider
if Gitlab.ee?
optional :shared_runners_minutes_limit, type: Integer, desc: 'Pipeline minutes quota for this user'
optional :extra_shared_runners_minutes_limit, type: Integer, desc: '(admin-only) Extra pipeline minutes quota for this user'
end
use :optional_params_ee
end
params :sort_params do
......@@ -85,10 +84,7 @@ module API
use :sort_params
use :pagination
use :with_custom_attributes
if Gitlab.ee?
optional :skip_ldap, type: Boolean, default: false, desc: 'Skip LDAP users'
end
use :optional_index_params_ee
end
# rubocop: disable CodeReuse/ActiveRecord
get do
......
......@@ -280,11 +280,12 @@ describe API::Users do
context "when authenticated and ldap is enabled" do
it "returns non-ldap user" do
create :omniauth_user, provider: "ldapserver1"
get api("/users", user), params: { skip_ldap: "true" }
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an Array
username = user.username
expect(json_response.first["username"]).to eq username
expect(json_response.first["username"]).to eq user.username
end
end
end
......@@ -644,13 +645,10 @@ describe API::Users do
end
it "updates user with new password and forces reset on next login" do
stub_licensed_features(extended_audit_events: true)
put api("/users/#{user.id}", admin), params: { password: '12345678' }
expect(response).to have_gitlab_http_status(200)
expect(user.reload.password_expires_at).to be <= Time.now
expect(AuditEvent.count).to eq(1)
end
it "updates user with organization" do
......@@ -740,17 +738,6 @@ describe API::Users do
expect(user.reload.private_profile).to eq(true)
end
# EE
it "updates shared_runners_minutes_limit" do
expect do
put api("/users/#{user.id}", admin), params: { shared_runners_minutes_limit: 133 }
end.to change { user.reload.shared_runners_minutes_limit }
.from(nil).to(133)
expect(response).to have_gitlab_http_status(200)
expect(json_response['shared_runners_minutes_limit']).to eq(133)
end
it "does not update admin status" do
put api("/users/#{admin_user.id}", admin), params: { can_create_group: false }
......@@ -774,14 +761,6 @@ describe API::Users do
expect(response).to have_gitlab_http_status(403)
end
it "cannot update their own shared_runners_minutes_limit" do
expect do
put api("/users/#{user.id}", user), params: { shared_runners_minutes_limit: 133 }
end.not_to change { user.reload.shared_runners_minutes_limit }
expect(response).to have_gitlab_http_status(403)
end
end
it "returns 404 for non-existing user" do
......
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