-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from hitobito/#2147_siblings-in-layer
PEOPLE: Geschwister in Abteilung als computed value
- Loading branch information
Showing
19 changed files
with
220 additions
and
14 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
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
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,33 @@ | ||
# Copyright (c) 2023, Pfadibewegung Schweiz. This file is part of | ||
# hitobito_pbs 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_pbs. | ||
|
||
class Person::FamilyMemberFinder | ||
attr_reader :person | ||
|
||
def initialize(person) | ||
@person = person | ||
end | ||
|
||
def family_members_in_layer(group, kind: :sibling) | ||
Role.joins(person: :family_members) | ||
.where(group: group.groups_in_same_layer, | ||
person: { family_members: { kind: kind, other: person } }) | ||
end | ||
|
||
def family_members_in_event(event, kind: :sibling) | ||
Event::Participation.joins(person: :family_members) | ||
.where(person: { family_members: { kind: kind, other: person } }, | ||
event: event) | ||
end | ||
|
||
def family_members_in_context(context, kind: :sibling) | ||
case context | ||
when Event | ||
family_members_in_event(context, kind: kind) | ||
when Group | ||
family_members_in_layer(context, kind: kind) | ||
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
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
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
5 changes: 5 additions & 0 deletions
5
db/migrate/20230912120642_remove_brother_and_sister_from_persons.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,5 @@ | ||
class RemoveBrotherAndSisterFromPersons < ActiveRecord::Migration[6.1] | ||
def change | ||
remove_column :people, :brother_and_sisters, :boolean, default: false, null: false | ||
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,93 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) 2017, Pfadibewegung Schweiz. This file is part of | ||
# hitobito_pbs 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_pbs. | ||
|
||
require 'spec_helper' | ||
|
||
describe Person::FamilyMemberFinder do | ||
|
||
let(:service) { described_class.new(person) } | ||
let(:person) { Fabricate(:person) } | ||
let(:sibling) { Fabricate(:person) } | ||
|
||
let!(:sibling_relation) { Fabricate(:family_member, person: person, other: sibling, kind: :sibling) } | ||
|
||
describe '#family_members_in_event' do | ||
|
||
let(:person_event) { Fabricate(:event) } | ||
let!(:person_participation) { Fabricate(:event_participation, person: person, event: person_event) } | ||
let(:sibling_event) { Fabricate(:event) } | ||
let!(:sibling_participation) { Fabricate(:event_participation, person: sibling, event: sibling_event) } | ||
|
||
subject do | ||
service.family_members_in_event(person_event, kind: :sibling) | ||
end | ||
|
||
context 'without siblings' do | ||
let!(:sibling_relation) { nil } | ||
it { is_expected.to be_empty } | ||
end | ||
|
||
context 'with siblings in different events' do | ||
it { is_expected.to be_empty } | ||
end | ||
|
||
context 'with siblings in same event' do | ||
let(:sibling_event) { person_event } | ||
it { is_expected.to contain_exactly(sibling_participation) } | ||
end | ||
|
||
context 'with siblings with deleted role in same group' do | ||
let!(:sibling_participation) { Fabricate(:event_participation, person: sibling, event: sibling_event, active: false) } | ||
it { is_expected.to be_empty } | ||
end | ||
|
||
end | ||
|
||
describe '#family_members_in_layer' do | ||
|
||
let(:layer) { Fabricate(Group::Abteilung.name) } | ||
|
||
let(:person_group) { Fabricate(Group::Pfadi.name, parent: layer)} | ||
let!(:person_role) { Fabricate(person_group.default_role.name, person: person, group: person_group) } | ||
|
||
let(:sibling_group) { Fabricate(Group::Woelfe.name, parent: layer)} | ||
let!(:sibling_role) { Fabricate(sibling_group.default_role.name, person: sibling, group: sibling_group) } | ||
|
||
subject do | ||
service.family_members_in_layer(person_group, kind: :sibling) | ||
end | ||
|
||
context 'without siblings' do | ||
let!(:sibling_relation) { nil } | ||
it { is_expected.to be_empty } | ||
end | ||
|
||
context 'with siblings in different groups' do | ||
let(:sibling_group) { Fabricate(Group::Woelfe.name, parent: Fabricate(Group::Abteilung.name))} | ||
it { is_expected.to be_empty } | ||
end | ||
|
||
context 'with siblings in same group' do | ||
let(:sibling_group) { person_group } | ||
it { is_expected.to contain_exactly(sibling_role) } | ||
end | ||
|
||
context 'with siblings in same layer' do | ||
it { is_expected.to contain_exactly(sibling_role) } | ||
end | ||
|
||
context 'with siblings with deleted role in same group' do | ||
let!(:sibling_role) do | ||
Fabricate(sibling_group.default_role.name, person: sibling, group: sibling_group, | ||
created_at: 2.months.ago, deleted_at: 1.month.ago) | ||
end | ||
it { is_expected.to be_empty } | ||
end | ||
|
||
end | ||
|
||
end |