-
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 #138 from hitobito/feature/jubla-128-new-root
- Loading branch information
Showing
7 changed files
with
109 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ Gemfile.lock | |
.sass-cache | ||
.project | ||
|
||
config/settings.local.yml | ||
|
||
# reports | ||
spec/reports | ||
spec/coverage | ||
|
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,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 |
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 |
---|---|---|
|
@@ -77,6 +77,8 @@ groups: | |
enabled: false | ||
nextcloud: | ||
enabled: true | ||
nejb: | ||
enabled: false | ||
|
||
event: | ||
participations: | ||
|
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,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 |