From 08d953b3975f0d189e94c4d85249428733827414 Mon Sep 17 00:00:00 2001 From: takahashim Date: Fri, 1 Apr 2022 01:44:52 +0900 Subject: [PATCH 1/4] Copy Decidim::Debates::VersionsController from decidim-debates --- .../decidim/debates/versions_controller.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/controllers/decidim/debates/versions_controller.rb diff --git a/app/controllers/decidim/debates/versions_controller.rb b/app/controllers/decidim/debates/versions_controller.rb new file mode 100644 index 0000000000..55e289e4d9 --- /dev/null +++ b/app/controllers/decidim/debates/versions_controller.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Decidim + module Debates + # Exposes Debates versions so users can see how a Debate has been updated + # through time. + class VersionsController < Decidim::Proposals::ApplicationController + include Decidim::ApplicationHelper + include Decidim::ResourceVersionsConcern + + def versioned_resource + @versioned_resource ||= present(Debate.where(component: current_component).find(params[:debate_id])) + end + end + end +end From 0ba0ce5373a27ffb91e2862b9ae1a2dd3c4972ef Mon Sep 17 00:00:00 2001 From: takahashim Date: Fri, 1 Apr 2022 01:52:08 +0900 Subject: [PATCH 2/4] Fix: do not display changeset if it is too large --- app/controllers/decidim/debates/versions_controller.rb | 10 ++++++++++ config/locales/en.yml | 4 ++++ config/locales/ja.yml | 2 ++ 3 files changed, 16 insertions(+) diff --git a/app/controllers/decidim/debates/versions_controller.rb b/app/controllers/decidim/debates/versions_controller.rb index 55e289e4d9..0e5e106013 100644 --- a/app/controllers/decidim/debates/versions_controller.rb +++ b/app/controllers/decidim/debates/versions_controller.rb @@ -8,9 +8,19 @@ class VersionsController < Decidim::Proposals::ApplicationController include Decidim::ApplicationHelper include Decidim::ResourceVersionsConcern + OBJECT_CHANGE_SIZE_LIMIT = 1_000_000 + def versioned_resource @versioned_resource ||= present(Debate.where(component: current_component).find(params[:debate_id])) end + + def show + description = current_version.object_changes + if description.size > OBJECT_CHANGE_SIZE_LIMIT + flash[:alert] = I18n.t("debates.versions.too_large_changeset", scope: "decidim.debates") + redirect_to action: :index + end + end end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 8fcc08be2c..f81b5a168d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,6 +9,10 @@ en: occupation: Occupation real_name: Real Name decidim: + debates: + debates: + versions: + too_large_changeset: This changeset is too large to show. following: non_public_followings: Some of the resources followed are not public. enums: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index d7a443e5ee..a09abf22d4 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -79,6 +79,8 @@ ja: citizens: 一般参加者 official: 事務局 origin: 起案者 + versions: + too_large_changeset: 履歴のサイズが大きすぎるため表示できません devise: registrations: new: From 153685b6bfcee60b1a2dbf34287e42154fab99d6 Mon Sep 17 00:00:00 2001 From: takahashim Date: Mon, 4 Apr 2022 19:37:29 +0900 Subject: [PATCH 3/4] Add comments in UPGRADE.md --- docs/UPGRADE.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/UPGRADE.md b/docs/UPGRADE.md index 5ebde399b8..fa5efb31c6 100644 --- a/docs/UPGRADE.md +++ b/docs/UPGRADE.md @@ -33,6 +33,10 @@ Decidim本体のバージョンを更新する際、特に注意が必要な内 https://github.com/decidim/decidim/pull/7781 で本家にフィードバックしたので、これが取り込まれたバージョン(v0.25.0以降)になればファイルごと削除できるはずです。 +* `app/controllers/decidim/debates/versions_controller.rb` + + https://github.com/codeforjapan/decidim-cfj/pull/359 で追加したファイル。履歴の差分が巨大になるとサーバ負荷が大きいため、renderを実行させないよう表示前にredirectさせるものです。 + * `app/forms/decidim/proposals/proposal_wizard_create_step_form.rb`, `app/forms/decidim/proposals/admin/proposal_form.rb` https://github.com/codeforjapan/decidim-cfj/issues/23 の対応のために追加されたもの。対応するPRは https://github.com/codeforjapan/decidim-cfj/pull/60 https://github.com/codeforjapan/decidim-cfj/pull/163 です。 From 8b0f3cfcb3ab091bad8d89257d517b8e9534d19c Mon Sep 17 00:00:00 2001 From: takahashim Date: Mon, 4 Apr 2022 19:56:13 +0900 Subject: [PATCH 4/4] RSpec: Add ignore query option --- spec/sytem/needs_user_extension_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/sytem/needs_user_extension_spec.rb b/spec/sytem/needs_user_extension_spec.rb index 4097efd626..235a5576ef 100644 --- a/spec/sytem/needs_user_extension_spec.rb +++ b/spec/sytem/needs_user_extension_spec.rb @@ -19,7 +19,7 @@ context "without user extension" do it "redirect to account page" do visit decidim.notifications_path - expect(page).to have_current_path(decidim.account_path) + expect(page).to have_current_path(decidim.account_path, ignore_query: true) end it "not redirect in root page" do