Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude blocked and deleted users from participants stats #8147

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased](https://github.com/decidim/decidim/tree/HEAD)

#### Statistics change
As per [\#8147](https://github.com/decidim/decidim/pull/8147), the participants stats will not take into account deleted and blocked users.

#### Webpacker migration
As per [#7464](https://github.com/decidim/decidim/pull/7464), [#7733](https://github.com/decidim/decidim/pull/7733) Decidim has been upgraded to use Webpacker to manage its assets. It's a huge change that requires some updates in your applications. Please refer to the guide [Migrate to Webpacker an instance app](https://github.com/decidim/decidim/blob/develop/docs/modules/develop/pages/guide_migrate_webpacker_app.adoc) and follow the steps described.

Expand Down
3 changes: 1 addition & 2 deletions decidim-core/app/queries/decidim/stats_users_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ def initialize(organization, start_at = nil, end_at = nil)
end

def query
users = Decidim::User.where(organization: @organization)
users = Decidim::User.where(organization: @organization).not_deleted.not_blocked.confirmed
users = users.where("created_at >= ?", @start_at) if @start_at.present?
users = users.where("created_at <= ?", @end_at) if @end_at.present?
users = users.where.not(confirmed_at: nil)
users.count
end
end
Expand Down
10 changes: 10 additions & 0 deletions decidim-core/spec/queries/decidim/stats_users_count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@
expect(subject.query).to eq(1)
end
end

context "with blocked and deleted users" do
it "will exclude all the users blocked or with deleted account" do
create(:user, :confirmed, organization: organization, blocked: true)
create(:user, :confirmed, organization: organization, deleted_at: Time.current - 1.day)
create(:user, :confirmed, organization: organization)

expect(subject.query).to eq(1)
end
end
end