diff --git a/.gitignore b/.gitignore index ed97a52d..726df630 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ Gemfile.lock .sass-cache .project +config/settings.local.yml + # reports spec/reports spec/coverage diff --git a/app/domain/jubla/person/filter/list.rb b/app/domain/jubla/person/filter/list.rb index 6c3beea4..71fa5aa6 100644 --- a/app/domain/jubla/person/filter/list.rb +++ b/app/domain/jubla/person/filter/list.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2017, Jungwacht Blauring Schweiz. This file is part of +# Copyright (c) 2017-2024, Jungwacht Blauring 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. @@ -18,6 +18,9 @@ def accessibles_with_excluded def excluded_people_ids layer_type = group.layer_group.type.demodulize.underscore + + return [] if layer_type == "root" + Person.alumnus_only.where("contactable_by_#{layer_type}": false).pluck(:id) end end diff --git a/app/models/group/root.rb b/app/models/group/root.rb new file mode 100644 index 00000000..c1079a2b --- /dev/null +++ b/app/models/group/root.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# Copyright (c) 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. + +class Group::Root < ::Group + self.layer = true + self.event_types = [] + + class NullAlumnusManager + def create = true + + def destroy = true + end + + class Admin < ::Role + self.permissions = [:layer_and_below_full, :admin] + self.two_factor_authentication_enforced = true + + def skip_alumnus_callbacks + true + end + + def alumnus_manager + @alumnus_manager ||= NullAlumnusManager.new + end + end + + roles Admin + + children Group::Federation +end diff --git a/config/locales/models.de.yml b/config/locales/models.de.yml index a5ad538e..5772c631 100644 --- a/config/locales/models.de.yml +++ b/config/locales/models.de.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2014, Jungwacht Blauring Schweiz. This file is part of +# Copyright (c) 2012-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. @@ -7,6 +7,11 @@ de: activerecord: models: + group/root: Organisation + group/root/admin: + other: Administrator + long: Administrator + group/child_group: Kindergruppe group/federal_board: Bundesleitung group/federation: Bund diff --git a/config/settings.yml b/config/settings.yml index 3bf32621..8fb012ad 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -77,6 +77,8 @@ groups: enabled: false nextcloud: enabled: true + nejb: + enabled: false event: participations: diff --git a/lib/hitobito_jubla/wagon.rb b/lib/hitobito_jubla/wagon.rb index 0548b528..56145dc2 100644 --- a/lib/hitobito_jubla/wagon.rb +++ b/lib/hitobito_jubla/wagon.rb @@ -129,6 +129,7 @@ class Wagon < Rails::Engine initializer "jubla.add_settings" do |_app| Settings.add_source!(File.join(paths["config"].existent, "settings.yml")) + Settings.add_source!(File.join(paths["config"].existent, "settings.local.yml")) Settings.reload! end diff --git a/lib/tasks/nejb.rake b/lib/tasks/nejb.rake new file mode 100644 index 00000000..dd8d2e28 --- /dev/null +++ b/lib/tasks/nejb.rake @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +# Copyright (c) 2024-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. + +namespace :nejb do + task abort_if_deactivated: [:environment] do + abort "NEJB is not enabled" if FeatureGate.disabled?("groups.nejb") + end + + task :prepare do + def say_with_time(message) + say(message) + result = nil + time = Benchmark.measure { result = yield } + say "%.4fs" % time.real, :subitem + say("#{result} rows", :subitem) if result.is_a?(Integer) + result + end + + def say(message, subitem = false) + puts "#{subitem ? " ->" : "--"} #{message}" + end + end + + task insert_new_root: [:abort_if_deactivated, :prepare, :environment] do + admin_layer = nil + + say_with_time "Create new root-group" do + admin_layer_attrs = { + name: "hitobito", + type: "Group::Root" + } + + # find or create by with validate: false + 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 previous top group below new root-group" do + Group + .where(type: "Group::Federation", parent_id: nil) + .update_all(parent_id: admin_layer.id, lft: nil, rgt: nil) + end + + say_with_time "Rebuilding nested set..." do + Group.archival_validation = false + Group.rebuild!(false) + Group.archival_validation = true + end + end +end