diff --git a/app/domain/jubla/mailing_lists/subscribers.rb b/app/domain/jubla/mailing_lists/subscribers.rb index 0d5c8ed0..48d05abc 100644 --- a/app/domain/jubla/mailing_lists/subscribers.rb +++ b/app/domain/jubla/mailing_lists/subscribers.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright (c) 2017-2021, 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. @@ -25,7 +25,10 @@ def excluded_subscriber_ids_with_preferences end def excluded_by_contact_preference - Person.alumnus_only.where("contactable_by_#{layer_type}": false).select(:id) + preference_column = "contactable_by_#{layer_type}" + return Person.none unless Person.column_names.include?(preference_column) + + Person.alumnus_only.where("#{preference_column}": false).select(:id) end def layer_type diff --git a/app/domain/jubla/person/filter/list.rb b/app/domain/jubla/person/filter/list.rb index 71fa5aa6..aa333a9a 100644 --- a/app/domain/jubla/person/filter/list.rb +++ b/app/domain/jubla/person/filter/list.rb @@ -19,8 +19,9 @@ def accessibles_with_excluded def excluded_people_ids layer_type = group.layer_group.type.demodulize.underscore - return [] if layer_type == "root" + preference_column = "contactable_by_#{layer_type}" + return Person.none unless Person.column_names.include?(preference_column) - Person.alumnus_only.where("contactable_by_#{layer_type}": false).pluck(:id) + Person.alumnus_only.where("#{preference_column}": false).pluck(:id) end end