Commit 7cabf43e authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'remove_roles_stats_method' into 'master'

Remove ProjectAuthorization.roles_stats method

Closes #213083

See merge request gitlab-org/gitlab!29120
parents 98e42f80 a3039962
...@@ -12,39 +12,6 @@ module EE ...@@ -12,39 +12,6 @@ module EE
def pluck_user_ids def pluck_user_ids
pluck(:user_id) pluck(:user_id)
end end
# Get amount of users with highest role they have.
# If John is a developer in one project but maintainer in another he will be
# counted once as maintainer. This is needed to count users who don't use
# functionality available to higher roles only.
#
# Example of result:
# [{"kind"=>"guest", "amount"=>"4"},
# {"kind"=>"reporter", "amount"=>"6"},
# {"kind"=>"developer", "amount"=>"10"},
# {"kind"=>"maintainer", "amount"=>"9"},
# {"kind"=>"owner", "amount"=>"1"}]
#
def roles_stats
connection.exec_query <<-EOF.strip_heredoc
SELECT CASE access_level
WHEN 10 THEN 'guest'
WHEN 20 THEN 'reporter'
WHEN 30 THEN 'developer'
WHEN 40 THEN 'maintainer'
WHEN 50 THEN 'owner'
ELSE 'unknown' END
AS kind,
count(*) AS amount
FROM (
SELECT user_id, max(access_level) AS access_level
FROM #{table_name}
GROUP BY user_id
) access_per_user
GROUP BY access_level
ORDER BY access_level ASC;
EOF
end
end end
end end
end end
...@@ -3,36 +3,6 @@ ...@@ -3,36 +3,6 @@
require 'spec_helper' require 'spec_helper'
describe ProjectAuthorization do describe ProjectAuthorization do
describe '.roles_stats' do
before do
project1 = create(:project_empty_repo)
project1.add_reporter(create(:user))
project2 = create(:project_empty_repo)
project2.add_developer(create(:user))
# Add same user as Reporter and Developer to different projects
# and expect it to be counted once for the stats
user = create(:user)
project1.add_reporter(user)
project2.add_developer(user)
end
subject { described_class.roles_stats.to_a }
it do
expect(amount_for_kind('reporter')).to eq(1)
expect(amount_for_kind('developer')).to eq(2)
expect(amount_for_kind('maintainer')).to eq(2)
end
def amount_for_kind(access_level)
subject.find do |row|
row['kind'] == access_level
end['amount'].to_i
end
end
describe '.visible_to_user_and_access_level' do describe '.visible_to_user_and_access_level' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project1) { create(:project) } let(:project1) { create(:project) }
......
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