Commit 316c9044 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move project authorization to ee module and add spec

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 1a64afbc
class ProjectAuthorization < ActiveRecord::Base
prepend ::EE::ProjectAuthorization
belongs_to :user
belongs_to :project
......@@ -24,21 +26,4 @@ class ProjectAuthorization < ActiveRecord::Base
EOF
end
end
def self.roles_stats
connection.execute <<-EOF.strip_heredoc
SELECT CASE max(access_level)
WHEN 10 THEN 'guest'
WHEN 20 THEN 'reporter'
WHEN 30 THEN 'developer'
WHEN 40 THEN 'master'
WHEN 50 THEN 'owner'
ELSE 'unknown' END
AS kind,
count(DISTINCT user_id) AS amount
FROM #{table_name}
GROUP BY access_level
ORDER BY amount DESC;
EOF
end
end
module EE
module ProjectAuthorization
extend ActiveSupport::Concern
module ClassMethods
def roles_stats
connection.execute <<-EOF.strip_heredoc
SELECT CASE max(access_level)
WHEN 10 THEN 'guest'
WHEN 20 THEN 'reporter'
WHEN 30 THEN 'developer'
WHEN 40 THEN 'master'
WHEN 50 THEN 'owner'
ELSE 'unknown' END
AS kind,
count(DISTINCT user_id) AS amount
FROM #{table_name}
GROUP BY access_level
ORDER BY amount DESC;
EOF
end
end
end
end
......@@ -5,7 +5,7 @@
= @admin_count
- if @roles_count
- @roles_count.reverse_each do |row|
- @roles_count.each do |row|
%p
Users with highest role
%strong
......
require 'spec_helper'
describe "Admin Dashboard" do
before do
3.times do
project = create(:project)
user = create(:user)
project.add_reporter(user)
end
2.times do
project = create(:project)
user = create(:user)
project.add_developer(user)
end
# Add same user as Reporter and Developer to different projects
# and expect it to be counted once for the stats
user = create(:user)
project1 = Project.first
project2 = Project.last
project1.add_reporter(user)
project2.add_developer(user)
sign_in(create(:admin))
end
describe 'Roles stats' do
it 'show correct amount of users per role' do
visit admin_root_path
expect(page).to have_content('Admin users 1')
expect(page).to have_content('Users with highest role developer 3')
expect(page).to have_content('Users with highest role reporter 3')
end
end
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