Skip to content

Commit

Permalink
Add hostname for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWalkingLeek authored and daniel-illi committed Sep 12, 2023
1 parent aab45e5 commit cd4831b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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)
* Neu kann der Hostname auf PBS und SiSc Ebene gesetzt werden (hitobito_pbs#272)

## Version 1.28

Expand Down
18 changes: 18 additions & 0 deletions app/controllers/concerns/hostnamed_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

module HostnamedGroups
extend ActiveSupport::Concern

included do
prepend_before_action :determine_group_by_hostname
end

def determine_group_by_hostname
@group ||= Group.where(hostname: request.host).first
end
end
1 change: 1 addition & 0 deletions app/models/pbs/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module Pbs::Group
self.superior_attributes = [:pbs_shortname]

validates :description, length: { allow_nil: true, maximum: 2**16 - 1 }
validates :hostname, uniqueness: true, allow_blank: true
has_many :crises

root_types Group::Root
Expand Down
4 changes: 4 additions & 0 deletions app/views/groups/_fields_pbs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@
= field_set_tag do
- entry.modifiable?(:group_health) do
= f.labeled_input_field(:group_health, help: t('.group_health_info'))

- if entry.parent.is_a?(Group::Root)
= field_set_tag do
= f.labeled_input_field :hostname
1 change: 1 addition & 0 deletions config/locales/models.pbs.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,7 @@ de:
pbs_shortname: PBS Kürzel
bank_account: Bank-/Postverbindung
cantons: Kantone
hostname: Hostname

group/abteilung:
gender: Geschlecht
Expand Down
15 changes: 12 additions & 3 deletions db/migrate/20230517082130_insert_new_root_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ def up
admin_layer = nil

say_with_time 'Create new root-group' do
admin_layer = Group.find_or_create_by(
admin_layer_attrs = {
name: 'hitobito',
type: 'Group::Root',
)
}
admin_layer = if Group.exists?(admin_layer_attrs)
Group.find_by(admin_layer_attrs)
else
Group.new(admin_layer_attrs).tap do |g|
g.save(validate: false)
g.reload
end
end
end

say_with_time 'Move bund group below new root-group' do
Expand All @@ -23,7 +31,8 @@ def up
end

say_with_time 'Create new silverscouts group below new root-group' do
Group::Silverscouts.create(name: 'Silverscouts', short_name: 'SiSc', type: 'Group::Silverscouts')
sisc = Group::Silverscouts.new(name: 'Silverscouts', short_name: 'SiSc', type: 'Group::Silverscouts')
sisc.save(validate: false)
Group
.where(type: 'Group::Silverscouts', parent_id: nil)
.update_all(parent_id: admin_layer.id, lft: nil, rgt: nil)
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20230824145511_add_hostname_to_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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 AddHostnameToGroups < ActiveRecord::Migration[6.1]
def change
add_column :groups, :hostname, :string

add_index :groups, :hostname, unique: true
end
end
3 changes: 3 additions & 0 deletions lib/hitobito_pbs/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class Wagon < Rails::Engine
PeopleController.permitted_attrs += [:salutation, :title, :grade_of_school, :entry_date,
:leaving_date, :j_s_number, :correspondence_language,
:prefers_digital_correspondence, :brother_and_sisters]
GroupsController.permitted_attrs += [:hostname]
Event::KindsController.permitted_attrs += [:documents_text, :campy, :can_have_confirmations,
:confirmation_name]
QualificationKindsController.permitted_attrs += [:manual]
Expand All @@ -133,6 +134,8 @@ class Wagon < Rails::Engine
Person::QueryController.search_columns << :pbs_number
SubscriptionsController.include Pbs::SubscriptionsController

DeviseController.include HostnamedGroups

### sheets
Sheet::Group.include Pbs::Sheet::Group
Sheet::Event.include Pbs::Sheet::Event
Expand Down

0 comments on commit cd4831b

Please sign in to comment.