Verified Commit 0e50d5c0 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

fix some stuff from review

parent 6e5e46b4
Pipeline #13815 failed with stage
in 19 minutes and 41 seconds
......@@ -22,12 +22,9 @@ class GroupAssignmentsController < ApplicationController
def update
@group_assignment.assign_attributes(group_assignment_params)
if @group_assignment.will_save_change_to_period_end? && @group_assignment.ended?
@group_assignment.period_end_set_by = current_user
period_end_set_notice = 'Einsatzende wurde erfolgreich gesetzt.'
end
period_end_set_notice, redirect_action = handle_period_end
if @group_assignment.save
create_redirect_to(period_end_set_notice)
create_redirect_to(period_end_set_notice, action: redirect_action)
else
render :edit
end
......@@ -78,9 +75,20 @@ class GroupAssignmentsController < ApplicationController
private
def create_redirect_to(notice_text = nil)
def handle_period_end
if @group_assignment.will_save_change_to_period_end?(from: nil) && @group_assignment.ending?
@group_assignment.period_end_set_by = current_user
[
'Einsatzende wurde erfolgreich gesetzt.',
params[:redirect_to] || :terminated_group_assignments_index
]
end
end
def create_redirect_to(notice_text = nil, action: nil)
action ||= params[:redirect_to] unless params[:redirect_to] == 'show'
redirect_to(
polymorphic_path(@group_assignment.group_offer, action: params[:redirect_to]),
polymorphic_path(@group_assignment.group_offer, action: action),
notice: notice_text || make_notice[:notice]
)
end
......
......@@ -84,7 +84,7 @@ class GroupOffersController < ApplicationController
def submit_initiate_termination
if @group_offer.update(period_end: group_offer_params[:period_end],
period_end_set_by: current_user)
redirect_to group_offers_path, notice: 'Gruppenangebots beendigung erfolgreich eingeleitet.'
redirect_to group_offers_path, notice: 'Gruppenangebots Beendigung erfolgreich eingeleitet.'
else
render :initiate_termination
end
......
......@@ -104,7 +104,11 @@ module GroupAssignmentAndAssignmentCommon
end
def ended?
period_start.present? && period_end.present? && period_end <= Time.zone.today
ending? && period_end <= Time.zone.today
end
def ending?
period_start.present? && period_end.present?
end
end
end
......@@ -51,7 +51,7 @@ class GroupOffer < ApplicationRecord
group_assignments.active_between(start_date, end_date).any?
end
def endable?
def terminatable?
group_assignments.have_start.any? || group_assignment_logs.any?
end
......
......@@ -96,7 +96,7 @@ table.table.table-striped
- if offer.period_end.blank?
= link_to "#{ offer.active? ? t('.deactivate') : t('.activate') }",
change_active_state_group_offer_path(offer), method: :put, remote: :true
= link_to_if(policy(offer).initiate_termination? && offer.endable?,
= link_to_if(policy(offer).initiate_termination? && offer.terminatable?,
'Beenden', initiate_termination_group_offer_path(offer)) { '' }
......
......@@ -73,7 +73,7 @@ h2= @group_offer.title
- if @group_offer.group_assignments.any?
h2 Aktuelle Gruppeneinsätze
= render 'group_assignments_index', group_assignments: @group_offer.group_assignments
= render 'group_assignments_index', group_assignments: @group_offer.group_assignments, redirect_to_action: :show
- if @group_offer.group_assignment_logs.any?
h2 Archivierte Gruppeneinsätze
......
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