Verified Commit 51f5ac51 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

fix only reasonable group_offers have end link

parent 6818d9dc
......@@ -34,6 +34,7 @@ module GroupAssignmentAndAssignmentCommon
scope :started_ca_six_weeks_ago, lambda {
start_at_or_after(8.weeks.ago).start_at_or_before(6.weeks.ago)
}
scope :no_start_and_end, (-> { no_start.no_end })
scope :with_hours, (-> { joins(:hours) })
......@@ -42,7 +43,7 @@ module GroupAssignmentAndAssignmentCommon
}
scope :active, (-> { not_ended.started.or(no_start.end_in_future) })
scope :stay_active, (-> { active.no_end })
scope :inactive, (-> { ended.or(no_start.no_end).or(will_start) })
scope :inactive, (-> { ended.or(no_start_and_end).or(will_start) })
scope :active_between, lambda { |start_date, end_date|
no_end.start_before(end_date)
.or(start_before(end_date).end_after(start_date))
......
......@@ -33,11 +33,10 @@ class GroupOffer < ApplicationRecord
validates :necessary_volunteers, numericality: { greater_than: 0 }, allow_nil: true
validates :period_end, absence: {
message: lambda { |object, _|
'Dieses Gruppenangebot kann noch nicht beendet werden, da es noch '\
"#{object.group_assignments.running.count} laufende Gruppeneinsätze hat."
}
},
if: :running_assignments?
'Dieses Gruppenangebot kann noch nicht beendet werden, da es noch '\
"#{object.group_assignments.running.count} laufende Gruppeneinsätze hat."
}
}, if: :running_assignments?
scope :active, (-> { where(active: true) })
scope :inactive, (-> { where(active: false) })
......@@ -52,6 +51,10 @@ class GroupOffer < ApplicationRecord
group_assignments.active_between(start_date, end_date).any?
end
def endable?
group_assignments.have_start.any? || group_assignment_logs.any?
end
def all_group_assignments_ended_within?(date_range)
ended_within = group_assignments.end_within(date_range).ids
not_end_before = group_assignments.end_after(date_range.last).ids
......
......@@ -93,7 +93,7 @@ table.table.table-striped
= link_to t_action(:show), group_offer_path(offer)
= link_to t('download'), group_offer_path(offer, format: :pdf)
= link_to t_action(:edit), edit_group_offer_path(offer)
- if offer.period_end.blank?
- if offer.period_end.blank? && offer.endable?
= 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?, 'Beenden', initiate_termination_group_offer_path(offer)) { '' }
......
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