Skip to content

Commit

Permalink
Enforce visibility of event when creating participation for oneself, …
Browse files Browse the repository at this point in the history
…refs #1967
  • Loading branch information
carlobeltrame authored and TheWalkingLeek committed Apr 28, 2023
1 parent 7ac4e32 commit 749d00f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/abilities/event/participation_ability.rb
Expand Up @@ -49,7 +49,7 @@ def her_own_or_for_participations_read_events
end

def her_own_if_application_possible
her_own && event.application_possible?
her_own && event.application_possible? && participant_can_show_event?
end

def her_own_if_application_cancelable
Expand All @@ -62,6 +62,10 @@ def participating?
event.participations.map(&:person_id).include? user.id
end

def participant_can_show_event?
participation.person && (Ability.new(participation.person).can? :show, participation.event)
end

private

def participation
Expand Down
43 changes: 43 additions & 0 deletions spec/abilities/event/participation_ability_spec.rb
@@ -0,0 +1,43 @@
# encoding: utf-8

# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of
# hitobito 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.

require 'spec_helper'

describe Event::ParticipationAbility do

let(:user) { role.person }
subject { Ability.new(user) }

context 'creating participation for herself' do
let(:participation) { Event::Participation.new(event: course, person: user) }
let(:role) { Fabricate(Group::BottomLayer::Leader.name, group: groups(:bottom_layer_one)) }

context 'in event which can be shown' do
let(:course) { Event::Course.new(groups: [groups(:bottom_layer_one)], globally_visible: false) }

it 'may create participation for herself' do
is_expected.to be_able_to(:create, participation)
end
end

context 'in globally visible event' do
let(:course) { Event::Course.new(groups: [groups(:bottom_layer_two)], globally_visible: true) }

it 'may create participation for herself' do
is_expected.to be_able_to(:create, participation)
end
end

context 'in event which cannot be shown' do
let(:course) { Event::Course.new(groups: [groups(:bottom_layer_two)], globally_visible: false) }

it 'may not create participation for herself' do
is_expected.not_to be_able_to(:create, participation)
end
end
end
end

0 comments on commit 749d00f

Please sign in to comment.