-
-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
167 additions
and
113 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
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
112 changes: 112 additions & 0 deletions
112
decidim-system/app/forms/decidim/system/organization_form.rb
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,112 @@ | ||
# frozen_string_literal: true | ||
|
||
require "decidim/translatable_attributes" | ||
|
||
module Decidim | ||
module System | ||
# A form object used to update organizations from the system dashboard. | ||
# | ||
class OrganizationForm < Form | ||
include TranslatableAttributes | ||
include JsonbAttributes | ||
|
||
mimic :organization | ||
|
||
attribute :host, String | ||
attribute :secondary_hosts, String | ||
attribute :force_users_to_authenticate_before_access_organization, Boolean | ||
attribute :available_authorizations, Array[String] | ||
attribute :users_registration_mode, String | ||
attribute :default_locale, String | ||
|
||
jsonb_attribute :smtp_settings, [ | ||
[:from, String], | ||
[:from_email, String], | ||
[:from_label, String], | ||
[:user_name, String], | ||
[:encrypted_password, String], | ||
[:address, String], | ||
[:port, Integer], | ||
[:authentication, String], | ||
[:enable_starttls_auto, Boolean] | ||
] | ||
|
||
jsonb_attribute :content_security_policy, [ | ||
[:"default-src", String], | ||
[:"img-src", String], | ||
[:"media-src", String], | ||
[:"script-src", String], | ||
[:"style-src", String], | ||
[:"frame-src", String], | ||
[:"font-src", String], | ||
[:"connect-src", String] | ||
] | ||
|
||
attribute :password, String | ||
attribute :file_upload_settings, FileUploadSettingsForm | ||
|
||
OMNIATH_PROVIDERS_ATTRIBUTES = Decidim::OmniauthProvider.available.keys.map do |provider| | ||
Rails.application.secrets.dig(:omniauth, provider).keys.map do |setting| | ||
if setting == :enabled | ||
["omniauth_settings_#{provider}_enabled".to_sym, Boolean] | ||
else | ||
["omniauth_settings_#{provider}_#{setting}".to_sym, String] | ||
end | ||
end | ||
end.flatten(1) | ||
|
||
jsonb_attribute :omniauth_settings, OMNIATH_PROVIDERS_ATTRIBUTES | ||
|
||
validates :host, :users_registration_mode, presence: true | ||
validate :validate_organization_uniqueness | ||
validates :users_registration_mode, inclusion: { in: Decidim::Organization.users_registration_modes } | ||
|
||
def map_model(model) | ||
self.default_locale = model.default_locale | ||
self.secondary_hosts = model.secondary_hosts.join("\n") | ||
self.omniauth_settings = (model.omniauth_settings || {}).transform_values do |v| | ||
Decidim::OmniauthProvider.value_defined?(v) ? Decidim::AttributeEncryptor.decrypt(v) : v | ||
end | ||
self.file_upload_settings = FileUploadSettingsForm.from_model(model.file_upload_settings) | ||
end | ||
|
||
def clean_secondary_hosts | ||
return unless secondary_hosts | ||
|
||
secondary_hosts.split("\n").map(&:chomp).select(&:present?) | ||
end | ||
|
||
def clean_available_authorizations | ||
return unless available_authorizations | ||
|
||
available_authorizations.select(&:present?) | ||
end | ||
|
||
def password | ||
encrypted_password.nil? ? super : Decidim::AttributeEncryptor.decrypt(encrypted_password) | ||
end | ||
|
||
def encrypted_smtp_settings | ||
smtp_settings["from"] = set_from | ||
|
||
smtp_settings.merge(encrypted_password: Decidim::AttributeEncryptor.encrypt(password)) | ||
end | ||
|
||
def set_from | ||
return from_email if from_label.blank? | ||
|
||
"#{from_label} <#{from_email}>" | ||
end | ||
|
||
def encrypted_omniauth_settings | ||
omniauth_settings.transform_values do |v| | ||
Decidim::OmniauthProvider.value_defined?(v) ? Decidim::AttributeEncryptor.encrypt(v) : v | ||
end | ||
end | ||
|
||
private | ||
|
||
def validate_organization_uniqueness; end | ||
end | ||
end | ||
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
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
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