FEATURE: adds a currently away report (#234)

This commit is contained in:
Joffrey JAFFEUX 2022-02-25 15:46:45 +01:00 committed by GitHub
parent 0df5cadb13
commit 20d012516c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -45,6 +45,10 @@ en:
more_than_one_calendar: "You cant have more than one calendar in a post."
more_than_two_dates: "A post of a calendar topic cant contain more than two dates."
event_expired: "Event expired"
reports:
currently_away:
labels:
username: Username
discourse_post_event:
notifications:
before_event_reminder: "%{title} is about to start."

View File

@ -657,4 +657,23 @@ after_initialize do
register_notification_consolidation_plan(reminders_consolidation_plan)
register_notification_consolidation_plan(invitation_consolidation_plan)
Report.add_report('currently_away') do |report|
group_filter = report.filters.dig(:group) || Group::AUTO_GROUPS[:staff]
report.add_filter('group', type: 'group', default: group_filter)
return unless group = Group.find_by(id: group_filter)
report.labels = [
{
property: :username,
title: I18n.t('reports.currently_away.labels.username')
},
]
group_usernames = group.users.pluck(:username)
on_holiday_usernames = DiscourseCalendar.users_on_holiday
report.data = (group_usernames & on_holiday_usernames).map { |username| { username: username } }
report.total = report.data.count
end
end

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'currently_away report' do
fab!(:user_1) { Fabricate(:user) }
fab!(:user_2) { Fabricate(:user) }
fab!(:group_1) { Fabricate(:group) }
before do
group_1.add(user_1)
DiscourseCalendar.users_on_holiday = [user_1.username]
end
it 'generates a correct report' do
report = Report.find('currently_away', filters: { group: group_1.id })
expect(report.data).to contain_exactly({ username: user_1.username })
expect(report.total).to eq(1)
end
end