Class: Decidim::Organization

Inherits:
ApplicationRecord show all
Includes:
ActsAsAuthor, HasUploadValidations, Loggable, Traceable, TranslatableResource, TranslationsHelper
Defined in:
decidim-core/app/models/decidim/organization.rb

Overview

Organizations are one of the main models of Decidim. In a single Decidim installation we can find many organizations and each of them can start their own participatory processes.

Constant Summary collapse

SOCIAL_HANDLERS =
[:twitter, :facebook, :instagram, :youtube, :github].freeze
AVAILABLE_MACHINE_TRANSLATION_DISPLAY_PRIORITIES =
%w(original translation).freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasUploadValidations

#attached_uploader, #maximum_avatar_size

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods included from TranslatableAttributes

#default_locale?

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



86
87
88
# File 'decidim-core/app/models/decidim/organization.rb', line 86

def self.log_presenter_class_for(_log)
  Decidim::AdminLog::OrganizationPresenter
end

Instance Method Details

#admin_terms_of_service_bodyObject



140
141
142
143
# File 'decidim-core/app/models/decidim/organization.rb', line 140

def admin_terms_of_service_body
  self[:admin_terms_of_service_body] ||
    multi_translation("decidim.admin_terms_of_service.default_body", available_locales)
end

#available_authorization_handlersObject



99
100
101
# File 'decidim-core/app/models/decidim/organization.rb', line 99

def available_authorization_handlers
  available_authorizations & Decidim.authorization_handlers.map(&:name)
end

#customize_welcome_notificationObject



126
127
128
# File 'decidim-core/app/models/decidim/organization.rb', line 126

def customize_welcome_notification
  self[:welcome_notification_subject].present? || self[:welcome_notification_body].present?
end

#enabled_omniauth_providersObject



159
160
161
162
163
164
# File 'decidim-core/app/models/decidim/organization.rb', line 159

def enabled_omniauth_providers
  return Decidim::OmniauthProvider.enabled || {} if omniauth_settings.nil?

  default_except_disabled = Decidim::OmniauthProvider.enabled.except(*tenant_disabled_providers_keys)
  default_except_disabled.merge(tenant_enabled_providers)
end

#favicon_icoObject



184
185
186
187
188
189
190
191
# File 'decidim-core/app/models/decidim/organization.rb', line 184

def favicon_ico
  return unless favicon.attached?
  return favicon if favicon.content_type == "image/vnd.microsoft.icon"

  uploader = attached_uploader(:favicon)
  variant = uploader.variant(:favicon)
  variant.processed.image
end

#machine_translation_prioritizes_original?Boolean

Returns:

  • (Boolean)


166
167
168
# File 'decidim-core/app/models/decidim/organization.rb', line 166

def machine_translation_prioritizes_original?
  machine_translation_display_priority == "original"
end

#machine_translation_prioritizes_translation?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'decidim-core/app/models/decidim/organization.rb', line 170

def machine_translation_prioritizes_translation?
  machine_translation_display_priority == "translation"
end

#maximum_upload_sizeObject

This is needed for the upload validations



95
96
97
# File 'decidim-core/app/models/decidim/organization.rb', line 95

def maximum_upload_size
  settings.upload_maximum_file_size
end

#open_data_file_path(resource = nil) ⇒ Object



153
154
155
156
157
# File 'decidim-core/app/models/decidim/organization.rb', line 153

def open_data_file_path(resource = nil)
  return "#{host}-open-data.zip" if resource.nil?

  "#{host}-open-data-#{resource}.csv"
end

#participatory_spacesObject



110
111
112
113
114
# File 'decidim-core/app/models/decidim/organization.rb', line 110

def participatory_spaces
  @participatory_spaces ||= Decidim.participatory_space_manifests.flat_map do |manifest|
    manifest.participatory_spaces.call(self)
  end
end

#presenterObject

Returns the presenter for this author, to be used in the views. Required by ActsAsAuthor.



176
177
178
# File 'decidim-core/app/models/decidim/organization.rb', line 176

def presenter
  Decidim::OfficialAuthorPresenter.new
end

#public_participatory_spacesObject



116
117
118
119
120
# File 'decidim-core/app/models/decidim/organization.rb', line 116

def public_participatory_spaces
  @public_participatory_spaces ||= Decidim.participatory_space_manifests.flat_map do |manifest|
    manifest.participatory_spaces.call(self).public_spaces
  end
end

#published_componentsObject



122
123
124
# File 'decidim-core/app/models/decidim/organization.rb', line 122

def published_components
  @published_components ||= Component.where(participatory_space: public_participatory_spaces).published
end

#settingsObject



90
91
92
# File 'decidim-core/app/models/decidim/organization.rb', line 90

def settings
  Decidim::OrganizationSettings.for(self)
end

#sign_in_enabled?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'decidim-core/app/models/decidim/organization.rb', line 149

def 
  !users_registration_mode_disabled?
end

#sign_up_enabled?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'decidim-core/app/models/decidim/organization.rb', line 145

def 
  users_registration_mode_enabled?
end

#static_pages_accessible_for(user) ⇒ Object



180
181
182
# File 'decidim-core/app/models/decidim/organization.rb', line 180

def static_pages_accessible_for(user)
  static_pages.accessible_for(self, user)
end

#top_scopesObject

Returns top level scopes for this organization.

Returns an ActiveRecord::Relation.



106
107
108
# File 'decidim-core/app/models/decidim/organization.rb', line 106

def top_scopes
  @top_scopes ||= scopes.top_level
end

#unique_nameObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'decidim-core/app/models/decidim/organization.rb', line 67

def unique_name
  base_query = new_record? ? Decidim::Organization.all : Decidim::Organization.where.not(id:).all

  organization_names = []

  base_query.pluck(:name).each do |value|
    organization_names += value.except("machine_translations").values
    organization_names += value.fetch("machine_translations", {}).values
  end

  organization_names = organization_names.map(&:downcase).compact_blank

  name.each do |language, value|
    next if value.is_a?(Hash)

    errors.add("name_#{language}", :taken) if organization_names.include?(value.downcase)
  end
end

#welcome_notification_bodyObject



135
136
137
138
# File 'decidim-core/app/models/decidim/organization.rb', line 135

def welcome_notification_body
  self[:welcome_notification_body] ||
    multi_translation("decidim.welcome_notification.default_body", available_locales)
end

#welcome_notification_subjectObject



130
131
132
133
# File 'decidim-core/app/models/decidim/organization.rb', line 130

def welcome_notification_subject
  self[:welcome_notification_subject] ||
    multi_translation("decidim.welcome_notification.default_subject", available_locales)
end