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

Fix broken dashboard action logs under certain conditions #6857

Merged
merged 7 commits into from
Nov 25, 2020

Conversation

ahukkanen
Copy link
Contributor

@ahukkanen ahukkanen commented Nov 12, 2020

🎩 What? Why?

There is a programming mistake in most action log presenters that can cause the action log views to break when the version record is not available (for one reason or another) and the diff is set to be shown.

If you take a look at the has_diff? method in the BasePresenter, it tries to assume that the action log version record is always available in order to show its changeset:

def has_diff?
%w(update create).include?(action.to_s) && action_log.version.present?
end

However, this check is bypassed by most of the action log record specific presenters, such as the proposal presenter as you can see here:

def has_diff?
action == "answer" || super
end

So, if for one reason or another, the action log's version record is not set properly, is deleted, etc. the dashboard index page and the action logs page could be totally broken.

Of course, this does not happen under "normal" and "stable" conditions when everything has been stored normally but it is certainly possible that the version record is not always available for the action log.

This ensures this is always the case and adds a shared example spec which is applied to all of these records that may have had this problem before. If you run those tests against the current core, they would fail.

The exception that you may see in the application logs should look something like this:

Show stacktrace
F, [2020-11-12T10:06:21.384159 #13416] FATAL -- : [a1bcd234-5e67-890a-bc12-34d56efa789b] ActionView::Template::Error (undefined method `changeset' for nil:NilClass):
F, [2020-11-12T10:06:21.384256 #13416] FATAL -- : [a1bcd234-5e67-890a-bc12-34d56efa789b]      8:     <% if logs.any? %>
[a1bcd234-5e67-890a-bc12-34d56efa789b]      9:       <ul class="logs table">
[a1bcd234-5e67-890a-bc12-34d56efa789b]     10:         <% logs.each do |log| %>
[a1bcd234-5e67-890a-bc12-34d56efa789b]     11:           <%= render_log(log) %>
[a1bcd234-5e67-890a-bc12-34d56efa789b]     12:         <% end %>
[a1bcd234-5e67-890a-bc12-34d56efa789b]     13:       </ul>
[a1bcd234-5e67-890a-bc12-34d56efa789b]     14:     <% else %>
F, [2020-11-12T10:06:21.384285 #13416] FATAL -- : [a1bcd234-5e67-890a-bc12-34d56efa789b]   
F, [2020-11-12T10:06:21.384355 #13416] FATAL -- : [a1bcd234-5e67-890a-bc12-34d56efa789b] /home/decidim/staging/shared/bundle/ruby/2.6.0/bundler/gems/decidim-21e4a981fe35/decidim-core/app/presenters/dec
idim/log/base_presenter.rb:247:in `changeset'
[a1bcd234-5e67-890a-bc12-34d56efa789b] /home/decidim/staging/shared/bundle/ruby/2.6.0/bundler/gems/decidim-21e4a981fe35/decidim-core/app/presenters/decidim/log/base_presenter.rb:131:in `diff_presenter'
[a1bcd234-5e67-890a-bc12-34d56efa789b] /home/decidim/staging/shared/bundle/ruby/2.6.0/bundler/gems/decidim-21e4a981fe35/decidim-core/app/presenters/decidim/log/base_presenter.rb:145:in `present_diff'
[a1bcd234-5e67-890a-bc12-34d56efa789b] /home/decidim/staging/shared/bundle/ruby/2.6.0/bundler/gems/decidim-21e4a981fe35/decidim-core/app/presenters/decidim/log/base_presenter.rb:155:in `block in presen
t_action_log'
[a1bcd234-5e67-890a-bc12-34d56efa789b] actionview (5.2.4.4) lib/action_view/helpers/capture_helper.rb:41:in `block in capture'
[a1bcd234-5e67-890a-bc12-34d56efa789b] actionview (5.2.4.4) lib/action_view/helpers/capture_helper.rb:205:in `with_output_buffer'
[a1bcd234-5e67-890a-bc12-34d56efa789b] actionview (5.2.4.4) lib/action_view/helpers/capture_helper.rb:41:in `capture'
[a1bcd234-5e67-890a-bc12-34d56efa789b] actionview (5.2.4.4) lib/action_view/helpers/tag_helper.rb:272:in `content_tag'
[a1bcd234-5e67-890a-bc12-34d56efa789b] /home/decidim/staging/shared/bundle/ruby/2.6.0/bundler/gems/decidim-21e4a981fe35/decidim-core/app/presenters/decidim/log/base_presenter.rb:153:in `present_action_
log'
[a1bcd234-5e67-890a-bc12-34d56efa789b] /home/decidim/staging/shared/bundle/ruby/2.6.0/bundler/gems/decidim-21e4a981fe35/decidim-core/app/presenters/decidim/log/base_presenter.rb:43:in `present'

Testing

  • Create a Decidim instance with the default seed content
  • Go to one of the proposals components and answer to a proposal
  • Run the following in the Rails console: Decidim::ActionLog.last.update!(version_id: nil)
  • Go to the dashboard index view as an admin

📋 Checklist

  • CONSIDER adding a unit test if your PR resolves an issue.
  • ✔️ DO check open PR's to avoid duplicates.
  • ✔️ DO keep pull requests small so they can be easily reviewed.
  • ✔️ DO build locally before pushing.
  • ✔️ DO make sure tests pass.
  • ✔️ DO make sure any new changes are documented in docs/.
  • ✔️ DO add and modify seeds if necessary.
  • ✔️ DO add CHANGELOG upgrade notes if required.
  • ✔️ DO add to GraphQL API if there are new public fields.
  • ✔️ DO add link to MetaDecidim if it's a new feature.
  • AVOID breaking the continuous integration build.
  • AVOID making significant changes to the overall architecture.

@@ -5,7 +5,7 @@
module Decidim
module Assemblies
module AdminLog
describe AssembliesTypePresenter, type: :helper do
describe AdminLog::AssembliesTypePresenter, type: :helper do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to simply specify the whole class & module names?

describe Decidim::Assemblies::AdminLog::AssembliesTypePresenter do

Same for the rest of the files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrcasals At some point I got Rubocop violation for doing that but I'm not sure if the rules have changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrcasals I tried to change it like this and this is what I get:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird, because we have specs similar to what you post:

describe Decidim::Assemblies::AdminLog::ValueTypes::MemberPositionPresenter, type: :helper do

Maybe your Rubocop is not getting the Decidim config for some reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's using the correct config. Other cops work totally fine.

It seems to be an issue with the VSCode extension:
rubyide/vscode-ruby#625

Althrough I don't know where it's coming from because what that extension is doing is running the same rubocop that I can run on the command line...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrcasals It's now changed as you proposed.

I assume the issue is in rubocop-rspec, I reported it here with further details:
rubocop/rubocop-rspec#1091

The result of that cop depends where rubocop is run from which doesn't seem right to me. The CI runs it in the root of the project when it works correctly. The VSCode extension runs it in the same folder where the file is located at when it does not work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice catch, thanks!!

@mrcasals
Copy link
Contributor

Apart from that comment, thank you very much for those PRs, @ahukkanen! Clear, to the point and easy to understand what's going on! As an ex-member of the Core team, I find this kind of PRs super helpful and easy for reviewers 😃 Thanks!

Copy link
Contributor

@tramuntanal tramuntanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @ahukkanen!

@tramuntanal tramuntanal merged commit ff38d6d into decidim:develop Nov 25, 2020
@ahukkanen ahukkanen deleted the fix/issues-with-action-logs branch November 25, 2020 11:46
ahukkanen added a commit to mainio/decidim that referenced this pull request Nov 25, 2020
* Fix broken dashboard action logs and add specs

* Avoid autoload conflicts with the admin log presenter tests

Before the autoloader could confuse the admin log presenters
with the normal presenters. This is an attempt to try to avoid
this issue.

* Clarify the admin log presenter shared example context name

* Fix invalid namespace with meetings admin log spec

* Change the namespacing convention in the specs

* Fix return type comment
tramuntanal pushed a commit that referenced this pull request Nov 25, 2020
)

* Fix broken dashboard action logs and add specs

* Avoid autoload conflicts with the admin log presenter tests

Before the autoloader could confuse the admin log presenters
with the normal presenters. This is an attempt to try to avoid
this issue.

* Clarify the admin log presenter shared example context name

* Fix invalid namespace with meetings admin log spec

* Change the namespacing convention in the specs

* Fix return type comment
entantoencuanto added a commit that referenced this pull request Dec 2, 2020
…ngs_content_block

* develop: (22 commits)
  Fix email CTA alignment on Outlook and Windows Mail (#6895)
  Fix mailer meeting registration invitation using path instead of URL (#6965)
  Fix the data portability exporter when zip is not in the gemfile (#6969)
  Convert technical docs to Antora (#6526)
  New Crowdin updates (#6957)
  Bugfix - moderated meetings are displayed in the meetings index page  (#6927)
  Add HTML Content Blocks in Process Groups  (#6823)
  Prevent error in view due to optional html not showing (#6942)
  Improve layout for standalone T&C page (#6944)
  chore: move rubocop ruby config to own file (#6952)
  Fix some strings (#6958)
  Fix newsletter html containing style tag content (#6876)
  New Crowdin updates (#6945)
  New Crowdin updates (#6926)
  Localize a string in conference speaker (#6866)
  Fix broken dashboard action logs under certain conditions (#6857)
  Fix traceability logs with invalid record (#6879)
  Allow user to drag address on proposal map (#6291)
  New Crowdin updates (#6898)
  Update release notes documentation (#6809)
  ...
entantoencuanto added a commit that referenced this pull request Dec 2, 2020
…_content_block

* develop: (22 commits)
  Fix email CTA alignment on Outlook and Windows Mail (#6895)
  Fix mailer meeting registration invitation using path instead of URL (#6965)
  Fix the data portability exporter when zip is not in the gemfile (#6969)
  Convert technical docs to Antora (#6526)
  New Crowdin updates (#6957)
  Bugfix - moderated meetings are displayed in the meetings index page  (#6927)
  Add HTML Content Blocks in Process Groups  (#6823)
  Prevent error in view due to optional html not showing (#6942)
  Improve layout for standalone T&C page (#6944)
  chore: move rubocop ruby config to own file (#6952)
  Fix some strings (#6958)
  Fix newsletter html containing style tag content (#6876)
  New Crowdin updates (#6945)
  New Crowdin updates (#6926)
  Localize a string in conference speaker (#6866)
  Fix broken dashboard action logs under certain conditions (#6857)
  Fix traceability logs with invalid record (#6879)
  Allow user to drag address on proposal map (#6291)
  New Crowdin updates (#6898)
  Update release notes documentation (#6809)
  ...
entantoencuanto added a commit that referenced this pull request Dec 2, 2020
…cipatory_processes_content_block

* develop: (22 commits)
  Fix email CTA alignment on Outlook and Windows Mail (#6895)
  Fix mailer meeting registration invitation using path instead of URL (#6965)
  Fix the data portability exporter when zip is not in the gemfile (#6969)
  Convert technical docs to Antora (#6526)
  New Crowdin updates (#6957)
  Bugfix - moderated meetings are displayed in the meetings index page  (#6927)
  Add HTML Content Blocks in Process Groups  (#6823)
  Prevent error in view due to optional html not showing (#6942)
  Improve layout for standalone T&C page (#6944)
  chore: move rubocop ruby config to own file (#6952)
  Fix some strings (#6958)
  Fix newsletter html containing style tag content (#6876)
  New Crowdin updates (#6945)
  New Crowdin updates (#6926)
  Localize a string in conference speaker (#6866)
  Fix broken dashboard action logs under certain conditions (#6857)
  Fix traceability logs with invalid record (#6879)
  Allow user to drag address on proposal map (#6291)
  New Crowdin updates (#6898)
  Update release notes documentation (#6809)
  ...
entantoencuanto added a commit that referenced this pull request Dec 2, 2020
…link

* develop: (22 commits)
  Fix email CTA alignment on Outlook and Windows Mail (#6895)
  Fix mailer meeting registration invitation using path instead of URL (#6965)
  Fix the data portability exporter when zip is not in the gemfile (#6969)
  Convert technical docs to Antora (#6526)
  New Crowdin updates (#6957)
  Bugfix - moderated meetings are displayed in the meetings index page  (#6927)
  Add HTML Content Blocks in Process Groups  (#6823)
  Prevent error in view due to optional html not showing (#6942)
  Improve layout for standalone T&C page (#6944)
  chore: move rubocop ruby config to own file (#6952)
  Fix some strings (#6958)
  Fix newsletter html containing style tag content (#6876)
  New Crowdin updates (#6945)
  New Crowdin updates (#6926)
  Localize a string in conference speaker (#6866)
  Fix broken dashboard action logs under certain conditions (#6857)
  Fix traceability logs with invalid record (#6879)
  Allow user to drag address on proposal map (#6291)
  New Crowdin updates (#6898)
  Update release notes documentation (#6809)
  ...
entantoencuanto added a commit that referenced this pull request Dec 2, 2020
…ighted_groups

* develop: (22 commits)
  Fix email CTA alignment on Outlook and Windows Mail (#6895)
  Fix mailer meeting registration invitation using path instead of URL (#6965)
  Fix the data portability exporter when zip is not in the gemfile (#6969)
  Convert technical docs to Antora (#6526)
  New Crowdin updates (#6957)
  Bugfix - moderated meetings are displayed in the meetings index page  (#6927)
  Add HTML Content Blocks in Process Groups  (#6823)
  Prevent error in view due to optional html not showing (#6942)
  Improve layout for standalone T&C page (#6944)
  chore: move rubocop ruby config to own file (#6952)
  Fix some strings (#6958)
  Fix newsletter html containing style tag content (#6876)
  New Crowdin updates (#6945)
  New Crowdin updates (#6926)
  Localize a string in conference speaker (#6866)
  Fix broken dashboard action logs under certain conditions (#6857)
  Fix traceability logs with invalid record (#6879)
  Allow user to drag address on proposal map (#6291)
  New Crowdin updates (#6898)
  Update release notes documentation (#6809)
  ...
entantoencuanto added a commit that referenced this pull request Dec 2, 2020
…s_and_processes_block

* develop: (22 commits)
  Fix email CTA alignment on Outlook and Windows Mail (#6895)
  Fix mailer meeting registration invitation using path instead of URL (#6965)
  Fix the data portability exporter when zip is not in the gemfile (#6969)
  Convert technical docs to Antora (#6526)
  New Crowdin updates (#6957)
  Bugfix - moderated meetings are displayed in the meetings index page  (#6927)
  Add HTML Content Blocks in Process Groups  (#6823)
  Prevent error in view due to optional html not showing (#6942)
  Improve layout for standalone T&C page (#6944)
  chore: move rubocop ruby config to own file (#6952)
  Fix some strings (#6958)
  Fix newsletter html containing style tag content (#6876)
  New Crowdin updates (#6945)
  New Crowdin updates (#6926)
  Localize a string in conference speaker (#6866)
  Fix broken dashboard action logs under certain conditions (#6857)
  Fix traceability logs with invalid record (#6879)
  Allow user to drag address on proposal map (#6291)
  New Crowdin updates (#6898)
  Update release notes documentation (#6809)
  ...
@mrcasals mrcasals added type: fix PRs that implement a fix for a bug module: admin labels Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: admin type: fix PRs that implement a fix for a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants