Skip to content

Commit

Permalink
Merge pull request #142 from OpenSourcePolitics/develop
Browse files Browse the repository at this point in the history
release: Fixes Rack::Attack, Budgets vote count, password configuration
  • Loading branch information
luciegrau authored Oct 17, 2023
2 parents 1ffdd58 + 46963f0 commit aff77ab
Show file tree
Hide file tree
Showing 14 changed files with 10,380 additions and 10,855 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ yarn-debug.log*
.yarn-integrity
app/compiled_views/

.DS_Store
.DS_Store
certificate-https-local/
52 changes: 52 additions & 0 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Builder Stage
FROM ruby:3.0.6-slim as builder

ENV RAILS_ENV=production \
SECRET_KEY_BASE=dummy

WORKDIR /app

RUN apt-get update -q && \
apt-get install -yq libpq-dev curl git libicu-dev build-essential && \
curl https://deb.nodesource.com/setup_16.x | bash && \
apt-get install -y nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
npm install --global yarn && \
gem install bundler:2.4.9

COPY Gemfile Gemfile.lock ./
RUN bundle config set --local without 'test' && \
bundle install -j"$(nproc)"

COPY package.json yarn.lock ./
COPY packages packages
RUN yarn install --frozen-lockfile

COPY . .
RUN bundle exec bootsnap precompile --gemfile app/ lib/ config/ bin/ db/ && \
bundle exec rails deface:precompile && \
bundle exec bin/webpack

# Runner Stage
FROM ruby:3.0.6-slim as runner

ENV RAILS_ENV=production \
SECRET_KEY_BASE=dummy \
RAILS_LOG_TO_STDOUT=true \
LD_PRELOAD="libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:5000,muzzy_decay_ms:5000,narenas:2"

WORKDIR /app

RUN apt-get update -q && \
apt-get install -yq postgresql-client imagemagick libproj-dev proj-bin libjemalloc2 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
gem install bundler:2.4.9

COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY --from=builder /app /app

EXPOSE 3000
CMD ["bundle", "exec", "rails", "server", "-b", "ssl://0.0.0.0:3000?key=/app/certificate-https-local/key.pem&cert=/app/certificate-https-local/cert.pem"]
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ gem "deface"
gem "faker", "~> 2.14"
gem "fog-aws"
gem "foundation_rails_helper", git: "https://github.com/sgruhier/foundation_rails_helper.git"
gem "letter_opener_web", "~> 1.3"
gem "nokogiri", "1.13.4"
gem "omniauth-rails_csrf_protection", "~> 1.0"
gem "puma", ">= 5.5.1"
gem "rack-attack", "~> 6.6"
gem "sys-filesystem"

group :development do
gem "letter_opener_web", "~> 1.3"
gem "listen", "~> 3.1"
gem "rubocop-faker"
gem "spring", "~> 2.0"
Expand Down
99 changes: 30 additions & 69 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,83 +1,44 @@
#### Terraform | Scaleway provider
init-scw:
terraform -chdir=deploy/providers/scaleway init

plan-scw:
@make init-scw
terraform -chdir=deploy/providers/scaleway plan

deploy-scw:
@make init-scw
terraform -chdir=deploy/providers/scaleway apply
run: up
@make create-seeds

destroy-scw:
terraform -chdir=deploy/providers/scaleway destroy
up: generate-certificate
docker-compose -f docker-compose.local.yml up --build -d
@make setup-database

### Docker usage
certificate:
mkdir -p -- ./certificate-https-local

# Docker images commands
generate-certificate: certificate
@if [ ! -f "./certificate-https-local/cert.pem" ]; then \
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=FR/ST=France/L=Paris/O=OpenSourcePolitics/CN=opensourcepolitics.eu" -keyout ./certificate-https-local/key.pem -out ./certificate-https-local/cert.pem; \
fi

REGISTRY := rg.fr-par.scw.cloud
NAMESPACE := decidim-app
VERSION := latest
IMAGE_NAME := decidim-app
TAG := $(REGISTRY)/$(NAMESPACE)/$(IMAGE_NAME):$(VERSION)
# Stops containers and remove volumes
teardown:
docker-compose -f docker-compose.local.yml down -v --rmi all

