-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Switch Stammsektion Wizard (#605)
- Loading branch information
1 parent
51d26eb
commit 9b926ad
Showing
30 changed files
with
793 additions
and
96 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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2012-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 Memberships | ||
module Constraints | ||
def for_self_if_active_member_or_backoffice | ||
active_member? && (for_self? || backoffice?) | ||
end | ||
|
||
def backoffice? | ||
user_context.user.backoffice? | ||
end | ||
|
||
def for_self? | ||
subject.person == user_context.user | ||
end | ||
|
||
def active_member? | ||
People::SacMembership.new(subject.person).active? | ||
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
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2012-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 Memberships | ||
class SwitchStammsektionAbility < AbilityDsl::Base | ||
include Memberships::Constraints | ||
|
||
on(Wizards::Memberships::SwitchStammsektion) do | ||
permission(:any).may(:create).for_self_if_active_member_or_backoffice | ||
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
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
52 changes: 52 additions & 0 deletions
52
app/controllers/memberships/switch_stammsektions_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,52 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2012-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 Memberships | ||
class SwitchStammsektionsController < Wizards::BaseController | ||
before_action :wizard, :person, :group, :authorize | ||
|
||
helper_method :group, :person | ||
alias_method :entry, :wizard | ||
|
||
private | ||
|
||
def authorize | ||
authorize!(:create, wizard) | ||
end | ||
|
||
def wizard | ||
@wizard ||= model_class.new( | ||
person: person, | ||
current_step: params[:step].to_i, | ||
backoffice: current_user.backoffice?, | ||
**model_params.to_unsafe_h | ||
) | ||
end | ||
|
||
def model_class | ||
Wizards::Memberships::SwitchStammsektion | ||
end | ||
|
||
def success_message | ||
roles_count = wizard.switch_operation.affected_people.count | ||
t(".success", count: roles_count, group_name: wizard.choose_sektion.group.to_s, switch_date: wizard.choose_date.switch_on_text) | ||
end | ||
|
||
# NOTE: format: :html is required otherwise it is redirect as turbo_stream | ||
def redirect_target | ||
person_path(person, format: :html) | ||
end | ||
|
||
def person | ||
@person ||= Person.find(params[:person_id]) | ||
end | ||
|
||
def group | ||
@group ||= Group.find(params[:group_id]) | ||
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
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,17 @@ | ||
# 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::Memberships | ||
class SwitchStammsektion < Sheet::Base | ||
self.parent_sheet = Sheet::Person | ||
|
||
def initialize(*args) | ||
super | ||
@title = I18n.t(".title", scope: self.class.to_s.underscore) # rubocop:disable Rails/HelperInstanceVariable | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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 Memberships | ||
class SwitchStammsektionMailer < ApplicationMailer | ||
CONFIRMATION = "memberships_switch_stammsektion_confirmation" | ||
|
||
def confirmation(person, sektion, switch_on_text) | ||
values = [ | ||
%W[person-name #{person}], | ||
%W[group-name #{sektion}], | ||
%W[switch-date #{switch_on_text}] | ||
].to_h | ||
custom_headers = {cc: Group::Geschaeftsstelle.first.email} | ||
custom_content_mail([person], CONFIRMATION, values, custom_headers) | ||
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
Oops, something went wrong.