Class: Decidim::Organization

Inherits:
ApplicationRecord show all
Includes:
ActsAsAuthor, HasUploadValidations, Loggable, Traceable, TranslatableResource, TranslationsHelper
Defined in:
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

#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



63
64
65
# File 'app/models/decidim/organization.rb', line 63

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

Instance Method Details

#admin_terms_of_use_bodyObject



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

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

#available_authorization_handlersObject



76
77
78
# File 'app/models/decidim/organization.rb', line 76

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

#customize_welcome_notificationObject



97
98
99
# File 'app/models/decidim/organization.rb', line 97

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

#enabled_omniauth_providersObject



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

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

#machine_translation_prioritizes_original?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'app/models/decidim/organization.rb', line 142

def machine_translation_prioritizes_original?
  machine_translation_display_priority == "original"
end

#machine_translation_prioritizes_translation?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'app/models/decidim/organization.rb', line 146

def machine_translation_prioritizes_translation?
  machine_translation_display_priority == "translation"
end

#maximum_upload_sizeObject

This is needed for the upload validations



72
73
74
# File 'app/models/decidim/organization.rb', line 72

def maximum_upload_size
  settings.upload_maximum_file_size
end

#open_data_fileObject



124
125
126
127
128
129
# File 'app/models/decidim/organization.rb', line 124

def open_data_file
  @open_data_file ||= OpenDataUploader.new.tap do |uploader|
    uploader.retrieve_from_store! open_data_file_path
    uploader.cache! open_data_file_path
  end
end

#open_data_file_pathObject



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

def open_data_file_path
  "#{host}-open-data.zip"
end

#presenterObject

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



152
153
154
# File 'app/models/decidim/organization.rb', line 152

def presenter
  Decidim::Debates::OfficialAuthorPresenter.new
end

#public_participatory_spacesObject



87
88
89
90
91
# File 'app/models/decidim/organization.rb', line 87

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



93
94
95
# File 'app/models/decidim/organization.rb', line 93

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

#settingsObject



67
68
69
# File 'app/models/decidim/organization.rb', line 67

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

#sign_in_enabled?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'app/models/decidim/organization.rb', line 120

def 
  !users_registration_mode_disabled?
end

#sign_up_enabled?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'app/models/decidim/organization.rb', line 116

def 
  users_registration_mode_enabled?
end

#top_scopesObject

Returns top level scopes for this organization.

Returns an ActiveRecord::Relation.



83
84
85
# File 'app/models/decidim/organization.rb', line 83

def top_scopes
  @top_scopes ||= scopes.top_level
end

#welcome_notification_bodyObject



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

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

#welcome_notification_subjectObject



101
102
103
104
# File 'app/models/decidim/organization.rb', line 101

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