Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: v2.5.2 #650

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/controllers/decidim/system/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Decidim
module System
class DashboardController < Decidim::System::ApplicationController
before_action :check_organizations_presence

def show
@organizations = Organization.all
@db_size = db_size
end

def check_organizations_presence
return if Organization.exists?

redirect_to new_organization_path
end

private

def db_size
dbname = ActiveRecord::Base.connection.current_database
sql = "SELECT pg_size_pretty(pg_database_size('#{dbname}'));"
ActiveRecord::Base.connection.execute(sql)[0]["pg_size_pretty"]
end
end
end
end
17 changes: 17 additions & 0 deletions app/jobs/concerns/decidim/logging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Decidim
module Logging
private

def log!(msg, level = :warn)
msg = "(#{self.class}) #{Time.current.strftime("%d-%m-%Y %H:%M")}> #{msg}"
case level
when :info
Rails.logger.info msg
else
Rails.logger.warn msg
end
end
end
end
53 changes: 53 additions & 0 deletions app/jobs/decidim/papertrail_versions_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

module Decidim
class PapertrailVersionsJob < ApplicationJob
queue_as :default

include Decidim::Logging

def perform(ret = nil)
ret = retention(ret)

log! "Cleaning versions in database..."
log! "Cleaning item_types : #{item_types.join(", ")}"

total = 0
PaperTrail::Version.where(item_type: item_types).where("created_at <= ?", ret).in_batches(of: 5000) do |versions|
total += versions.size
versions.destroy_all
end

log! "#{total} versions have been removed"
end

private

def retention(ret)
return ret if ret.present? && ret.is_a?(Time)

ret = Rails.application.secrets.dig(:decidim, :database, :versions, :clean, :retention)
ret.months.ago
end

# Exhaustive list of item_types to remove from versions table
def item_types
@item_types ||= %w(
Decidim::Accountability::TimelineEntry
Decidim::Accountability::Result
Decidim::Attachment
Decidim::AttachmentCollection
Decidim::Blogs::Post
Decidim::Budgets::Project
Decidim::Comments::Comment
Decidim::Conferences::MediaLink
Decidim::Conferences::Partner
Decidim::Debates::Debate
Decidim::Categorization
Decidim::Categorization
Decidim::Forms::Questionnaire
Decidim::UserBaseEntity
)
end
end
end
12 changes: 12 additions & 0 deletions app/views/decidim/system/dashboard/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% provide :title do %>
<h2><%= t("decidim.system.titles.dashboard.title") %></h2>
<h3><%= t ".current_organizations" %></h3>
<%= render partial: "decidim/system/shared/organizations_list", locals: { organizations: @organizations } %>
<% end %>
<div class="header">
<h3><%= I18n.t("decidim.system.titles.dashboard.info.title") %></h3>
<div>
<p><%= I18n.t("decidim.system.titles.dashboard.info.db_size", db_size: @db_size) %></p>
<p><%= I18n.t("decidim.system.titles.dashboard.info.decidim_version", version: Decidim.version) %></p>
</div>
</div>
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Application < Rails::Application
require "extends/controllers/decidim/admin/scopes_controller_extends"
require "extends/controllers/decidim/scopes_controller_extends"
require "extends/controllers/decidim/initiatives/committee_requests_controller_extends"
require "extends/controllers/decidim/comments/comments_controller"
# Models
require "extends/models/decidim/budgets/project_extends"
require "extends/models/decidim/authorization_extends"
Expand All @@ -67,6 +68,7 @@ class Application < Rails::Application
# Forms
require "extends/forms/decidim/initiatives/initiative_form_extends"
require "extends/forms/decidim/initiatives/admin/initiative_form_extends"
require "extends/forms/decidim/comments/comment_form_extends"
# Commands
require "extends/commands/decidim/initiatives/admin/update_initiative_answer_extends"
require "extends/commands/decidim/budgets/admin/import_proposals_to_budgets_extends"
Expand Down
6 changes: 4 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,18 @@
config.action_mailer.default_url_options = { port: 3000 }
else
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
smtp_settings = {
address: Rails.application.secrets.smtp_address,
port: Rails.application.secrets.smtp_port,
authentication: Rails.application.secrets.smtp_authentication,
user_name: Rails.application.secrets.smtp_username,
password: Rails.application.secrets.smtp_password,
domain: Rails.application.secrets.smtp_domain,
enable_starttls_auto: Rails.application.secrets.smtp_starttls_auto,
openssl_verify_mode: "none"
}
smtp_settings = smtp_settings.merge(authentication: Rails.application.secrets.smtp_authentication) if smtp_settings[:user_name].present? && smtp_settings[:password].present?

config.action_mailer.smtp_settings = smtp_settings

