-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce sac section membership config, refs #472
- Loading branch information
Showing
35 changed files
with
982 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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/hitobito/hitobito_sac_cas | ||
|
||
class SacSectionMembershipConfigAbility < AbilityDsl::Base | ||
|
||
include AbilityDsl::Constraints::Group | ||
|
||
on(SacSectionMembershipConfig) do | ||
permission(:layer_and_below_full).may(:manage).in_same_layer_or_below | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/components/sac_section_membership_configs/reduction_field_rows_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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/hitobito/hitobito_sac_cas | ||
|
||
module SacSectionMembershipConfigs | ||
class ReductionFieldRowsComponent < SacMembershipConfigs::FieldRowsComponent | ||
|
||
def initialize(form:, attrs: []) | ||
super | ||
@attrs = [:sac_fee_exemption_for_honorary_members, | ||
:sac_section_fee_exemption_for_honorary_members, | ||
:sac_fee_exemption_for_benefited_members, | ||
:sac_section_fee_exemption_for_benefited_members, | ||
:reduction_amount, | ||
:reduction_required_membership_years, | ||
:reduction_required_age] | ||
|
||
end | ||
|
||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
app/components/sac_section_membership_configs/valid_from_selector_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
%ul.pagination.pagination-sm | ||
- @available_configs.each do |config| | ||
%li.page-item{ class: [active?(config) && 'active'] } | ||
= link_to_edit_config(config) | ||
%li.page-item{ class: [entry.new_record? && 'active'] } | ||
= link_new_config |
37 changes: 37 additions & 0 deletions
37
app/components/sac_section_membership_configs/valid_from_selector_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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/hitobito/hitobito_sac_cas | ||
|
||
module SacSectionMembershipConfigs | ||
class ValidFromSelectorComponent < ApplicationComponent | ||
|
||
delegate :entry, to: :helpers | ||
|
||
def initialize(available_configs:, sac_section_id:) | ||
@available_configs = available_configs | ||
@sac_section_id = sac_section_id | ||
end | ||
|
||
private | ||
|
||
def active?(config) | ||
config.id == params[:id].to_i | ||
end | ||
|
||
def link_to_edit_config(config) | ||
link_to(config.valid_from, | ||
edit_group_sac_section_membership_config_path(group_id: config.group_id, id: config.id), | ||
class: 'page-link') | ||
end | ||
|
||
def link_new_config | ||
link_to(t('sac_section_membership_configs.global.link.add'), | ||
new_group_sac_section_membership_config_path(group_id: helpers.params[:group_id]), | ||
class: 'page-link') | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
app/controllers/sac_section_membership_configs_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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/hitobito/hitobito_sac_cas | ||
|
||
class SacSectionMembershipConfigsController < CrudController | ||
self.nesting = Group | ||
self.permitted_attrs =[:valid_from, | ||
:sac_section_fee_adult, | ||
:sac_section_fee_family, | ||
:sac_section_fee_youth, | ||
:entry_fee_adult, | ||
:entry_fee_family, | ||
:entry_fee_youth, | ||
:bulletin_postage_abroad, | ||
:sac_fee_exemption_for_honorary_members, | ||
:sac_section_fee_exemption_for_honorary_members, | ||
:sac_fee_exemption_for_benefited_members, | ||
:sac_section_fee_exemption_for_benefited_members, | ||
:reduction_amount, | ||
:reduction_required_membership_years, | ||
:reduction_required_age] | ||
|
||
decorates :sac_section_membership_config | ||
helper_method :cancel_url, :available_configs, :sac_section | ||
|
||
before_action :assert_sac_section_or_ortsgruppe | ||
|
||
def index | ||
redirect_to latest_config_entry_path | ||
end | ||
|
||
def show | ||
redirect_to edit_path(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def build_entry | ||
if latest_config | ||
attrs = latest_config.attributes | ||
attrs.delete('id') | ||
attrs[:valid_from] = latest_config.valid_from + 1 | ||
else | ||
attrs = { valid_from: Time.zone.now.year } | ||
end | ||
SacSectionMembershipConfig.new(attrs) | ||
end | ||
|
||
def find_entry | ||
SacSectionMembershipConfig.find(params[:id]) | ||
end | ||
|
||
def latest_config_entry_path | ||
if latest_config | ||
edit_path(latest_config.id) | ||
else | ||
new_path | ||
end | ||
end | ||
|
||
def edit_path(id) | ||
helpers.edit_group_sac_section_membership_config_path(group_id: sac_section.id, id: id) | ||
end | ||
|
||
def new_path | ||
helpers.new_group_sac_section_membership_config_path(group_id: sac_section.id) | ||
end | ||
|
||
def cancel_url | ||
group_path(id: sac_section.id) | ||
end | ||
|
||
def available_configs | ||
@available_configs ||= | ||
SacSectionMembershipConfig.where(group_id: sac_section.id).order(:valid_from) | ||
end | ||
|
||
def latest_config | ||
available_configs.last | ||
end | ||
|
||
def sac_section | ||
@sac_section ||= fetch_sac_section | ||
end | ||
|
||
def fetch_sac_section | ||
Group.find_by(id: params[:group_id], type: model_class.group_types) | ||
end | ||
|
||
def assert_sac_section_or_ortsgruppe | ||
return if sac_section | ||
|
||
head :not_found | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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/hitobito/hitobito_sac_cas. | ||
|
||
class SacSectionMembershipConfigDecorator < ApplicationDecorator | ||
decorates SacSectionMembershipConfig | ||
|
||
def to_s | ||
"#{@object.class.model_name.human} (#{valid_from})" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas 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/hitobito/hitobito_sac_cas | ||
|
||
module Sheet | ||
class SacSectionMembershipConfig < Base | ||
self.parent_sheet = Sheet::Group | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.