Commit 11cb1ac8 authored by Jiri Strojil's avatar Jiri Strojil

Merge branch 'feat/automatic-department-for-volunteers' into 'develop'

Auto assign department to volunteer

See merge request !1000
parents 1d0b5d61 14c694e5
Pipeline #63080 failed with stage
in 34 minutes and 7 seconds
......@@ -68,6 +68,7 @@ class VolunteersController < ApplicationController
if @volunteer.will_save_change_to_attribute?(:acceptance, to: 'accepted') &&
@volunteer.internal? && !@volunteer.user && @volunteer.save
auto_assign_department!
redirect_to(edit_volunteer_path(@volunteer),
notice: t('invite_sent', email: @volunteer.primary_email))
elsif @volunteer.save
......@@ -124,6 +125,13 @@ class VolunteersController < ApplicationController
private
def auto_assign_department!
return if !current_user.department_manager? || current_user.department.empty? || @volunteer.department.present?
# association
@volunteer.update(department: current_user.department.first)
end
def not_resigned
return if params[:q]
@volunteers = @volunteers.not_resigned
......
......@@ -96,6 +96,60 @@ class VolunteersTest < ApplicationSystemTestCase
assert page.has_field? 'Abschlussevaluation erhalten', checked: true
end
test 'automatically assigned department if accepted by department manager' do
volunteer = Volunteer.last
department = create :department
department_manager = create :department_manager, department: [department]
volunteer.update department: nil
volunteer.undecided!
login_as department_manager
visit edit_volunteer_path volunteer
select 'Akzeptiert', from: 'Prozess'
click_button 'Freiwillige/n aktualisieren', match: :first
assert volunteer.reload.accepted?
assert_equal volunteer.reload.department, department
end
test 'department will not be automatically assigned if already selected' do
volunteer = create :volunteer, acceptance: :undecided, waive: false
department1 = create :department
department2 = create :department
department_manager = create :department_manager, department: [department1, department2]
volunteer.update department: department2
login_as department_manager
visit edit_volunteer_path volunteer
select 'Akzeptiert', from: 'Prozess'
click_button 'Freiwillige/n aktualisieren', match: :first
assert volunteer.reload.accepted?
assert_equal volunteer.reload.department, department2
end
test 'department should not be assigned if accepted by superadmin' do
volunteer = create :volunteer, acceptance: :undecided, waive: false
department = create :department
@user.update(department: [department])
volunteer.update department: nil
volunteer.undecided!
login_as @user
visit edit_volunteer_path volunteer
select 'Akzeptiert', from: 'Prozess'
click_button 'Freiwillige/n aktualisieren', match: :first
assert volunteer.reload.accepted?
assert_nil volunteer.reload.department
end
test 'volunteer checklist has default values (false)' do
visit new_volunteer_path
select('Frau', from: 'Anrede')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment