Skip to content

Commit

Permalink
Merge pull request #144 from hitobito/feature/jubla-131-avoid-previou…
Browse files Browse the repository at this point in the history
…s-alumnus-logic-in-nejb-part

Avoid previous Alumnus-Logic in NEJB-Tree
  • Loading branch information
kronn authored Oct 25, 2024
2 parents d03d600 + 870c9d9 commit 8ea587f
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 44 deletions.
18 changes: 18 additions & 0 deletions app/domain/jubla/role/null_alumnus_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

# Implementation of the NullObject-Pattern
#
# Mimics an AlumnusManager, but does nothing. Intended as a temporary drop-in
# to gradually phase out the previous alumnus-logic
module Jubla::Role
class NullAlumnusManager
def create = true

def destroy = true
end
end
14 changes: 7 additions & 7 deletions app/models/group/kanton_ehemaligenverein.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@
class Group::KantonEhemaligenverein < ::Group
### ROLES

class Leader < ::Role
class Leader < ::NejbRole
self.permissions = [:group_and_below_full, :contact_data]
end

class GroupAdmin < ::Role
class GroupAdmin < ::NejbRole
self.permissions = [:group_and_below_full]
end

class Treasurer < ::Role
class Treasurer < ::NejbRole
self.permissions = [:group_and_below_read]
end

class NejbMember < ::Role
class NejbMember < ::NejbRole
self.permissions = [:group_read]
end

class NejbJoiner < ::Role
class NejbJoiner < ::NejbRole
self.permissions = []
end

class External < ::Role
class External < ::NejbRole
self.permissions = []
end

class DispatchAddress < ::Role
class DispatchAddress < ::NejbRole
self.permissions = []
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/group/nejb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class Group::Nejb < ::Group

### ROLES

class GroupAdmin < ::Role
class GroupAdmin < ::NejbRole
self.permissions = [:group_full]
end

class DispatchAddress < ::Role
class DispatchAddress < ::NejbRole
self.permissions = []
end

class ITSupport < ::Role
class ITSupport < ::NejbRole
self.permissions = [:admin, :impersonation]
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/group/nejb_bundesleitung.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# https://github.com/hitobito/hitobito_jubla.

class Group::NejbBundesleitung < ::Group
class GroupAdmin < ::Role
class GroupAdmin < ::NejbRole
self.permissions = [:admin, :layer_and_below_full, :contact_data]
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/group/nejb_kanton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Group::NejbKanton < ::Group
children Group::KantonEhemaligenverein, Group::NejbRegion
self.layer = true

class GroupAdmin < ::Role
class GroupAdmin < ::NejbRole
self.permissions = [:admin, :layer_and_below_full, :contact_data]
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/group/nejb_region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Group::NejbRegion < ::Group
children Group::RegionEhemaligenverein, Group::NejbSchar
self.layer = true

class GroupAdmin < ::Role
class GroupAdmin < ::NejbRole
self.permissions = [:admin, :layer_and_below_full, :contact_data]
end

Expand Down
14 changes: 7 additions & 7 deletions app/models/group/nejb_schar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ class Group::NejbSchar < ::Group

### ROLES

class Leader < ::Role
class Leader < ::NejbRole
self.permissions = [:group_and_below_full, :contact_data]
end

class GroupAdmin < ::Role
class GroupAdmin < ::NejbRole
self.permissions = [:group_and_below_full]
end

class Treasurer < ::Role
class Treasurer < ::NejbRole
self.permissions = [:group_and_below_read]
end

class NejbMember < ::Role
class NejbMember < ::NejbRole
self.permissions = [:group_read]
end

class NejbJoiner < ::Role
class NejbJoiner < ::NejbRole
self.permissions = []
end

class External < ::Role
class External < ::NejbRole
self.permissions = []
end

class DispatchAddress < ::Role
class DispatchAddress < ::NejbRole
self.permissions = []
end

Expand Down
18 changes: 9 additions & 9 deletions app/models/group/netzwerk_ehemalige_jungwacht_blauring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@
class Group::NetzwerkEhemaligeJungwachtBlauring < ::Group
### ROLES

class Leader < ::Role
class Leader < ::NejbRole
self.permissions = [:group_and_below_full, :contact_data]
end

class GroupAdmin < ::Role
class GroupAdmin < ::NejbRole
self.permissions = [:group_and_below_full]
end

class Treasurer < ::Role
class Treasurer < ::NejbRole
self.permissions = [:group_and_below_read]
end

class ActiveMember < ::Role
class ActiveMember < ::NejbRole
self.permissions = [:group_read]
end

class PassiveMember < ::Role
class PassiveMember < ::NejbRole
self.permissions = [:group_read]
end

class CollectiveMember < ::Role
class CollectiveMember < ::NejbRole
self.permissions = [:group_read]
end

class NejbJoiner < ::Role
class NejbJoiner < ::NejbRole
self.permissions = []
end

class External < ::Role
class External < ::NejbRole
self.permissions = []
end

class DispatchAddress < ::Role
class DispatchAddress < ::NejbRole
self.permissions = []
end

Expand Down
14 changes: 7 additions & 7 deletions app/models/group/region_ehemaligenverein.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@
class Group::RegionEhemaligenverein < ::Group
### ROLES

class Leader < ::Role
class Leader < ::NejbRole
self.permissions = [:group_and_below_full, :contact_data]
end

class GroupAdmin < ::Role
class GroupAdmin < ::NejbRole
self.permissions = [:group_and_below_full]
end

class Treasurer < ::Role
class Treasurer < ::NejbRole
self.permissions = [:group_and_below_read]
end

class NejbMember < ::Role
class NejbMember < ::NejbRole
self.permissions = [:group_read]
end

class NejbJoiner < ::Role
class NejbJoiner < ::NejbRole
self.permissions = []
end

class External < ::Role
class External < ::NejbRole
self.permissions = []
end

class DispatchAddress < ::Role
class DispatchAddress < ::NejbRole
self.permissions = []
end

Expand Down
10 changes: 2 additions & 8 deletions app/models/group/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,16 @@ 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
def skip_alumnus_callback
true
end

def alumnus_manager
@alumnus_manager ||= NullAlumnusManager.new
@alumnus_manager ||= Jubla::Role::NullAlumnusManager.new
end
end

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

class NejbRole < Role
module AlumnusFreeRole
def skip_alumnus_callback
true
end

def alumnus_manager
@alumnus_manager ||= Jubla::Role::NullAlumnusManager.new
end
end
include AlumnusFreeRole
end
18 changes: 18 additions & 0 deletions spec/domain/jubla/role/null_alumnus_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

require "spec_helper"

describe Jubla::Role::NullAlumnusManager do
it "has a create-method" do
expect(subject.create).to be_truthy
end

it "has a destroy-method" do
expect(subject.destroy).to be_truthy
end
end
34 changes: 34 additions & 0 deletions spec/models/nejb_role_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.

require "spec_helper"

describe NejbRole do
it "is a Role" do
expect(subject).to be_a Role
end

it "is a Jubla::Role" do
expect(subject).to be_a Jubla::Role
end

it "disables the alumnus-callback" do
expect(subject.skip_alumnus_callback).to be_truthy
end

it "uses the NullAlumnusManager" do
expect(subject.alumnus_manager).to be_a Jubla::Role::NullAlumnusManager
end

%w[
Group::NejbSchar::GroupAdmin
].each do |role|
context role do
it "is a NeJbRole" do
expect(role.safe_constantize.new).to be_a NejbRole
end
end
end
end

0 comments on commit 8ea587f

Please sign in to comment.