OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/models/user/status_options.rb

43 lines
1.3 KiB

class User
module StatusOptions
module_function
##
# @param extra [Hash] A hash containing extra entries with a count for each.
# For example: { random: 42 }
# @return [Hash[Symbol, Integer]] A hash mapping each status symbol (such as :active, :blocked,
# etc.) to its count (e.g. { active: 1, blocked: 5, random: 42).
def user_statuses_with_count(extra: {})
user_count_by_status(extra: extra)
.compact
.to_h
end
def user_count_by_status(extra: {})
counts = User.not_builtin.group(:status).count.to_hash
counts
.merge(symbolic_user_counts)
.merge(extra)
.reject { |_, v| v.nil? } # remove nil counts to support dropping counts via extra
.map do |k, v|
known_status = Principal::STATUSES.detect { |_, i| i == k }
if known_status
[known_status.first, v]
else
[k, v]
end
end
.to_h
end
def symbolic_user_counts
{
blocked: User.not_builtin.blocked.count, # not_builtin to skip DeletedUser
all: User.not_builtin.count,
active: User.not_builtin.active.not_blocked.count # not_builtin to skip Anonymous and System users
}
end
end
end