From 16958615054de55b48b39b90301068f91e3cc04b Mon Sep 17 00:00:00 2001 From: Lukas Grimm Date: Mon, 20 Feb 2023 13:55:53 +0100 Subject: [PATCH 1/3] added reminder for some special people --- app/controllers/employees_controller.rb | 2 +- app/jobs/worktime_reminder_job.rb | 14 ++++++++++++++ app/mailers/employee_mailer.rb | 9 +++++++++ app/views/employees/settings.html.haml | 2 ++ config/locales/models.de-CH.yml | 1 + db/schema.rb | 1 + test/controllers/employees_controller_test.rb | 3 ++- test/fixtures/employees.yml | 8 ++++++++ 8 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 app/jobs/worktime_reminder_job.rb diff --git a/app/controllers/employees_controller.rb b/app/controllers/employees_controller.rb index 07e946f7..9f744adf 100644 --- a/app/controllers/employees_controller.rb +++ b/app/controllers/employees_controller.rb @@ -38,7 +38,7 @@ def settings def update_settings @employee = @user - attrs = params.require(:employee).permit(:worktimes_commit_reminder, eval_periods: []) + attrs = params.require(:employee).permit(:worktimes_commit_reminder, :worktimes_reminder, eval_periods: []) attrs[:eval_periods] = [] if attrs[:eval_periods].blank? if @employee.update_attributes(attrs) flash[:notice] = 'Die Benutzereinstellungen wurden aktualisiert' diff --git a/app/jobs/worktime_reminder_job.rb b/app/jobs/worktime_reminder_job.rb new file mode 100644 index 00000000..78f0909b --- /dev/null +++ b/app/jobs/worktime_reminder_job.rb @@ -0,0 +1,14 @@ +# Copyright (c) 2006-2022, Puzzle ITC GmbH. This file is part of +# PuzzleTime and licensed under the Affero General Public License version 3 +# or later. See the COPYING file at the top-level directory or at +# https://github.com/puzzle/puzzletime. + +class CommitReminderJob < CronJob + self.cron_expression = '45 16 * * *' + + def perform + Employee.active_employed_last_month.where(worktimes_reminder: true).each do |employee| + EmployeeMailer.worktime_reminder_mail(employee).deliver_now + end + end +end diff --git a/app/mailers/employee_mailer.rb b/app/mailers/employee_mailer.rb index 139db27f..4ad6cb28 100644 --- a/app/mailers/employee_mailer.rb +++ b/app/mailers/employee_mailer.rb @@ -15,4 +15,13 @@ def worktime_commit_reminder_mail(employee) subject: 'PuzzleTime Zeiten freigeben' ) end + + def worktime_reminder_mail(employee) + @employee = employee + + mail( + to: "#{employee.firstname} #{employee.lastname} <#{employee.email}>", + subject: 'PuzzleTime Zeiten eintragen' + ) + end end diff --git a/app/views/employees/settings.html.haml b/app/views/employees/settings.html.haml index 8f5a4bc4..9e8f016d 100644 --- a/app/views/employees/settings.html.haml +++ b/app/views/employees/settings.html.haml @@ -13,6 +13,8 @@ = link_to 'Ändern', edit_employee_registration_path = f.labeled_input_field :worktimes_commit_reminder + + = f.labeled_input_field :worktimes_reminder = f.labeled(:eval_periods) do %table.table-condensed diff --git a/config/locales/models.de-CH.yml b/config/locales/models.de-CH.yml index 852b01c6..80f61dce 100644 --- a/config/locales/models.de-CH.yml +++ b/config/locales/models.de-CH.yml @@ -211,6 +211,7 @@ de-CH: identity_card_valid_until: Ausweis gültig bis workplace_id: Arbeitsort worktimes_commit_reminder: Freigabeerinnerung senden + worktimes_reminder: Zeiterfassungserinnerung senden employee/marital_statuses: married: Verheiratet single: Ledig diff --git a/db/schema.rb b/db/schema.rb index b75f9618..7ac3e247 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -197,6 +197,7 @@ t.datetime "updated_at", default: -> { "now()" }, null: false t.bigint "workplace_id" t.boolean "worktimes_commit_reminder", default: true, null: false + t.boolean "worktimes_reminder", default: false, null: false t.index ["department_id"], name: "index_employees_on_department_id" t.index ["shortname"], name: "chk_unique_name", unique: true t.index ["workplace_id"], name: "index_employees_on_workplace_id" diff --git a/test/controllers/employees_controller_test.rb b/test/controllers/employees_controller_test.rb index 40944715..36d520cb 100644 --- a/test/controllers/employees_controller_test.rb +++ b/test/controllers/employees_controller_test.rb @@ -16,7 +16,7 @@ def test_settings get :settings, params: test_params(id: test_entry.id) assert_response :success assert_template 'employees/settings' - assert_attrs_equal test_entry.attributes.slice(:worktimes_commit_reminder, :eval_periods) + assert_attrs_equal test_entry.attributes.slice(:worktimes_commit_reminder, :worktime_reminder, :eval_periods) end def test_update_settings @@ -89,6 +89,7 @@ def test_entry_attrs def test_settings_attrs { worktimes_commit_reminder: false, + worktimes_reminder: false, eval_periods: ["-1m", "0"] } end diff --git a/test/fixtures/employees.yml b/test/fixtures/employees.yml index 4010664b..b2dd7ed0 100644 --- a/test/fixtures/employees.yml +++ b/test/fixtures/employees.yml @@ -49,6 +49,7 @@ half_year_maria: management: true eval_periods: ["-1m", "0"] worktimes_commit_reminder: true + worktimes_reminder: true various_pedro: id: 2 @@ -60,6 +61,7 @@ various_pedro: social_insurance: 123.4567.8910.11 management: false worktimes_commit_reminder: true + worktimes_reminder: true next_year_pablo: id: 3 @@ -70,6 +72,7 @@ next_year_pablo: email: ps@bla.ch management: false worktimes_commit_reminder: true + worktimes_reminder: true left_this_year_macy: id: 4 @@ -80,6 +83,7 @@ left_this_year_macy: email: mg@bla.ch management: false worktimes_commit_reminder: true + worktimes_reminder: true long_time_john: id: 5 @@ -97,6 +101,7 @@ long_time_john: graduation: Klubschule department: devone worktimes_commit_reminder: true + worktimes_reminder: true pascal: id: 6 @@ -109,6 +114,7 @@ pascal: department: devtwo workplace: bern worktimes_commit_reminder: true + worktimes_reminder: true mark: id: 7 @@ -127,6 +133,7 @@ mark: - '-1y' workplace: jona worktimes_commit_reminder: true + worktimes_reminder: true lucien: id: 8 @@ -138,3 +145,4 @@ lucien: management: false department: devtwo worktimes_commit_reminder: true + worktimes_reminder: true From 88e088fcc195354973597d1aafe5efcd32ec1141 Mon Sep 17 00:00:00 2001 From: Lukas Grimm Date: Mon, 20 Feb 2023 16:07:52 +0100 Subject: [PATCH 2/3] add migration --- db/migrate/20230220143608_add_worktimes_reminder_to_user.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20230220143608_add_worktimes_reminder_to_user.rb diff --git a/db/migrate/20230220143608_add_worktimes_reminder_to_user.rb b/db/migrate/20230220143608_add_worktimes_reminder_to_user.rb new file mode 100644 index 00000000..0a863884 --- /dev/null +++ b/db/migrate/20230220143608_add_worktimes_reminder_to_user.rb @@ -0,0 +1,5 @@ +class AddWorktimesReminderToUser < ActiveRecord::Migration[5.2] + def change + add_column :employees, :worktimes_reminder, :boolean, default: false, null: false + end +end From fd75d0cd25cc1de777ed41b675df8ee634b1d0fb Mon Sep 17 00:00:00 2001 From: Lukas Grimm Date: Mon, 20 Feb 2023 16:16:06 +0100 Subject: [PATCH 3/3] only inform on weekdays --- app/jobs/worktime_reminder_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/worktime_reminder_job.rb b/app/jobs/worktime_reminder_job.rb index 78f0909b..86ad12e4 100644 --- a/app/jobs/worktime_reminder_job.rb +++ b/app/jobs/worktime_reminder_job.rb @@ -4,7 +4,7 @@ # https://github.com/puzzle/puzzletime. class CommitReminderJob < CronJob - self.cron_expression = '45 16 * * *' + self.cron_expression = '45 16 * * 1-5' def perform Employee.active_employed_last_month.where(worktimes_reminder: true).each do |employee|