diff --git a/app/abilities/sac_cas/role_ability.rb b/app/abilities/sac_cas/role_ability.rb index 76e557621..760ebcd51 100644 --- a/app/abilities/sac_cas/role_ability.rb +++ b/app/abilities/sac_cas/role_ability.rb @@ -16,6 +16,7 @@ module SacCas::RoleAbility def self_terminatable_own_role return false unless her_own + return false if abonnent? return true unless mitglied_role? !has_termination_by_section_only_role @@ -58,4 +59,6 @@ def mitglied_termination_by_section_only?(role = subject) def wizard_managed_role?(role = subject) SacCas::WIZARD_MANAGED_ROLES.include?(role.class) end + + def abonnent? = subject.is_a?(Group::AboMagazin::Abonnent) end diff --git a/config/locales/wagon.de.yml b/config/locales/wagon.de.yml index d126a97e2..5d7253a22 100644 --- a/config/locales/wagon.de.yml +++ b/config/locales/wagon.de.yml @@ -1678,6 +1678,8 @@ de: global: sac_cas/role/mitglied_common: no_permission: Für einen Austritt musst du dich an den Mitgliederdienst der Sektion wenden + group/abo_magazin/abonnent: + no_permission: "Eine Kündigung kann nur über den Mitgliederdienst des SAC erfolgen. Bitte schreibe eine E-Mail mit dem gewünschten Kündigungstermin sowie deinem Vor- und Nachnamen an mv@sac-cas.ch." sac_membership_configs: form: diff --git a/spec/abilities/sac_cas/role_ability_spec.rb b/spec/abilities/sac_cas/role_ability_spec.rb index b25ecd435..03cf0ab7f 100644 --- a/spec/abilities/sac_cas/role_ability_spec.rb +++ b/spec/abilities/sac_cas/role_ability_spec.rb @@ -54,5 +54,14 @@ def set_termination_by_section_only(role, value) expect(ability).to be_able_to(:terminate, role_zusatzsektion) end end + + context "Abo" do + let(:person) { people(:abonnent) } + let(:role_abonnent) { roles(:abonnent_alpen) } + + it "is denied when Sektion#mitglied_termination_by_section_only" do + expect(ability).not_to be_able_to(:terminate, role_abonnent) + end + end end end diff --git a/spec/features/roles/terminations_spec.rb b/spec/features/roles/terminations_spec.rb index 9f2c83c10..7f29daa13 100644 --- a/spec/features/roles/terminations_spec.rb +++ b/spec/features/roles/terminations_spec.rb @@ -8,8 +8,10 @@ require "spec_helper" describe :roles_terminations, js: true do - def visit_dialog(role) - sign_in(role.person) + let(:role) { roles(:abonnent_alpen) } + + def visit_dialog + sign_in(people(:admin)) visit history_group_person_path(group_id: role.group_id, id: role.person_id) click_link(href: /#{new_group_role_termination_path(group_id: role.group_id, role_id: role.id)}/) @@ -20,11 +22,19 @@ def visit_dialog(role) it "lists affected role and mentions person" do # when terminating the stammsektion role, the affected roles include # all zusatzektion roles as well - visit_dialog(roles(:abonnent_alpen)) + visit_dialog within(".modal-dialog") do expect(page).to have_content "SAC/CAS / Die Alpen DE / Abonnent" # roles(:mitglied) expect(page).to have_content(/Austritt.*#{roles(:abonnent_alpen).person.full_name}/) end end + + it "displays disabled button with tooltip when current_user is abonnent" do + sign_in(role.person) + visit history_group_person_path(group_id: role.group_id, id: role.person_id) + + expect(page).to have_css 'button[disabled="disabled"]', text: "Austritt" + expect(page).to have_css('div[rel="tooltip"][title="Eine Kündigung kann nur über den Mitgliederdienst des SAC erfolgen. Bitte schreibe eine E-Mail mit dem gewünschten Kündigungstermin sowie deinem Vor- und Nachnamen an mv@sac-cas.ch."]') + end end