-
Notifications
You must be signed in to change notification settings - Fork 12
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 #184 from hitobito/feature/jubla-162-reduce-alumnu…
…s-management-above-flock Reduce alumnus management above flock
- Loading branch information
Showing
7 changed files
with
208 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2021-2024, Jungwacht Blauring Schweiz. This file is part of | ||
# hitobito_jubla 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_jubla. | ||
|
||
# Trimmed down version of the Jubla::Role::AlumnusManager | ||
# | ||
# This one only creates the "exiting"-role that can be filtered. It does not add | ||
# the person to the "former people"-group | ||
module Jubla::Role | ||
class LightAlumnusManager | ||
attr_reader :role, :group, :person | ||
|
||
def initialize(role) | ||
@role = role | ||
@group = role.group | ||
@person = role.person | ||
end | ||
|
||
def create | ||
create_alumnus_role if last_in_group? | ||
end | ||
|
||
def destroy | ||
destroy_alumnus_role | ||
end | ||
|
||
private | ||
|
||
def create_alumnus_role | ||
alumnus_role = group.alumnus_class.new(person: person, group: group) | ||
alumnus_role.label = role.class.label | ||
alumnus_role.save! | ||
end | ||
|
||
def destroy_alumnus_role | ||
person | ||
.roles | ||
.joins(:group) | ||
.where(group: group, type: group.alumnus_class.sti_name) | ||
.destroy_all | ||
end | ||
|
||
def last_in_group? | ||
group.roles.where(person_id: person.id).empty? | ||
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