Class: Decidim::DecidimAwesome::CookieManagementStore

Inherits:
Object
  • Object
show all
Defined in:
app/services/decidim/decidim_awesome/cookie_management_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organization, config = nil) ⇒ CookieManagementStore

Returns a new instance of CookieManagementStore.



6
7
8
9
# File 'app/services/decidim/decidim_awesome/cookie_management_store.rb', line 6

def initialize(organization, config = nil)
  @organization = organization
  @config = config || {}
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'app/services/decidim/decidim_awesome/cookie_management_store.rb', line 11

def config
  @config
end

#organizationObject (readonly)

Returns the value of attribute organization.



11
12
13
# File 'app/services/decidim/decidim_awesome/cookie_management_store.rb', line 11

def organization
  @organization
end

Instance Method Details

#categoriesObject

merge from config



14
15
16
# File 'app/services/decidim/decidim_awesome/cookie_management_store.rb', line 14

def categories
  @categories ||= decidim_defaults.deep_merge(config)
end

#decidim_defaultsObject

Categories coming from the Decidim defaults (or initializers) can only be edited partially

  • title and description can be edited

  • slug, mandatory, visibility and items are not editable



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/services/decidim/decidim_awesome/cookie_management_store.rb', line 21

def decidim_defaults
  (Decidim.consent_categories || []).to_h do |category|
    slug = category[:slug].to_s
    [
      slug,
      {
        "slug" => slug,
        "default" => true,
        "blocked" => category[:mandatory],
        "mandatory" => category[:mandatory],
        "visibility" => "visible",
        "title" => localized_translation("layouts.decidim.data_consent.modal.#{slug}.title"),
        "description" => localized_translation("layouts.decidim.data_consent.modal.#{slug}.description"),
        "items" => (category[:items] || []).to_h do |item|
          name = item[:name].to_s
          [
            name,
            {
              "name" => name,
              "default" => true,
              "type" => item[:type].to_s,
              "service" => localized_translation("layouts.decidim.data_consent.details.items.#{name}.service"),
              "description" => localized_translation("layouts.decidim.data_consent.details.items.#{name}.description"),
              "expiration" => localized_translation("layouts.decidim.data_consent.details.items.#{name}.expiration")
            }
          ]
        end
      }
    ]
  end
end

#localized_translation(key) ⇒ Object



53
54
55
56
57
# File 'app/services/decidim/decidim_awesome/cookie_management_store.rb', line 53

def localized_translation(key)
  organization.available_locales.each_with_object({}) do |locale, hash|
    hash[locale.to_s] = I18n.t(key, locale: locale, default: "")
  end
end