if Rails.application.secrets.sendgrid
config.action_mailer.default_options = {
Expand Down
2 changes: 2 additions & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,7 @@ ignore_unused:
- decidim.events.proposals.author_confirmation_proposal_event.email_intro
- decidim.events.proposals.author_confirmation_proposal_event.email_outro
- decidim.events.proposals.author_confirmation_proposal_event.notification_title
- decidim.system.titles.{dashboard,title}
- decidim.system.titles.info.*


1 change: 1 addition & 0 deletions config/initializers/extends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

require "decidim/exporters/serializer"
require "extends/lib/decidim/forms/user_answers_serializer_extend"
require "extends/lib/decidim/geocoding/geocoder_coordinates_extends"
14 changes: 14 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ en:
projects_count:
one: 1 project
other: "%{count} projects"
comments:
comments:
create:
error: There was a problem creating the comment.
devise:
sessions:
new:
Expand Down Expand Up @@ -206,6 +210,9 @@ en:
please_sign_in: Please sign in
sign_up: Sign up
system:
dashboard:
show:
current_organizations: Current organizations
organizations:
omniauth_settings:
france_connect:
Expand Down Expand Up @@ -241,6 +248,13 @@ en:
client_id: Client ID
client_secret: Client secret
site_url: Site URL
titles:
dashboard:
info:
db_size: 'Database size: %{db_size}'
decidim_version: 'Decidim version: v%{version}'
title: General informations
title: Dashboard
verifications:
authorizations:
create:
Expand Down
14 changes: 14 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ fr:
projects_count:
one: 1 projet
other: "%{count} projets"
comments:
comments:
create:
error: Une erreur s'est produite lors du vote sur le commentaire.
devise:
sessions:
new:
Expand Down Expand Up @@ -208,6 +212,9 @@ fr:
please_sign_in: Veuillez vous connecter
sign_up: Créer un compte
system:
dashboard:
show:
current_organizations: Organisations
organizations:
omniauth_settings:
france_connect:
Expand Down Expand Up @@ -243,6 +250,13 @@ fr:
client_id: Client ID
client_secret: Client secret
site_url: Site URL
titles:
dashboard:
info:
db_size: 'Poids base de données: %{db_size}'
decidim_version: 'Decidim version: v%{version}'
title: Informations générales
title: Tableau de bord système
verifications:
authorizations:
create:
Expand Down
4 changes: 4 additions & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ default: &default
authorizations:
export_data_to_userdata_enabled_for: <%= ENV.fetch("AUTO_EXPORT_AUTHORIZATIONS_DATA_TO_USER_DATA_ENABLED_FOR", "") %>
currency: <%= ENV["CURRENCY"] || "€" %>
database:
versions:
clean:
retention: <%= ENV.fetch("DECIDIM_DB_VERSIONS_RETENTION", "6")&.to_i %>
half_signup:
show_tos_page_after_signup: <%= ENV.fetch("DECIDIM_HALF_SIGNUP_SHOW_TOS_PAGE_AFTER_SIGNUP", "true") == "true" %>
initiatives:
Expand Down
4 changes: 4 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@
cron: "0 9 0 * * *"
class: Decidim::Cleaner::CleanDeletedUsersDataJob
queue: scheduled
PapertrailCleanVersions:
cron: '0 0 3 * * *'
class: Decidim::PapertrailVersionJob
queue: default
61 changes: 61 additions & 0 deletions lib/extends/controllers/decidim/comments/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require "active_support/concern"
module CommentsControllerExtends
extend ActiveSupport::Concern
included do
def update
set_comment
@commentable = comment.commentable
enforce_permission_to :update, :comment, comment: comment

form = Decidim::Comments::CommentForm.from_params(
params.merge(commentable: comment.commentable, current_component: current_component)
).with_context(
current_organization: current_organization
)

Decidim::Comments::UpdateComment.call(comment, current_user, form) do
on(:ok) do
respond_to do |format|
format.js { render :update }
end
end

on(:invalid) do
respond_to do |format|
format.js { render :update_error }
end
end
end
end

def create
enforce_permission_to :create, :comment, commentable: commentable

form = Decidim::Comments::CommentForm.from_params(
params.merge(commentable: commentable, current_component: current_component)
).with_context(
current_organization: current_organization,
current_component: current_component
)
Decidim::Comments::CreateComment.call(form, current_user) do
on(:ok) do |comment|
handle_success(comment)
respond_to do |format|
format.js { render :create }
end
end

on(:invalid) do
@error = t("create.error", scope: "decidim.comments.comments")
respond_to do |format|
format.js { render :error }
end
end
end
end
end
end

Decidim::Comments::CommentsController.include(CommentsControllerExtends)
15 changes: 15 additions & 0 deletions lib/extends/forms/decidim/comments/comment_form_extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "active_support/concern"

module CommentFormExtends
extend ActiveSupport::Concern

included do
attribute :current_component, Decidim::Component

validates :current_component, presence: true
end
end

Decidim::Comments::CommentForm.include(CommentFormExtends)
16 changes: 16 additions & 0 deletions lib/extends/lib/decidim/geocoding/geocoder_coordinates_extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module GeocoderCoordinatesExtends
def coordinates(address, options = {})
if address.to_s.match?(/^(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)$/)
address_parts = address.to_s.split(/\s*,\s*/)
[address_parts[0].to_f, address_parts[1].to_f]
elsif (results = search(address, options)).size.positive?
results.first.coordinates
end
end
end

Geocoder.singleton_class.class_eval do
prepend(GeocoderCoordinatesExtends)
end
12 changes: 12 additions & 0 deletions lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,17 @@ namespace :decidim do
Decidim::SurveysService.new(verbose: true).clear
end
end

namespace :versions do
desc "Clean versions"
task clean: :environment do
puts "(decidim:db:versions:clean) #{Time.current.strftime("%d-%m-%Y %H:%M:%S")}> Executing PapertrailVersionsJob..."
retention = Rails.application.secrets.dig(:decidim, :database, :versions, :clean, :retention)
retention = retention.months.ago
puts "(decidim:db:versions:clean) #{Time.current.strftime("%d-%m-%Y %H:%M:%S")}> Clean versions created before #{retention.strftime("%d-%m-%Y %H:%M:%S")}..."
Decidim::PapertrailVersionsJob.perform_later(retention)
puts "(decidim:db:versions:clean) #{Time.current.strftime("%d-%m-%Y %H:%M:%S")}> Job delayed to Sidekiq."
end
end
end
end
Loading
Loading