Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow managers to create and manage event participations of their man…
…ageds Most of the changes here can use the new for_self_or_manageds mechanism. But when a condition combines her_own_or_something_else, then we must manually add the manager option, to make sure that the manager only inherits the her_own part, not the something_else part. Refs hitobito/hitobito#1967
- Loading branch information
1 parent
8d9b8cc
commit b059b0a
Showing
10 changed files
with
330 additions
and
2 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,19 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of | ||
# hitobito_youth 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_youth. | ||
|
||
module Youth::Event::ApplicationAbility | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
on(Event::Application) do | ||
for_self_or_manageds do | ||
# abilities which managers inherit from their managed children | ||
permission(:any).may(:show_priorities, :show_approval).her_own | ||
end | ||
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,19 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of | ||
# hitobito_youth 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_youth. | ||
|
||
module Youth::Event::InvitationAbility | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
on(Event::Invitation) do | ||
for_self_or_manageds do | ||
# abilities which managers inherit from their managed children | ||
permission(:any).may(:decline).own_invitation | ||
end | ||
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
19 changes: 19 additions & 0 deletions
19
app/abilities/youth/event/participation_contact_data_ability.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,19 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of | ||
# hitobito_youth 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_youth. | ||
|
||
module Youth::Event::ParticipationContactDataAbility | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
on(Event::ParticipationContactData) do | ||
for_self_or_manageds do | ||
# abilities which managers inherit from their managed children | ||
permission(:any).may(:show, :update).her_own | ||
end | ||
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,43 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of | ||
# hitobito_youth 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_youth. | ||
|
||
require 'spec_helper' | ||
|
||
describe Event::ApplicationAbility do | ||
|
||
let(:applicant) { Fabricate(:person) } | ||
let(:manager) { Fabricate(:person) } | ||
let!(:manager_relation) { PeopleManager.create(manager: manager, managed: applicant) } | ||
|
||
let(:course) { Fabricate(:course) } | ||
let(:application) { Fabricate(:event_application, priority_1: course, priority_2: nil) } | ||
let!(:participation) { Fabricate(:event_participation, event: course, application: application, person: applicant) } | ||
|
||
subject { Ability.new(user) } | ||
|
||
[:show_priorities, :show_approval].each do |ability| | ||
context ability.to_s do | ||
|
||
context 'for self' do | ||
let(:user) { applicant } | ||
it { is_expected.to be_able_to ability, application } | ||
end | ||
|
||
context 'for manager' do | ||
let(:user) { manager } | ||
it { is_expected.to be_able_to ability, application } | ||
end | ||
|
||
context 'for unrelated user' do | ||
let(:user) { Fabricate(:person) } | ||
it { is_expected.not_to be_able_to ability, application } | ||
end | ||
|
||
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,40 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of | ||
# hitobito_youth 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_youth. | ||
|
||
require 'spec_helper' | ||
|
||
describe Event::InvitationAbility do | ||
|
||
let(:invitee) { Fabricate(:person) } | ||
let(:manager) { Fabricate(:person) } | ||
let!(:manager_relation) { PeopleManager.create(manager: manager, managed: invitee) } | ||
|
||
let(:course) { Fabricate(:course) } | ||
let(:invitation) { Fabricate(:event_invitation, event: course, person: invitee) } | ||
|
||
subject { Ability.new(user) } | ||
|
||
context 'decline' do | ||
|
||
context 'for self' do | ||
let(:user) { invitee } | ||
it { is_expected.to be_able_to :decline, invitation } | ||
end | ||
|
||
context 'for manager' do | ||
let(:user) { manager } | ||
it { is_expected.to be_able_to :decline, invitation } | ||
end | ||
|
||
context 'for unrelated user' do | ||
let(:user) { Fabricate(:person) } | ||
it { is_expected.not_to be_able_to :decline, invitation } | ||
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
49 changes: 49 additions & 0 deletions
49
spec/abilities/event/participation_contact_data_ability_spec.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,49 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of | ||
# hitobito_youth 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_youth. | ||
|
||
require 'spec_helper' | ||
|
||
describe Event::ParticipationContactDataAbility do | ||
|
||
let(:participant) { Fabricate(:person) } | ||
let(:manager) { Fabricate(:person) } | ||
let!(:manager_relation) { PeopleManager.create(manager: manager, managed: participant) } | ||
|
||
let(:course) { Fabricate(:course) } | ||
let(:participation) { Fabricate(:event_participation, event: course, person: participant) } | ||
let(:attributes) do | ||
h = ActiveSupport::HashWithIndifferentAccess.new | ||
h.merge({ first_name: 'John', last_name: 'Gonzales', | ||
email: 'somebody@example.com', | ||
nickname: '' }) | ||
end | ||
let(:participation_contact_data) { Event::ParticipationContactData.new(course, participant, attributes) } | ||
|
||
subject { Ability.new(user) } | ||
|
||
[:show, :update].each do |ability| | ||
context ability.to_s do | ||
|
||
context 'for self' do | ||
let(:user) { participant } | ||
it { is_expected.to be_able_to ability, participation_contact_data } | ||
end | ||
|
||
context 'for manager' do | ||
let(:user) { manager } | ||
it { is_expected.to be_able_to ability, participation_contact_data } | ||
end | ||
|
||
context 'for unrelated user' do | ||
let(:user) { Fabricate(:person) } | ||
it { is_expected.not_to be_able_to ability, participation_contact_data } | ||
end | ||
|
||
end | ||
end | ||
|
||
end |