diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 00:09:30 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 00:09:30 +0000 |
commit | 060c842402c00f830a810702600cbe39dfa6cf62 (patch) | |
tree | 743bd65ac0c1d4d6518ae8cdd4af5718ec7fb890 /app/models | |
parent | 6867eff1f997a881cd3ea64109f7ba2d4b42fde4 (diff) | |
download | gitlab-ce-060c842402c00f830a810702600cbe39dfa6cf62.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/environment.rb | 4 | ||||
-rw-r--r-- | app/models/users_statistics.rb | 57 |
2 files changed, 46 insertions, 15 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index 23c2296688d..b2391f33aca 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -119,6 +119,10 @@ class Environment < ApplicationRecord find_or_create_by(name: name) end + def self.valid_states + self.state_machine.states.map(&:name) + end + class << self ## # This method returns stop actions (jobs) for multiple environments within one diff --git a/app/models/users_statistics.rb b/app/models/users_statistics.rb index 5b4c0ef37d0..1a500717efd 100644 --- a/app/models/users_statistics.rb +++ b/app/models/users_statistics.rb @@ -12,21 +12,48 @@ class UsersStatistics < ApplicationRecord :blocked ].freeze - private - - def highest_role_stats - return unless Feature.enabled?(:users_statistics) - - { - owner: batch_count_for_access_level(Gitlab::Access::OWNER), - maintainer: batch_count_for_access_level(Gitlab::Access::MAINTAINER), - developer: batch_count_for_access_level(Gitlab::Access::DEVELOPER), - reporter: batch_count_for_access_level(Gitlab::Access::REPORTER), - guest: batch_count_for_access_level(Gitlab::Access::GUEST) - } - end + class << self + def create_current_stats! + stats_by_role = highest_role_stats + + create!( + without_groups_and_projects: without_groups_and_projects_stats, + with_highest_role_guest: stats_by_role[:guest], + with_highest_role_reporter: stats_by_role[:reporter], + with_highest_role_developer: stats_by_role[:developer], + with_highest_role_maintainer: stats_by_role[:maintainer], + with_highest_role_owner: stats_by_role[:owner], + bots: bot_stats, + blocked: blocked_stats + ) + end + + private + + def highest_role_stats + { + owner: batch_count_for_access_level(Gitlab::Access::OWNER), + maintainer: batch_count_for_access_level(Gitlab::Access::MAINTAINER), + developer: batch_count_for_access_level(Gitlab::Access::DEVELOPER), + reporter: batch_count_for_access_level(Gitlab::Access::REPORTER), + guest: batch_count_for_access_level(Gitlab::Access::GUEST) + } + end + + def without_groups_and_projects_stats + batch_count_for_access_level(nil) + end + + def bot_stats + Gitlab::Database::BatchCount.batch_count(User.bots) + end + + def blocked_stats + Gitlab::Database::BatchCount.batch_count(User.blocked) + end - def batch_count_for_access_level(access_level) - Gitlab::Database::BatchCount.batch_count(UserHighestRole.with_highest_access_level(access_level)) + def batch_count_for_access_level(access_level) + Gitlab::Database::BatchCount.batch_count(UserHighestRole.with_highest_access_level(access_level)) + end end end |