Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pbs 271 new root group #279

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Das Anwesenheiten-Tab bei Kursen im Status "Qualifikationen erfasst" und "Abgeschlossen" wird neu mit einem Ausrufezeichen markiert, wenn die Anwesenheiten noch gespeichert werden müssen. Merci @ewangler! (hitobito/hitobito_pbs#262)
* Adressverwalter\*innen auf der Abteilungsebene können neu auch für Zugriffsanfragen ausgewählt werden. Merci @philobr! (hitobito/hitobito_pbs#261)
* Die Gruppenstruktur wurde so angepasst, dass neu Silverscouts und Silverscouts Regionen unter der "Root" Ebene erstellt werden können (hitobito_pbs#271)

## Version 1.28

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This hitobito wagon defines the organization hierarchy with groups and roles of
# Pfadi Organization Hierarchy

<!-- roles:start -->
* Root
* Root
* Admin: 2FA [:layer_and_below_full]
* Bund
* Bund
* Mitarbeiter*in GS: 2FA [:layer_and_below_full, :contact_data, :admin]
Expand Down Expand Up @@ -256,6 +259,10 @@ This hitobito wagon defines the organization hierarchy with groups and roles of
* Internes Gremium
* Leitung: [:group_and_below_full]
* Mitglied: [:group_read]
* Silverscouts
* Silverscouts
* Leitung: [:group_read, :contact_data]
* Mitglied: []
* Global
* Ehemalige
* Mitglied: []
Expand Down
2 changes: 1 addition & 1 deletion app/abilities/pbs/event/constraints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def in_same_layer_or_below_with_excluded_abteilungen_for_courses
def in_same_layer_or_course_in_below_abteilung
in_same_layer ||
(course_in_abteilung? &&
permission_in_layers?(course_group_ids_above_abteilung - [Group.root.id]))
permission_in_layers?(course_group_ids_above_abteilung - [Group.bund.id]))
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/censuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class CensusesController < CrudController
decorates :group

def create
super(location: census_bund_group_path(Group.root))
super(location: census_bund_group_path(group))
end

private

def group
@group ||= Group.root
@group ||= Group.bund
end

end
21 changes: 21 additions & 0 deletions app/models/group/root.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

# 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 Group::Root < ::Group
self.layer = true

self.event_types = [] # only managing structure, does not have events (as of 2023-05-23)

class Admin < ::Role
self.permissions = [:layer_and_below_full, :admin]
self.two_factor_authentication_enforced = true
end

roles Admin

children Group::Bund, Group::Silverscouts
end
26 changes: 26 additions & 0 deletions app/models/group/silverscouts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

# 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 Group::Silverscouts < ::Group
self.layer = true

class Verantwortung < ::Role
self.permissions = [:layer_and_below_full]
end

class Lesezugriff < ::Role
self.permissions = [:layer_and_below_read]
end

class PowerUser < ::Role
self.permissions = [:layer_full]
end

roles Verantwortung, Lesezugriff, PowerUser
daniel-illi marked this conversation as resolved.
Show resolved Hide resolved

children Silverscouts::Region
end
19 changes: 19 additions & 0 deletions app/models/group/silverscouts/region.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

# 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 Group::Silverscouts::Region < ::Group
self.layer = true

class Leitung < ::Role
self.permissions = [:group_read, :contact_data]
end

class Mitglied < ::Role
end

roles Leitung, Mitglied
end
6 changes: 5 additions & 1 deletion app/models/pbs/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ module Pbs::Group
validates :description, length: { allow_nil: true, maximum: 2**16 - 1 }
has_many :crises

root_types Group::Bund
root_types Group::Root

def self.bund
Group::Bund.first
end
end

def active_crisis_acknowledgeable?(person)
Expand Down
2 changes: 1 addition & 1 deletion app/models/pbs/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def find_kantonalverband

def kantonalverband_for(group)
group.hierarchy.select(:id).find_by(type: ::Group::Kantonalverband.sti_name) ||
Group.select(:id).root
Group::Bund.select(:id).first
end

def set_pbs_number!
Expand Down
2 changes: 1 addition & 1 deletion app/views/censuses/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
-title t('.title')

= entry_form(buttons_bottom: false,
cancel_url: census_bund_group_path(Group.root))
cancel_url: census_bund_group_path(Group.bund))

%p= t('.frozen_once_gathered')
35 changes: 35 additions & 0 deletions config/locales/models.pbs.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,18 @@ de:
one: Rover
other: Rovers
long: Regionale Rover
group/root:
one: Root
other: Root
group/rover:
one: Rover
other: Rovers
group/silverscouts:
one: Silverscouts
other: Silverscouts
group/silverscouts/region:
one: Region
other: Regionen
group/woelfe:
one: Wölfe
other: Wölfe
Expand Down Expand Up @@ -662,6 +671,32 @@ de:
other: Selbstregistrierte
description:

group/root/admin:
one: Admin
other: Admin

group/silverscouts/verantwortung:
one: Verantwortliche*r
other: Verantwortliche
description:
group/silverscouts/lesezugriff:
one: Lesezugriff
other: Lesezugriff
description:
group/silverscouts/power_user:
one: PowerUser
other: PowerUser
description:

group/silverscouts/region/leitung:
one: Leitung
other: Leitung
description:
group/silverscouts/region/mitglied:
one: Mitglied
other: Mitglieder
description:

group/abteilung/abteilungsleitung:
one: Abteilungsleiter*in
other: Abteilungsleiter*innen
Expand Down
54 changes: 54 additions & 0 deletions db/migrate/20230517082130_insert_new_root_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

# 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 InsertNewRootGroup < ActiveRecord::Migration[6.1]
def up
admin_layer = nil

say_with_time 'Create new root-group' do
admin_layer = Group.find_or_create_by(
name: 'hitobito',
type: 'Group::Root',
)
end

say_with_time 'Move bund group below new root-group' do
Group
.where(type: 'Group::Bund', parent_id: nil)
.update_all(parent_id: admin_layer.id, lft: nil, rgt: nil)
end

say_with_time 'Create new silverscouts group below new root-group' do
Group::Silverscouts.create(name: 'Silverscouts', short_name: 'SiSc', type: 'Group::Silverscouts')
Group
.where(type: 'Group::Silverscouts', parent_id: nil)
.update_all(parent_id: admin_layer.id, lft: nil, rgt: nil)
end

say_with_time 'Rebuilding nested set...' do
Group.rebuild!(false)
end
end

def down
admin_layer_ids = Group.where(type: 'Group::Root').pluck(:id)

say_with_time 'Make current bund root' do
Group
.where(type: 'Group::Bund', parent_id: admin_layer_ids)
.update_all(parent_id: nil, lft: nil, rgt: nil)
end

say_with_time 'Remove silverscouts groups' do
Group.where(type: 'Group::Silverscouts', parent_id: admin_layer_ids).find_each { |g| g.really_destroy! }
end

say_with_time 'Rebuilding nested set...' do
Group.rebuild!(false)
end
end
end
2 changes: 1 addition & 1 deletion db/seeds/development/0_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

seeder = GroupSeeder.new

ch = Group.roots.first
ch = Group::Bund.first
srand(42)

unless ch.address.present?
Expand Down
12 changes: 8 additions & 4 deletions db/seeds/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_pbs.

Group::Bund.seed_once(:parent_id,
{name: 'Pfadibewegung Schweiz',
short_name: 'PBS'}
)
Group::Root.seed_once(:parent_id,
{ name: 'Root' })

Group::Bund.seed_once(:parent_id,
{ name: 'Pfadibewegung Schweiz',
short_name: 'PBS', parent_id: Group.roots.first.id })
Group::Silverscouts.seed_once(:parent_id,
{ name: 'Silverscouts Schweiz',
short_name: 'SILV', parent_id: Group.roots.first.id })