kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
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.
43 lines
1.3 KiB
43 lines
1.3 KiB
4 years ago
|
module Users
|
||
8 years ago
|
module StatusOptions
|
||
8 years ago
|
module_function
|
||
|
|
||
|
##
|
||
|
# @param extra [Hash] A hash containing extra entries with a count for each.
|
||
|
# For example: { random: 42 }
|
||
7 years ago
|
# @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).
|
||
8 years ago
|
def user_statuses_with_count(extra: {})
|
||
7 years ago
|
user_count_by_status(extra: extra)
|
||
8 years ago
|
.compact
|
||
|
.to_h
|
||
|
end
|
||
|
|
||
|
def user_count_by_status(extra: {})
|
||
7 years ago
|
counts = User.not_builtin.group(:status).count.to_hash
|
||
8 years ago
|
|
||
|
counts
|
||
|
.merge(symbolic_user_counts)
|
||
|
.merge(extra)
|
||
|
.reject { |_, v| v.nil? } # remove nil counts to support dropping counts via extra
|
||
7 years ago
|
.map do |k, v|
|
||
|
known_status = Principal::STATUSES.detect { |_, i| i == k }
|
||
|
if known_status
|
||
|
[known_status.first, v]
|
||
|
else
|
||
|
[k, v]
|
||
|
end
|
||
|
end
|
||
8 years ago
|
.to_h
|
||
|
end
|
||
|
|
||
|
def symbolic_user_counts
|
||
|
{
|
||
5 years ago
|
blocked: User.not_builtin.blocked.count, # not_builtin to skip DeletedUser
|
||
8 years ago
|
all: User.not_builtin.count,
|
||
5 years ago
|
active: User.not_builtin.active.not_blocked.count # not_builtin to skip Anonymous and System users
|
||
8 years ago
|
}
|
||
|
end
|
||
|
end
|
||
|
end
|