Skip to content

Commit

Permalink
Merge pull request #138 from hitobito/feature/jubla-128-new-root
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWalkingLeek authored Oct 24, 2024
2 parents 455e3f4 + b632616 commit eac1ebf
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Gemfile.lock
.sass-cache
.project

config/settings.local.yml

# reports
spec/reports
spec/coverage
Expand Down
5 changes: 4 additions & 1 deletion app/domain/jubla/person/filter/list.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
34 changes: 34 additions & 0 deletions app/models/group/root.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion config/locales/models.de.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ groups:
enabled: false
nextcloud:
enabled: true
nejb:
enabled: false

event:
participations:
Expand Down
1 change: 1 addition & 0 deletions lib/hitobito_jubla/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
60 changes: 60 additions & 0 deletions lib/tasks/nejb.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit eac1ebf

Please sign in to comment.