Commit 192be216 authored by Tugce Nur Tas's avatar Tugce Nur Tas
Browse files

prevent group assignment from deleting if quittiert and update tests and views related to it

parent 0256fd38
......@@ -3,8 +3,8 @@ class GroupAssignment < ApplicationRecord
include GroupAssignmentCommon
after_save :update_group_offer_search_field
after_update :handle_archive_after_update_or_destroy, if: :dates_updated_or_termination_verified?
before_destroy :handle_archive_after_update_or_destroy
after_update :save_group_assignment_logs, if: :dates_updated?
before_destroy :create_log_of_self_and_delete_self
has_many :group_assignment_logs
......@@ -34,6 +34,7 @@ class GroupAssignment < ApplicationRecord
end
def create_log_of_self(start_date = period_start, end_date = period_end)
return false if running? # prevent deleting of running group assignment
GroupAssignmentLog.create!(
attributes.except('id', 'created_at', 'updated_at', 'active')
.merge(title: group_offer.title, group_assignment_id: id, period_start: start_date,
......@@ -67,17 +68,12 @@ class GroupAssignment < ApplicationRecord
private
def handle_archive_after_update_or_destroy
if !saved_change_to_termination_verified_by_id?(from: nil)
create_log_of_self(period_start_before_last_save, period_end_before_last_save)
elsif create_log_of_self && !running?
delete
end
def create_log_of_self_and_delete_self
delete if create_log_of_self
end
def dates_updated_or_termination_verified?
saved_change_to_period_start? || saved_change_to_period_end? ||
saved_change_to_termination_verified_by_id?(from: nil)
def dates_updated?
saved_change_to_period_start? || saved_change_to_period_end?
end
def update_group_offer_search_field
......
......@@ -5,7 +5,8 @@ nav.navbar.section-navigation.hidden-print
ul.list-inline
li= button_link 'Zurück zu Gruppenangeboten', group_offers_path, dimension: :sm
li= button_link 'Filter aufheben',
terminated_index_group_assignments_path(q: { termination_verified_by_id_null: 'true' }), dimension: :sm
terminated_index_group_assignments_path(q: { termination_verified_by_id_null: 'true' }),
dimension: :sm
= custom_filter_dropdown('Ende Bestätigt',
{ q: :termination_submitted_by_id_not_null, text: 'Bestätigt', value: 'true' },
{ q: :termination_submitted_by_id_null, text: 'Unbestätigt', value: 'true' })
......@@ -52,11 +53,9 @@ nav.navbar.section-navigation.hidden-print
= link_to 'Freiwillige/n beenden', '#'
- if policy(GroupAssignment).verify_termination?
td
- if assignment.termination_verified_by.blank?
= link_to 'Beendigung Quittieren', verify_termination_group_assignment_path(assignment),
class: 'btn btn-default',
data: { method: 'PATCH' }
- else
= "Quittiert von "
= link_to assignment.termination_verified_by.full_name, profile_link(assignment.termination_verified_by)
= " am #{l(assignment.termination_verified_at.to_date)}"
= link_to_if(assignment.termination_verified_by.blank?, 'Beendigung Quittieren',
verify_termination_group_assignment_path(assignment), class: 'btn btn-default',
data: { method: 'PATCH' }) do
= "Quittiert von "
= link_to assignment.termination_verified_by.full_name, profile_link(assignment.termination_verified_by)
= " am #{l(assignment.termination_verified_at.to_date)}"
......@@ -75,7 +75,7 @@ h2= @group_offer.title
h2 Aktuelle Gruppeneinsätze
= render 'group_assignments_index', group_assignments: @group_offer.group_assignments, redirect_to_action: :show
- if @group_offer.group_assignment_logs.any?
- if @group_offer.group_assignments.ended.any?
h2 Archivierte Gruppeneinsätze
.table-responsive.log-table.m-b-20
table.table.table-no-border-top
......@@ -88,21 +88,19 @@ h2= @group_offer.title
th Beendet
th Archiviert am
tbody
- @group_offer.group_assignment_logs.order('created_at desc').each do |ga_log|
- @group_offer.group_assignments.ended.each do |ga|
tr
td= link_to_if(policy(Volunteer).show?, ga_log.volunteer.contact.full_name,
volunteer_path(ga_log.volunteer)) { ga_log.volunteer.contact.full_name }
td= ga_log.responsible ? t_attr(:responsible, GroupAssignment) : t_attr(:member, GroupAssignment)
td= l(ga_log.period_start) if ga_log.period_start
td= l(ga_log.period_end) if ga_log.period_end
td= link_to_if(policy(Volunteer).show?, ga.volunteer.contact.full_name,
volunteer_path(ga.volunteer)) { ga.volunteer.contact.full_name }
td= ga.responsible ? t_attr(:responsible, GroupAssignment) : t_attr(:member, GroupAssignment)
td= l(ga.period_start) if ga.period_start
td= l(ga.period_end) if ga.period_end
td= ga.termination_verified_by.blank? ? boolean_glyph(false) : boolean_glyph(true)
td
- if ga_log.termination_verified_by.blank?
= boolean_glyph(false)
- else
- if ga.termination_verified_by.present?
= "Quittiert von "
= link_to ga_log.termination_verified_by.full_name, profile_link(ga_log.termination_verified_by)
= " am #{l(ga_log.termination_verified_at.to_date)}"
td= l(ga_log.created_at)
= link_to ga.termination_verified_by.full_name, profile_link(ga.termination_verified_by)
= " am #{l(ga.termination_verified_at.to_date)}"
- unless params[:format] == 'pdf'
= form_navigation_btn :edit
......
......@@ -80,7 +80,7 @@ class GroupAssignmentTerminationIndexTest < ApplicationSystemTestCase
page.find_all('a', text: 'Beendigung Quittieren').first.click
click_link 'Beendigung Quittieren'
assert page.has_text? 'Beendete Begleitungen'
assert page.has_text? 'Beendete Gruppen Begleitungen'
refute page.has_text? termination_index_table_text(@un_submitted)
refute page.has_text? termination_index_table_text(@submitted)
refute page.has_text? termination_index_table_text(@verified)
......@@ -118,9 +118,9 @@ class GroupAssignmentTerminationIndexTest < ApplicationSystemTestCase
end
test 'group_assignment_quittieren_creates_a_group_assignment_log_record_from_group_assignment' do
visit terminated_index_group:assignments_path(q: { termination_verified_by_id_null: 'true' })
visit terminated_index_group_assignments_path(q: { termination_verified_by_id_null: 'true' })
click_link 'Beendigung Quittieren', href: verify_termination_group_assignment_path(@submitted.id)
assert page.has_text? 'Der Einsatz wurde erfolgreich quittiert.'
assert page.has_text? 'Der Gruppeneinsatz wurde erfolgreich quittiert.'
assert_equal @submitted, GroupAssignmentLog.find_by(group_assignment_id: @submitted.id).group_assignment
end
......@@ -147,9 +147,9 @@ class GroupAssignmentTerminationIndexTest < ApplicationSystemTestCase
href: reminder_mailing_path(@un_submitted.reminder_mailings.termination.last)
click_link 'Beendigung Quittieren', href: /group_assignments\/#{@un_submitted.id}\/verify_termination/
assert page.has_text? 'Der Einsatz wurde erfolgreich quittiert.'
assert page.has_text? 'Der Gruppeneinsatz wurde erfolgreich quittiert.'
visit terminated_index_assignments_path(q: { termination_verified_by_id_not_null: 'true' })
visit terminated_index_group_assignments_path(q: { termination_verified_by_id_not_null: 'true' })
@un_submitted.reload
assert page.has_text? "Quittiert von #{@un_submitted.termination_verified_by.full_name} am"\
" #{I18n.l(@un_submitted.termination_verified_at.to_date)}"
......
......@@ -45,8 +45,7 @@ class RemoveVolunteerGroupOffersTest < ApplicationSystemTestCase
within '.log-table' do
assert page.has_text? "#{@ga1.volunteer.contact.full_name} "\
"#{@ga1.responsible ? 'Responsible' : 'Member'} #{I18n.l(@ga1.period_start)} "
assert page.has_text? I18n.l(@ga1.group_assignment_logs.first.created_at)
refute page.has_text? I18n.l(@ga1.period_end)
assert page.has_text? I18n.l(@ga1.period_end)
end
end
......
Supports Markdown
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