decidim-culturoscope 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +661 -0
  3. data/README.md +134 -0
  4. data/Rakefile +92 -0
  5. data/app/controllers/decidim/culturoscope/flux_controller.rb +71 -0
  6. data/app/forms/decidim/culturoscope/admin/organization_config_form.rb +17 -0
  7. data/app/models/decidim/culturoscope/application_record.rb +9 -0
  8. data/app/models/decidim/culturoscope/event.rb +22 -0
  9. data/config/locales/de.yml +20 -0
  10. data/config/locales/en.yml +20 -0
  11. data/config/locales/fr.yml +20 -0
  12. data/config/locales/it.yml +20 -0
  13. data/db/migrate/20260914001000_create_culturoscope_events.rb +16 -0
  14. data/lib/decidim/culturoscope/availability.rb +15 -0
  15. data/lib/decidim/culturoscope/bindings.rb +40 -0
  16. data/lib/decidim/culturoscope/bound_meetings.rb +67 -0
  17. data/lib/decidim/culturoscope/configuration.rb +16 -0
  18. data/lib/decidim/culturoscope/date_status.rb +31 -0
  19. data/lib/decidim/culturoscope/engine.rb +64 -0
  20. data/lib/decidim/culturoscope/event_mapper.rb +106 -0
  21. data/lib/decidim/culturoscope/event_status.rb +22 -0
  22. data/lib/decidim/culturoscope/feed_builder.rb +76 -0
  23. data/lib/decidim/culturoscope/feed_report.rb +53 -0
  24. data/lib/decidim/culturoscope/flux.schema.json +78 -0
  25. data/lib/decidim/culturoscope/image_url.rb +88 -0
  26. data/lib/decidim/culturoscope/meeting_bindable.rb +17 -0
  27. data/lib/decidim/culturoscope/schema.rb +21 -0
  28. data/lib/decidim/culturoscope/seeds.rb +110 -0
  29. data/lib/decidim/culturoscope/tenant.rb +23 -0
  30. data/lib/decidim/culturoscope/test/factories.rb +10 -0
  31. data/lib/decidim/culturoscope/upgrade.rb +37 -0
  32. data/lib/decidim/culturoscope/venue_mapper.rb +80 -0
  33. data/lib/decidim/culturoscope/version.rb +13 -0
  34. data/lib/decidim/culturoscope/vocabulary.rb +27 -0
  35. data/lib/decidim/culturoscope.rb +37 -0
  36. data/lib/decidim-culturoscope.rb +3 -0
  37. data/lib/tasks/decidim/culturoscope/upgrade.rake +13 -0
  38. data/lib/tasks/decidim/culturoscope.rake +19 -0
  39. metadata +137 -0
