Fixed #5041 with new User method to find total accounts excluding closed and invitations

This commit is contained in:
Marc Burt 2014-10-16 15:49:29 +01:00
parent b991ffe455
commit 9f5131b6ec
5 changed files with 37 additions and 3 deletions

View file

@ -127,6 +127,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a
* Fix localization of post and comment timestamps on mobile [#5482](https://github.com/diaspora/diaspora/issues/5482) * Fix localization of post and comment timestamps on mobile [#5482](https://github.com/diaspora/diaspora/issues/5482)
* Fix mobile JS loading to quieten errors. Fixes also service buttons on mobile bookmarklet. * Fix mobile JS loading to quieten errors. Fixes also service buttons on mobile bookmarklet.
* Don't error out when adding a too long location to the profile [#5614](https://github.com/diaspora/diaspora/pull/5614) * Don't error out when adding a too long location to the profile [#5614](https://github.com/diaspora/diaspora/pull/5614)
* Total user statistic no longer includes closed accounts [#5041](https://github.com/diaspora/diaspora/pull/5041)
## Features ## Features
* Don't pull jQuery from a CDN by default [#5105](https://github.com/diaspora/diaspora/pull/5105) * Don't pull jQuery from a CDN by default [#5105](https://github.com/diaspora/diaspora/pull/5105)

View file

@ -522,6 +522,11 @@ class User < ActiveRecord::Base
end end
end end
def self.total_users
User.joins(:person).where(:people => {:closed_account => false}).where.not(:username => nil)
end
private private
def clearable_fields def clearable_fields
self.attributes.keys - ["id", "username", "encrypted_password", self.attributes.keys - ["id", "username", "encrypted_password",

View file

@ -20,6 +20,21 @@ class StatisticsPresenter
'registrations_open' => open_registrations?, 'registrations_open' => open_registrations?,
'services' => available_services 'services' => available_services
} }
if AppConfig.privacy.statistics.user_counts?
result['total_users'] = User.total_users.count
result['active_users_halfyear'] = User.halfyear_actives.count
result['active_users_monthly'] = User.monthly_actives.count
end
if AppConfig.privacy.statistics.post_counts?
result['local_posts'] = self.local_posts
end
if AppConfig.privacy.statistics.comment_counts?
result['local_comments'] = self.local_comments
end
result["services"] = Configuration::KNOWN_SERVICES.select {|service| AppConfig["services.#{service}.enable"]}.map(&:to_s)
Configuration::KNOWN_SERVICES.each do |service, options|
result[service.to_s] = AppConfig["services.#{service}.enable"]
end end
def name def name

View file

@ -1077,5 +1077,18 @@ describe User, :type => :model do
@user.after_database_authentication @user.after_database_authentication
expect(@user.remove_after).to eq(nil) expect(@user.remove_after).to eq(nil)
end end
describe "total_users" do
before do
@user1 = FactoryGirl.build(:user, :username => nil)
@user1.save(:validate => false)
@user2 = FactoryGirl.create(:user)
@user2.person.closed_account = true
@user2.save
end
it "returns total_users excluding closed accounts & users without usernames" do
expect(User.total_users.count).to eq 5 #5 users from fixtures
end
end end
end end

View file

@ -51,8 +51,8 @@ describe StatisticsPresenter do
"name" => AppConfig.settings.pod_name, "name" => AppConfig.settings.pod_name,
"network" => "Diaspora", "network" => "Diaspora",
"version" => AppConfig.version_string, "version" => AppConfig.version_string,
"registrations_open" => AppConfig.settings.enable_registrations?, "registrations_open" => AppConfig.settings.enable_registrations,
"total_users" => User.count, "total_users" => User.total_users.count,
"active_users_halfyear" => User.halfyear_actives.count, "active_users_halfyear" => User.halfyear_actives.count,
"active_users_monthly" => User.monthly_actives.count, "active_users_monthly" => User.monthly_actives.count,
"local_posts" => @presenter.local_posts, "local_posts" => @presenter.local_posts,