Skip to content

Commit

Permalink
conferences external links (#127)
Browse files Browse the repository at this point in the history
* Use env vars for conference registrations

* check interpolation

* fix donate/chat buttons in assemblies/conferences

* normalize i18n

* exclude overrides

* update fixes
  • Loading branch information
microstudi authored Nov 3, 2023
1 parent f36f7f6 commit 6b92acf
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gem "decidim", DECIDIM_VERSION
gem "decidim-calendar", github: "decidim-ice/decidim-module-calendar", tag: "54b486c84f1c65b69b0aab66160c32bafc4fe376"
gem "decidim-civicrm", github: "openpoke/decidim-module-civicrm", branch: "release/0.26-stable"
gem "decidim-conferences", DECIDIM_VERSION
gem "decidim-decidim_awesome", github: "openpoke/decidim-module-decidim_awesome", branch: "graded_voting/final-fixes"
gem "decidim-decidim_awesome", github: "decidim-ice/decidim-module-decidim_awesome", branch: "develop"
gem "decidim-direct_verifications"
gem "decidim-templates", DECIDIM_VERSION
gem "decidim-term_customizer", github: "mainio/decidim-module-term_customizer", branch: "release/0.26-stable"
Expand Down
22 changes: 11 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ GIT
decidim-admin (>= 0.25.0, < 0.27)
decidim-core (>= 0.25.0, < 0.27)

GIT
remote: https://github.com/decidim-ice/decidim-module-decidim_awesome.git
revision: 43a61bd7099a04b47fdab9cffb0623c02d308ab1
branch: develop
specs:
decidim-decidim_awesome (0.10.0)
decidim-admin (>= 0.26.0, < 0.28)
decidim-core (>= 0.26.0, < 0.28)
deface (>= 1.5)
sassc (~> 2.3)

GIT
remote: https://github.com/mainio/decidim-module-term_customizer.git
revision: f0d720710822f1231ea249dd71f978143d38a6c4
Expand All @@ -27,17 +38,6 @@ GIT
decidim-verifications (>= 0.26.1, < 0.27)
deface (~> 1.5)

GIT
remote: https://github.com/openpoke/decidim-module-decidim_awesome.git
revision: 6d30e1641f021ecbd844abd2c811992a99fffc0d
branch: graded_voting/final-fixes
specs:
decidim-decidim_awesome (0.9.3)
decidim-admin (>= 0.26.0, < 0.28)
decidim-core (>= 0.26.0, < 0.28)
deface (>= 1.5)
sassc (~> 2.3)

GIT
remote: https://github.com/openpoke/decidim.git
revision: a9b258209af14ac28494bb45e93d97e90de930cf
Expand Down
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,41 @@ This is the open-source repository for https://gpcmembers.com based on [Decidim]

## Deploying the app

Deployed with [Capistrano](http://capistranorb.com/) using [Figaro](https://github.com/laserlemon/figaro) for `ENV` configuration.
This is a [Ruby on Rails](https://rubyonrails.org/) application packaged with Docker. It can be deployed into a Docker (or a Docker Swarm) environment with the usual commands:

In your machine, execute:
```bash
docker-compose up -d
```

To update between commit, you can force the build:

```bash
cap production deploy
docker-compose up -d --build
```

To enter the container and run commands, you can use (you need to have the container running):

```bash
docker-compose exec app bash
```

Once inside, you can run Rails/rake command as usual:

```bash
bin/rails db:migrate:status
```

Or enter the Rails console:

```bash
bin/rails c
```

Note that some ENV vars are dedicated to the Docker environment. Please check the [entrypoint.sh](entrypoint.sh) for details.
Mainly, you can specify if you want to run the Sidekiq worker or the Rails server with the `RUN_SIDEKIQ` ENV var. If not specified, defaults to false. Also the env `RUN_RAILS` is available to run the Rails server (defaults to true).

Finally, note that every time the container is started migrations are run. If you want to avoid this, you can use the `SKIP_MIGRATIONS` ENV var.

### ENV vars

These ENV vars modifies the behavior of the application in some ways:
Expand All @@ -40,6 +67,7 @@ These ENV vars modifies the behavior of the application in some ways:
| `ALWAYS_SHOW_DONATE_BUTTON` | if `true`, all proposals will show a generic donate button in the sidebar |
| `TRANSLATOR_API_KEY` | If defined, automatic translations are enabled. We use [DeepL API](https://www.deepl.com/pro-api) service, only api keys from there are valid |
| `TRANSLATOR_HOST` | The URL for the translator API. For the free service must be `https://api-free.deepl.com`. For the "pro" service is `https://api.deepl.com` |
| `CONFERENCE_{CONF_SLUG}_REGISTRATION` | If defined, it will replace the link to register into a conference by the one provided in this env var. Note that `{CONF_SLUG}` corresponds to the "slug" of the conference replacing any `-` hyphen with an `_` underscore. For instance a conference with the slug `gpc-2023` will expect an env var called `CONFERENCE_GPC_2023_REGISTRATION`. Also, language interpolation is available by substituing any string `%{locale}` by the current locale. |

Please refer to the private documentation repository for further details.

Expand Down
17 changes: 15 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ def donate_link(name)
end

def generic_donate_url
@generic_donate_url ||= Rails.application.secrets.dig(:gpc, :donate_button).gsub("%{locale}", I18n.locale.to_s)
@generic_donate_url ||= begin
path = Rails.application.secrets.dig(:gpc, :donate_button).presence
path ? path.gsub("%{locale}", I18n.locale.to_s) : nil
end
end

def generic_chat_url
@generic_chat_url ||= Rails.application.secrets.dig(:gpc, :chat_button).gsub("%{locale}", I18n.locale.to_s)
@generic_chat_url ||= begin
path = Rails.application.secrets.dig(:gpc, :chat_button).presence
path ? path.gsub("%{locale}", I18n.locale.to_s) : nil
end
end

def campaign_assembly_link(title)
Expand All @@ -55,4 +61,11 @@ def campaign_assembly_link(title)

decidim_assemblies.assembly_path(assembly.slug)
end

def external_conference_registration
@external_conference_registration ||= begin
path = ENV.fetch("CONFERENCE_#{current_participatory_space.slug.parameterize.gsub(/[^a-z0-9]/, "_").upcase}_REGISTRATION", nil).presence
path ? path.gsub("%{locale}", I18n.locale.to_s) : nil
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- insert_before '.card.extra.definition-data' -->

<%= render "decidim/donate" %>
<%= render "decidim/chat" %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- replace '.column.medium-9.medium-centered > erb[silent]:contains("if current_participatory_space.registrations_enabled?")' -->

<% if external_conference_registration %>
<div class="column medium-6">
<%= render "decidim/conferences/external_register_button" %>
</div>
<% elsif current_participatory_space.registrations_enabled? %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- replace '.columns.mediumlarge-12 > erb[silent]:contains("if current_participatory_space.registrations_enabled?")' -->

<% if external_conference_registration %>
<hr class="reset mt-none mb-m">
<section class="section">
<h3 class="section-heading"><%= t(".register") %></h3>
<div class="card p-m text-center">
<p><%= t(".make_conference_registration") %></p>
<div class="medium-3" style="margin: 0 auto;">
<%= render "decidim/conferences/external_register_button" %>
</div>
</div>
</div>
<% elsif current_participatory_space.registrations_enabled? %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- replace '.section:first' -->

<% if generic_donate_url || generic_chat_url %>
<div class="row">
<div class="column medium-9">
<h3 class="section-heading"><%= t("conferences.show.introduction", scope: "decidim") %></h3>
<%= decidim_sanitize_editor_admin translated_attribute(current_participatory_space.short_description) %>
</div>
<div class="column medium-3">
<%= render "decidim/donate" %>
<%= render "decidim/chat" %>
</div>
</div>
<% else %>
<h3 class="section-heading"><%= t("conferences.show.introduction", scope: "decidim") %></h3>
<%= decidim_sanitize_editor_admin translated_attribute(current_participatory_space.short_description) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- insert_before 'erb[loud]:contains("resource_reference(@proposal)")' -->

<% if show_donate_on_proposal? %>
<%= render "decidim/donate" %>
<%= render "decidim/donate" %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- replace 'erb[silent]:contains("if current_participatory_space.registrations_enabled?")' -->

<% if external_conference_registration %>
<div class="column medium-3 end">
<%= render "decidim/conferences/external_register_button" %>
</div>
<% elsif current_participatory_space.registrations_enabled? %>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- replace '.logo-wrapper' -->

<div class="logo-wrapper">
<%= content_tag :svg, role: "img" do
content_tag(:title, current_organization.name) +
<%= content_tag :svg, role: "img" do
content_tag(:title, current_organization.name) +
content_tag(:use, "", "href" => asset_pack_path("media/images/greenparty-#{locale}.svg") + "#logo")
end %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= link_to t("layouts.decidim.conference_hero.register"), external_conference_registration, target: "_blank", class:"button button--sc light expanded" %>
2 changes: 2 additions & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data:
- "<%= %x[bundle info decidim-assemblies --path].chomp %>/config/locales/%{locale}.yml"
- "<%= %x[bundle info decidim-participatory_processes --path].chomp %>/config/locales/%{locale}.yml"
- "<%= %x[bundle info decidim-proposals --path].chomp %>/config/locales/%{locale}.yml"
- "<%= %x[bundle info decidim-conferences --path].chomp %>/config/locales/%{locale}.yml"
## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class.
# router: conservative_router

Expand Down Expand Up @@ -72,6 +73,7 @@ search:
- app/assets/images
- app/assets/fonts
- app/assets/videos
- app/overrides

## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`:
## If specified, this settings takes priority over `exclude`, but `exclude` still applies.
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ en:
email_not_registered: Sorry, the email %{email} is not registered. Only existing users are allowed to login.
gpc:
campaign_space: "%{name} Campaign"
chat_button: AGM Chat (beta)
chat_button: GREEN CHAT (beta)
donate: Donate to %{name}
donate_button: Donate $10
donate_text_1: We're building a new kind of politics. One that is open, participatory, and people-powered
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fr:
email_not_registered: Désolé, l'email %{email} n'est pas enregistré. Seuls les utilisateurs existants sont autorisés à se connecter.
gpc:
campaign_space: Campagne de %{name}
chat_button: Chat AG (beta)
chat_button: CHAT VERT (beta)
donate: Faites un don à %{name}
donate_button: Don $10
donate_text_1: Nous construisons un nouveau type de politique. Une politique ouverte et participative
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ services:
- DECIDIM_FORCE_SSL=false
- QUEUE_ADAPTER=sidekiq
- REDIS_URL=redis://redis:6379/1
- SIDEKIQ_WORKER=true
- RUN_RAILS=false
- RUN_SIDEKIQ=true
depends_on:
- redis
command: /app/init.sh
Expand Down
1 change: 1 addition & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

require "decidim/core/test/factories"
require "decidim/proposals/test/factories"
require "decidim/conferences/test/factories"
require "decidim/decidim_awesome/test/factories"
7 changes: 7 additions & 0 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
"/app/views/decidim/assemblies/assemblies/show.html.erb" => "9b06118d61009d60fbe955e81593f74b"
}
},
{
package: "decidim-conferences",
files: {
"/app/views/decidim/conferences/conferences/show.html.erb" => "94e3fb8ee4e092678ce0f229c87e1bc0",
"/app/views/layouts/decidim/_conference_hero.html.erb" => "db2e565169a5ce7f8a3e7d03dd0ebfd9"
}
},
{
package: "decidim-participatory_processes",
files: {
Expand Down
79 changes: 79 additions & 0 deletions spec/system/conference_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

require "rails_helper"

describe "Visit a conference", type: :system do
let(:organization) { create :organization }
let(:conference) { create :conference, slug: slug, registrations_enabled: registrations_enabled, organization: organization }
let(:registrations_enabled) { true }
let(:slug) { "my-conference" }
let(:conference_env) { "CONFERENCE_#{slug.gsub("-", "_").upcase}_REGISTRATION" }
let(:external_path) { "https://example.org" }
let(:compare_path) { external_path }

before do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with(conference_env, nil).and_return(external_path)
switch_to_host(organization.host)
visit decidim_conferences.conference_path(conference)
end

shared_examples "external links" do
it "has a link to external site" do
expect(page).to have_link("Register", href: compare_path, count: 3)
expect(page).not_to have_link("Register", href: decidim_conferences.conference_registration_types_path(conference))
end
end

shared_examples "internal links" do
it "has the internal link" do
expect(page).to have_link("Register", href: decidim_conferences.conference_registration_types_path(conference), count: 2)
expect(page).not_to have_link("Register", href: compare_path)
end
end

shared_examples "no links" do
it "has no registration" do
expect(page).not_to have_link("Register")
end
end

it_behaves_like "external links"

context "when language interpolation" do
let(:external_path) { "https://example.org/%{locale}" }
let(:compare_path) { "https://example.org/#{I18n.locale}" }

it_behaves_like "external links"
end

context "when registrations not enabled" do
let(:registrations_enabled) { false }

it_behaves_like "external links"
end

context "when no path" do
let(:external_path) { "" }

it_behaves_like "internal links"

context "when registrations not enabled" do
let(:registrations_enabled) { false }

it_behaves_like "no links"
end
end

context "when no env" do
let(:conference_env) { "CONFERENCE_OTHER_CONFERENCE_REGISTRATION" }

it_behaves_like "internal links"

context "when registrations not enabled" do
let(:registrations_enabled) { false }

it_behaves_like "no links"
end
end
end
Loading

0 comments on commit 6b92acf

Please sign in to comment.