data/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # decidim-culturoscope
2
+
3
+ Serve a public JSON flux that [Culturoscope](https://dev.culturoscope.ch/documentation/flux) pulls from Decidim Meetings. Give them the URL. This gem does not POST to Culturoscope.
4
+
5
+ Who reads this: the person installing the gem on a Decidim host and handing the flux URL to Culturoscope.
6
+
7
+ ## Install
8
+
9
+ Add to the host `Gemfile` and bundle:
10
+
11
+ ```ruby
12
+ gem "decidim-culturoscope", git: "https://gitlab.com/octree_gva/decidim/vocacity/decidim-modules/decidim-culturoscope"
13
+ ```
14
+
15
+ ## Configure
16
+
17
+ ```ruby
18
+ # config/initializers/decidim_culturoscope.rb
19
+ Decidim::Culturoscope.configure do |config|
20
+ config.api_key = ENV.fetch("CULTUROSCOPE_API_KEY")
21
+ # Optional. When set, the flux URL must include ?token=
22
+ config.flux_token = ENV.fetch("CULTUROSCOPE_FLUX_TOKEN", "")
23
+ # Optional jpeg/png used when the meeting and the organization logo are not jpeg/png.
24
+ config.fallback_image_url = ENV.fetch("CULTUROSCOPE_FALLBACK_IMAGE_URL", "")
25
+ # Locality name => Swiss NPA, used when the address has no 4-digit code.
26
+ config.venue_localities = {
27
+ "Porrentruy" => 2900
28
+ }
29
+ end
30
+
31
+ # Map host category ids → Culturoscope codes (EX TH MU AN DA CI LI PR PA).
32
+ # meeting.category is often nil — never call .id without &.
33
+ CATEGORY_MAP = {
34
+ "595" => "EX",
35
+ "596" => "TH",
36
+ "597" => "MU",
37
+ "598" => "AN",
38
+ "599" => "DA",
39
+ "600" => "CI",
40
+ "601" => "LI",
41
+ "602" => "PR",
42
+ "603" => "PA"
43
+ }.freeze
44
+
45
+ Decidim::Culturoscope::Bindings.add(
46
+ component_id: "326", # meetings component id on the host
47
+ event_categories: lambda { |meeting|
48
+ code = CATEGORY_MAP[meeting.category&.id.to_s]
49
+ Array(code.presence || "AN")
50
+ }
51
+ )
52
+ ```
53
+
54
+ `Bindings.add` raises if `component_id` is blank or `event_categories` is not callable. A later `Bindings.add` for the same `component_id` replaces the earlier one. Repeat `Bindings.add` for each meetings component that should appear in the flux.
55
+
56
+ Enable the module per organization: System → Organizations → Edit → Culturoscope → Enable Culturoscope. While that box is off, `GET /culturoscope/flux` responds 404 and the feed includes no meetings from that organization.
57
+
58
+ Install / upgrade (host app):
59
+
60
+ ```bash
61
+ bundle exec rails decidim:update # alias of decidim:upgrade
62
+ bundle exec rails db:migrate
63
+ ```
64
+
65
+ `decidim:update` / `decidim:upgrade` appends this gem to `FROM` so migrations are copied. The `culturoscope_events` table is unused by the flux (it recorded POSTs). Leave it until a later migration drops it.
66
+
67
+ Env vars:
68
+
69
+ | Variable | Default | Required |
70
+ |----------|---------|----------|
71
+ | `CULTUROSCOPE_API_KEY` | `""` | Yes, for a schema-valid feed. Sent inside the JSON, as Culturoscope expects. |
72
+ | `CULTUROSCOPE_FLUX_TOKEN` | `""` | No. Empty means the URL is public. Set it to require `?token=`. |
73
+ | `CULTUROSCOPE_FALLBACK_IMAGE_URL` | `""` | No. jpeg/png URL when the meeting photo and the organization logo are not jpeg/png. |
74
+ | `CULTUROSCOPE_COMPONENT_ID` | unset | No. Registers a fallback `AN` binding only if that component has no `Bindings.add`. Do not set it to an id you also register. |
75
+
76
+ `venue_localities` is Ruby config, not an env var. Default `{}`.
77
+
78
+ ## Flux URL
79
+
80
+ `https://<organization.host>/culturoscope/flux.json`
81
+
82
+ One feed per organization: every bound meetings component in that organization. When Meeting soft-deletes (`with_deleted`), those rows stay in the feed. A meeting that fails the schema is skipped and logged. `?strict=1` returns 422 instead, for QA. The URL is not linked from the Decidim UI. Tell Culturoscope to attach it to the organizer account.
83
+
84
+ Local check:
85
+
86
+ ```bash
87
+ docker compose exec culturoscope bundle exec rails decidim:culturoscope
88
+ curl -s http://localhost:3006/culturoscope/flux.json
89
+ ```
90
+
91
+ The rake task prints the event count, skipped meetings, and the flux URL. It does not call Culturoscope.
92
+
93
+ ## Mapping
94
+
95
+ | Flux | Decidim |
96
+ |------|---------|
97
+ | `event_status` PUBLIC | published, not `private_meeting`, not hidden |
98
+ | `event_status` PRIVATE | unpublished and/or private |
99
+ | `date_status` CANCELLED | `deleted_at`, `withdrawn_at`, unpublished, or hidden |
100
+ | `date_status` SOLDOUT | registrations enabled and no remaining slots |
101
+ | `start_date` / `end_date` | `Europe/Zurich`, `YYYY-MM-DD HH:MM` |
102
+ | `venue_zip` / `venue_city` | Swiss NPA in the address, else `venue_localities` |
103
+ | `image_url` | meeting photo, else organization logo, else `fallback_image_url`. jpeg/png only. ActiveStorage redirect URL (no disk token). |
104
+
105
+ Online meetings omit venue fields.
106
+
107
+ ## QA seed
108
+
109
+ Run from the dummy app (gem root has no Rails app). Unset `DATABASE_URL` so Rails uses the dummy `database.yml`.
110
+
111
+ ```bash
112
+ docker compose up -d
113
+ docker compose exec culturoscope bash -lc 'cd spec/decidim_dummy_app && unset DATABASE_URL && bundle exec rails decidim:culturoscope:seed'
114
+ ```
115
+
116
+ ## Local checks
117
+
118
+ ```bash
119
+ docker compose up -d
120
+ docker compose exec culturoscope bash -lc 'bundle config set --local local.decidim-toggle /home/decidim-toggle && bundle install'
121
+ docker compose exec culturoscope bash -lc 'unset DATABASE_URL && bundle exec rspec'
122
+ docker compose exec culturoscope bundle exec rubocop .
123
+ docker compose -f docker-compose.ci.yml run --rm rspec
124
+ ```
125
+
126
+ Image: `octree/decidim-dev:0.32`. Ruby 3.4.7.
127
+
128
+ Apartment (optional sibling checkout `../decidim-apartment`):
129
+
130
+ ```bash
131
+ docker compose -f docker-compose.ci.yml run --rm -e BUNDLE_GEMFILE=gemfiles/with_apartment.gemfile rspec
132
+ ```
133
+
134
+ The flux reads only the tenant for the request host. An unknown host is 404.
data/Rakefile ADDED
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "rake"
5
+ require "rake/file_utils"
6
+ require "yaml"
7
+
8
+ require "decidim/dev/common_rake"
9
+
10
+ def expand_bundle_gemfile!
11
+ gemfile = ENV.fetch("BUNDLE_GEMFILE", nil)
12
+ return if gemfile.blank? || File.absolute_path?(gemfile)
13
+
14
+ ENV["BUNDLE_GEMFILE"] = File.expand_path(gemfile, __dir__)
15
+ end
16
+
17
+ def run!(cwd, command)
18
+ FileUtils.chdir(cwd) { sh(command) }
19
+ end
20
+
21
+ def strip_unused_demo_files!
22
+ root = File.expand_path("spec/decidim_dummy_app", __dir__)
23
+ %w(
24
+ app/services/dummy_signature_handler.rb
25
+ app/services/dummy_sms_mobile_phone_validator.rb
26
+ config/initializers/decidim_initiatives.rb
27
+ config/initializers/decidim_elections.rb
28
+ ).each { |path| FileUtils.rm_f(File.join(root, path)) }
29
+ FileUtils.rm_rf(File.join(root, "app/views/decidim/initiatives"))
30
+ end
31
+
32
+ def common_db_config
33
+ {
34
+ "adapter" => "postgresql",
35
+ "encoding" => "unicode",
36
+ "host" => ENV.fetch("DATABASE_HOST", "culturoscope-pg"),
37
+ "port" => ENV.fetch("DATABASE_PORT", "5432").to_i,
38
+ "username" => ENV.fetch("DATABASE_USERNAME", "decidim"),
39
+ "password" => ENV.fetch("DATABASE_PASSWORD", "pleaseChangeMe"),
40
+ "database" => "#{base_app_name}_test_app"
41
+ }
42
+ end
43
+
44
+ desc "Prepare for testing"
45
+ task :prepare_tests do
46
+ expand_bundle_gemfile!
47
+ unless ENV.fetch("DISABLED_DOCKER_COMPOSE", "false") == "true"
48
+ sh("docker-compose -f docker-compose.yml down -v --remove-orphans")
49
+ sh("docker-compose -f docker-compose.yml up -d")
50
+ end
51
+ ENV["RAILS_ENV"] = "development"
52
+ config_file = File.expand_path("spec/decidim_dummy_app/config/database.yml", __dir__)
53
+ File.open(config_file, "w") { |file| YAML.dump({ "test" => common_db_config, "development" => common_db_config }, file) }
54
+ dummy = File.expand_path("spec/decidim_dummy_app", __dir__)
55
+ run!(dummy, "bundle exec rails db:drop")
56
+ run!(dummy, "bundle exec rails db:create")
57
+ run!(dummy, "bundle exec rails db:migrate")
58
+ end
59
+
60
+ desc "Generates a dummy app for testing"
61
+ task :test_app do
62
+ expand_bundle_gemfile!
63
+ Bundler.with_original_env do
64
+ expand_bundle_gemfile!
65
+ generate_decidim_app(
66
+ "spec/decidim_dummy_app",
67
+ "--app_name", "#{base_app_name}_test_app",
68
+ "--path", "../..",
69
+ "--skip_spring",
70
+ "--demo",
71
+ "--force_ssl", "false",
72
+ "--locales", "en,fr,es,ca"
73
+ )
74
+ end
75
+ strip_unused_demo_files!
76
+ Rake::Task["prepare_tests"].invoke
77
+ end
78
+
79
+ desc "Generates a development app"
80
+ task :development_app do
81
+ expand_bundle_gemfile!
82
+ Bundler.with_original_env do
83
+ expand_bundle_gemfile!
84
+ generate_decidim_app(
85
+ "development_app",
86
+ "--app_name", "#{base_app_name}_development_app",
87
+ "--path", "..",
88
+ "--recreate_db",
89
+ "--demo"
90
+ )
91
+ end
92
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Culturoscope
5
+ class FluxController < ActionController::API
6
+ # Public pull URL. Optional flux token, not a Decidim permission.
7
+ def show # rubocop:disable Decidim/EnforcePermissionTo
8
+ return if Tenant.call(request.host) { serve }
9
+
10
+ head :not_found
11
+ end
12
+
13
+ private
14
+
15
+ def serve
16
+ return miss unless open?
17
+ return deny unless token_ok?
18
+
19
+ write_feed
20
+ rescue Error => e
21
+ fail_feed(e)
22
+ end
23
+
24
+ def miss
25
+ head :not_found
26
+ true
27
+ end
28
+
29
+ def deny
30
+ head :forbidden
31
+ true
32
+ end
33
+
34
+ def write_feed
35
+ render json: FeedBuilder.call(organization, strict: strict?)
36
+ true
37
+ end
38
+
39
+ def fail_feed(error)
40
+ render json: { "error" => error.message }, status: :unprocessable_content
41
+ true
42
+ end
43
+
44
+ def open?
45
+ organization.present? && Availability.enabled?(organization)
46
+ end
47
+
48
+ def organization
49
+ @organization ||= Decidim::Organization.find_by(host: request.host)
50
+ end
51
+
52
+ def strict?
53
+ params[:strict].to_s == "1"
54
+ end
55
+
56
+ def token_ok?
57
+ expected = Decidim::Culturoscope.config.flux_token.to_s
58
+ return true if expected.blank?
59
+
60
+ same_token?(expected)
61
+ end
62
+
63
+ def same_token?(expected)
64
+ given = params[:token].to_s
65
+ return false unless given.bytesize == expected.bytesize
66
+
67
+ ActiveSupport::SecurityUtils.secure_compare(given, expected)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Culturoscope
5
+ module Admin
6
+ class OrganizationConfigForm < Decidim::Form
7
+ include Decidim::Toggle::ModuleConfigForm
8
+
9
+ self.module_config_name = Decidim::Culturoscope::MODULE_NAME
10
+
11
+ mimic :organization
12
+
13
+ attribute :enabled, :boolean
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Culturoscope
5
+ class ApplicationRecord < ActiveRecord::Base
6
+ self.abstract_class = true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Culturoscope
5
+ class Event < ApplicationRecord
6
+ # ponytail: leftover from POST sync; the feed does not write here. Drop the table in a later migration.
7
+ self.table_name = "culturoscope_events"
8
+
9
+ belongs_to :meeting,
10
+ class_name: "Decidim::Meetings::Meeting",
11
+ foreign_key: :decidim_meetings_meeting_id,
12
+ inverse_of: :culturoscope
13
+
14
+ validates :culturoscope_id, presence: true, uniqueness: true
15
+ validates :decidim_meetings_meeting_id, uniqueness: true
16
+
17
+ def to_s
18
+ url.presence || "culturoscope:#{culturoscope_id}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ ---
2
+ de:
3
+ decidim_toggle:
4
+ system:
5
+ decidim_culturoscope:
6
+ tab: Culturoscope
7
+ enabled: Culturoscope aktivieren
8
+ decidim:
9
+ culturoscope:
10
+ errors:
11
+ event_categories_required: event_categories ist erforderlich
12
+ unknown_event_categories: "unbekannte event_categories: %{codes}"
13
+ exclusive_ex_category: EX darf nicht mit anderen Kategorien kombiniert werden
14
+ component_id_required: component_id ist erforderlich
15
+ event_categories_must_be_callable: event_categories muss aufrufbar sein
16
+ unknown_component_id: "unbekannte component_id %{component_id}"
17
+ component_not_meetings: "Komponente %{id} ist keine Meetings-Komponente"
18
+ image_url_required: image_url ist für den Flux erforderlich
19
+ api_key_required: api_key ist erforderlich
20
+ venue_incomplete: venue_zip und venue_city sind erforderlich
@@ -0,0 +1,20 @@
1
+ ---
2
+ en:
3
+ decidim_toggle:
4
+ system:
5
+ decidim_culturoscope:
6
+ tab: Culturoscope
7
+ enabled: Enable Culturoscope
8
+ decidim:
9
+ culturoscope:
10
+ errors:
11
+ event_categories_required: event_categories is required
12
+ unknown_event_categories: "unknown event_categories: %{codes}"
13
+ exclusive_ex_category: EX cannot be combined with other categories
14
+ component_id_required: component_id is required
15
+ event_categories_must_be_callable: event_categories must be callable
16
+ unknown_component_id: "unknown component_id %{component_id}"
17
+ component_not_meetings: "component %{id} is not meetings"
18
+ image_url_required: image_url is required by flux
19
+ api_key_required: api_key is required
20
+ venue_incomplete: venue_zip and venue_city are required
@@ -0,0 +1,20 @@
1
+ ---
2
+ fr:
3
+ decidim_toggle:
4
+ system:
5
+ decidim_culturoscope:
6
+ tab: Culturoscope
7
+ enabled: Activer Culturoscope
8
+ decidim:
9
+ culturoscope:
10
+ errors:
11
+ event_categories_required: event_categories est obligatoire
12
+ unknown_event_categories: "event_categories inconnues : %{codes}"
13
+ exclusive_ex_category: EX ne peut pas être combiné avec d'autres catégories
14
+ component_id_required: component_id est obligatoire
15
+ event_categories_must_be_callable: event_categories doit être invocable
16
+ unknown_component_id: "component_id inconnu %{component_id}"
17
+ component_not_meetings: "le composant %{id} n'est pas un composant meetings"
18
+ image_url_required: image_url est obligatoire pour le flux
19
+ api_key_required: api_key est obligatoire
20
+ venue_incomplete: venue_zip et venue_city sont obligatoires
@@ -0,0 +1,20 @@
1
+ ---
2
+ it:
3
+ decidim_toggle:
4
+ system:
5
+ decidim_culturoscope:
6
+ tab: Culturoscope
7
+ enabled: Attiva Culturoscope
8
+ decidim:
9
+ culturoscope:
10
+ errors:
11
+ event_categories_required: event_categories è obbligatorio
12
+ unknown_event_categories: "event_categories sconosciute: %{codes}"
13
+ exclusive_ex_category: EX non può essere combinato con altre categorie
14
+ component_id_required: component_id è obbligatorio
15
+ event_categories_must_be_callable: event_categories deve essere invocabile
16
+ unknown_component_id: "component_id sconosciuto %{component_id}"
17
+ component_not_meetings: "il componente %{id} non è un componente meetings"
18
+ image_url_required: image_url è obbligatorio per il flux
19
+ api_key_required: api_key è obbligatorio
20
+ venue_incomplete: venue_zip e venue_city sono obbligatori
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateCulturoscopeEvents < ActiveRecord::Migration[7.0]
4
+ def change
5
+ create_table :culturoscope_events do |t|
6
+ t.bigint :decidim_meetings_meeting_id, null: false
7
+ t.bigint :culturoscope_id, null: false
8
+ t.string :url
9
+ t.datetime :synced_at
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :culturoscope_events, :decidim_meetings_meeting_id, unique: true
14
+ add_index :culturoscope_events, :culturoscope_id, unique: true
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Culturoscope
5
+ module Availability
6
+ module_function
7
+
8
+ def enabled?(organization)
9
+ return false if organization.blank?
10
+
11
+ !!Decidim::Toggle.config_for(organization, MODULE_NAME)[:enabled]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Culturoscope
5
+ class Bindings
6
+ Binding = Struct.new(:component_id, :event_categories, keyword_init: true)
7
+
8
+ class << self
9
+ def add(component_id:, event_categories:)
10
+ raise Error, I18n.t("decidim.culturoscope.errors.component_id_required") if component_id.blank?
11
+ raise Error, I18n.t("decidim.culturoscope.errors.event_categories_must_be_callable") unless event_categories.respond_to?(:call)
12
+
13
+ id = component_id.to_i
14
+ registry.reject! { |binding| binding.component_id == id }
15
+ registry << Binding.new(component_id: id, event_categories:)
16
+ end
17
+
18
+ def registry
19
+ @registry ||= []
20
+ end
21
+
22
+ def clear
23
+ @registry = []
24
+ end
25
+
26
+ def for(meeting)
27
+ registry.find { |binding| binding.component_id == meeting.decidim_component_id }
28
+ end
29
+
30
+ def bound?(meeting)
31
+ self.for(meeting).present?
32
+ end
33
+
34
+ def registered?(component_id)
35
+ registry.any? { |binding| binding.component_id == component_id.to_i }
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Culturoscope
5
+ class BoundMeetings
6
+ def self.organizations
7
+ enabled_organizations.uniq
8
+ end
9
+
10
+ def self.enabled_organizations
11
+ components.filter_map { |component| component.organization if Availability.enabled?(component.organization) }
12
+ end
13
+
14
+ def self.components(organization = nil)
15
+ Bindings.registry.filter_map { |binding| component_for(binding, organization) }
16
+ end
17
+
18
+ def self.meetings(organization)
19
+ Tenant.call(organization.host) { listed(organization) } || []
20
+ end
21
+
22
+ def self.listed(organization)
23
+ return [] unless Availability.enabled?(organization)
24
+
25
+ components(organization).flat_map { |component| records(component) }
26
+ end
27
+
28
+ def self.component_for(binding, organization)
29
+ component = Decidim::Component.find_by(id: binding.component_id)
30
+ return log_unknown(binding) if component.blank?
31
+ return unless in_organization?(component, organization)
32
+ return log_wrong(component) unless meetings_component?(component)
33
+
34
+ component
35
+ end
36
+
37
+ def self.in_organization?(component, organization)
38
+ organization.blank? || component.organization == organization
39
+ end
40
+
41
+ def self.meetings_component?(component)
42
+ component.manifest_name.to_s == "meetings"
43
+ end
44
+
45
+ def self.records(component)
46
+ meeting_scope.where(component:)
47
+ end
48
+
49
+ def self.meeting_scope
50
+ klass = Decidim::Meetings::Meeting
51
+ return klass.with_deleted if klass.respond_to?(:with_deleted)
52
+
53
+ klass.unscoped
54
+ end
55
+
56
+ def self.log_unknown(binding)
57
+ Rails.logger.warn(I18n.t("decidim.culturoscope.errors.unknown_component_id", component_id: binding.component_id))
58
+ nil
59
+ end
60
+
61
+ def self.log_wrong(component)
62
+ Rails.logger.warn(I18n.t("decidim.culturoscope.errors.component_not_meetings", id: component.id))
63
+ nil
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Culturoscope
5
+ class Configuration
6
+ attr_accessor :api_key, :flux_token, :fallback_image_url, :venue_localities
7
+
8
+ def initialize
9
+ @api_key = ENV.fetch("CULTUROSCOPE_API_KEY", "")
10
+ @flux_token = ENV.fetch("CULTUROSCOPE_FLUX_TOKEN", "")
11
+ @fallback_image_url = ENV.fetch("CULTUROSCOPE_FALLBACK_IMAGE_URL", "")
12
+ @venue_localities = {}
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Culturoscope
5
+ # Flux date_status. RESCHEDULDED / RESCHEDULED (vocabulaire spellings) unused: no Decidim reschedule flag.
6
+ # CANCELLED = deleted_at / withdrawn_at / unpublished / hidden
7
+ # SOLDOUT = registrations enabled and no remaining slots
8
+ module DateStatus
9
+ def self.for(meeting)
10
+ return "CANCELLED" if cancelled?(meeting)
11
+ return "SOLDOUT" if sold_out?(meeting)
12
+
13
+ nil
14
+ end
15
+
16
+ def self.cancelled?(meeting)
17
+ deleted?(meeting) || meeting.withdrawn? || !meeting.published? || EventStatus.hidden?(meeting)
18
+ end
19
+
20
+ def self.sold_out?(meeting)
21
+ meeting.registrations_enabled? && !meeting.has_available_slots?
22
+ end
23
+
24
+ def self.deleted?(meeting)
25
+ return true if meeting.respond_to?(:deleted?) && meeting.deleted?
26
+
27
+ meeting.respond_to?(:deleted_at) && meeting.deleted_at.present?
28
+ end
29
+ end
30
+ end
31
+ end