login:
docker login $(REGISTRY) -u nologin -p $(SCW_SECRET_TOKEN)
create-database:
docker-compose -f docker-compose.local.yml exec app /bin/bash -c 'DISABLE_DATABASE_ENVIRONMENT_CHECK=1 /usr/local/bundle/bin/bundle exec rake db:create'

build-classic:
docker build -t $(IMAGE_NAME):$(VERSION) .
build-scw:
docker build -t $(TAG) .
push:
@make build-scw
@make login
docker push $(TAG)
pull:
@make build-scw
docker pull $(TAG)
setup-database: create-database
docker-compose -f docker-compose.local.yml exec app /bin/bash -c 'DISABLE_DATABASE_ENVIRONMENT_CHECK=1 /usr/local/bundle/bin/bundle exec rake db:migrate'

# Bundle commands
create-database:
docker-compose run app bundle exec rails db:create
run-migrations:
docker-compose run app bundle exec rails db:migrate
# Create seeds
create-seeds:
docker-compose run app bundle exec rails db:seed
docker-compose -f docker-compose.local.yml exec app /bin/bash -c 'DISABLE_DATABASE_ENVIRONMENT_CHECK=1 /usr/local/bundle/bin/bundle exec rake db:schema:load db:seed'

# Database commands
# Restore dump
restore-dump:
bundle exec rake restore_dump
bundle exec rake restore_dump

# Start commands seperated by context
start:
docker-compose up
shell:
docker-compose -f docker-compose.local.yml exec app /bin/bash

start-dumped-decidim:
@make create-database
@make -i restore-dump
@make run-migrations
@make start
start-seeded-decidim:
@make create-database
@make run-migrations
@make create-seeds
@make start
start-clean-decidim:
@make create-database
@make run-migrations
@make start
restart:
docker-compose -f docker-compose.local.yml up -d

# Utils commands
rails-console:
docker exec -it decidim-app_app_1 rails c
connect-app:
docker exec -it decidim-app_app_1 bash
status:
docker-compose -f docker-compose.local.yml ps

# Stop and delete commands
stop:
docker-compose down
delete:
@make stop
docker volume prune
logs:
docker-compose -f docker-compose.local.yml logs app
7 changes: 7 additions & 0 deletions OVERLOADS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Overrides
## Fixes

### Fix: Fix Display of Budgets Summary (#123), 2023-10-09
* `app/views/decidim/budgets/projects/_order_progress.html.erb`
* `app/views/decidim/budgets/projects/_order_total_budget.html.erb`
* (Add class `order-total-budget`)
* `app/views/decidim/budgets/line_items/update_budget.js.erb`
* (Loop on all `order-total-budget` class elements)

### bf363e7 - fix: Fix Display of Budgets Summary (#123), 2023-09-21
* `app/views/decidim/budgets/projects/_order_progress.html.erb`

Expand Down
36 changes: 36 additions & 0 deletions app/views/decidim/budgets/line_items/update_budget.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var $orderTotalBudgets = $('.order-total-budget');
var $orderSelectedProjects = $('#order-selected-projects');
var $orderProgress = $('#order-progress');
var $projectItem = $('#project-<%= project.id %>-item');
var $budgetConfirm = $('#budget-confirm');
var $projectModal = $('#project-modal-<%= project.id %>');

for (let $orderTotalBudget of $orderTotalBudgets) {
morphdom($orderTotalBudget, '<%= j(render partial: "decidim/budgets/projects/order_total_budget").strip.html_safe %>');
}
morphdom($orderSelectedProjects[0], '<%= j(render partial: "decidim/budgets/projects/order_selected_projects").strip.html_safe %>');
morphdom($orderProgress[0], '<%= j(render partial: "decidim/budgets/projects/order_progress").strip.html_safe %>');
morphdom($budgetConfirm[0], '<%= j(render partial: "decidim/budgets/projects/budget_confirm").strip.html_safe %>')

$("#order-progress").foundation();
$(".budget-summary__selected").foundation();
if ($projectItem.length > 0) {
morphdom($projectItem[0], '<%= j(render partial: "decidim/budgets/projects/project", locals: { project: project }).strip.html_safe %>');
}

if ($projectModal.length > 0) {
var $projectModalButtonForm = $(".project-vote-button", $projectModal).parent();
morphdom($projectModalButtonForm[0], '<%= j(cell("decidim/budgets/project_vote_button", project, scale_up: true)).strip.html_safe %>');
}

if ($projectModal.length > 0 && $projectModal.attr("aria-hidden") === "false") {
$(".project-vote-button", $projectModal).focus();
} else {
$(".project-vote-button", $projectItem).focus();
}

<% if @show_help_modal %>
$("#voting-help").foundation("open");
<% end %>

window.DecidimBudgets.checkProgressPosition();
4 changes: 1 addition & 3 deletions app/views/decidim/budgets/projects/_order_progress.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
</strong>
</span>
<% else %>
<div class="budget-summary__total" data-total-allocation="<%= current_order.available_allocation %>" data-total-budget="<%= budget.total_budget %>">
<span class="mini-title"><%= t(".total_budget") %>
<strong class="mini-title__strong mini-title__strong--highlight">
<%= budget_to_currency(budget.total_budget) %>
</strong>
</span>
</div>
<% end %>
</div>
<div class="budget-summary__progressbox budget-summary__progressbox--fixed">
Expand All @@ -55,4 +53,4 @@
</div>
<% end %>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<strong id="order-total-budget" class="order-total-budget mini-title__strong">
<% if current_order.projects_rule? %>
<%= current_order.projects.count %> / <%= current_order.maximum_projects %>
<% else %>
<%= budget_to_currency current_order&.total_budget.to_f %>
<% end %>
</strong>
1 change: 0 additions & 1 deletion config/initializers/decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Decidim.configure do |config|
config.application_name = "Loire Atlantique"
config.mailer_sender = "Loire Atlantique <[email protected]>"
config.expire_session_after = ENV.fetch("DECIDIM_SESSION_TIMEOUT", 180).to_i.minutes

# Admin admin password configurations
Rails.application.secrets.dig(:decidim, :admin_password, :strong).tap do |strong_pw|
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mount Sidekiq::Web => "/sidekiq"
end

mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? || ENV.fetch("ENABLE_LETTER_OPENER", "0") == "1"

mount Decidim::Core::Engine => "/"

Expand Down
77 changes: 77 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
version: '3'
services:
database:
image: postgres
volumes:
- pg-data:/var/lib/postgresql/data
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
memcached:
image: memcached
ports:
- "11211:11211"
redis:
image: redis
ports:
- "6379:6379"
volumes:
- redis-data:/var/lib/redis/data
sidekiq:
build:
context: .
dockerfile: Dockerfile.local
command: [ "bundle", "exec", "sidekiq", "-C", "config/sidekiq.yml" ]
environment:
- DATABASE_HOST=database
- DATABASE_USERNAME=postgres
- DECIDIM_HOST=localhost
- REDIS_URL=redis://redis:6379
- MEMCACHE_SERVERS=memcached:11211
- RAILS_SERVE_STATIC_FILES=true
- RAILS_LOG_TO_STDOUT=true
- ASSET_HOST=localhost:3000
- FORCE_SSL=1
- ENABLE_LETTER_OPENER=1
- SEED=true
- DEFACE_ENABLED=false
- QUESTION_CAPTCHA_HOST=
- DECIDIM_SESSION_TIMEOUT=30
depends_on:
- app
volumes:
- .:/app
links:
- database
- redis
app:
build:
context: .
dockerfile: Dockerfile.local
environment:
- DATABASE_HOST=database
- DATABASE_USERNAME=postgres
- DECIDIM_HOST=localhost
- REDIS_URL=redis://redis:6379
- MEMCACHE_SERVERS=memcached:11211
- RAILS_SERVE_STATIC_FILES=true
- RAILS_LOG_TO_STDOUT=true
- ASSET_HOST=localhost:3000
- FORCE_SSL=1
- ENABLE_LETTER_OPENER=1
- SEED=true
- DEFACE_ENABLED=false
- QUESTION_CAPTCHA_HOST=
- DECIDIM_SESSION_TIMEOUT=30
volumes:
- .:/app
ports:
- 3000:3000
depends_on:
- database
- redis
- memcached

volumes:
app-data: { }
pg-data: { }
redis-data: { }
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def after_sign_in_path_for(user)
end
end

def after_sign_out_path_for(user)
stored_location_for(user) || super
end

private

# Skip authorization handler by default
Expand Down
Loading

0 comments on commit aff77ab

Please sign in to comment.