Skip to content

Clean up CAPTCHA controller logic and modules

Chad Woolley requested to merge clean-up-captcha-controller-logic into master

What does this MR do?

This is part of the effort to clean up CAPTCHA logic and make it simpler to understand, with less technical debt.

Specifically, it is Part 1 of "Plan C" for addressing the technical debt around issue creation.

Part 2 will be to rewrite and simplify the CAPTCHA HAML views.

For more context on how we got to this point, see the discussion on this thread: !66427 (comment 635143092)

Changes:

  • Cleans up CAPTCHA controller logic
  • Splits existing single SpammableActions module into three separate cohesive, loosely-coupled, and well-named new modules:
    • SpammableActions::CaptchaCheck::JsonFormatActionsSupport
    • SpammableActions::CaptchaCheck::HtmlFormatActionsSupport
    • SpammableActions::AkismetMarkAsSpamAction
  • Updates and adds test coverage for the new modules.
  • Moves responsibility for redirects out of shared modules and back into controllers.
  • For clarity, inlines responsibility for determining whether a given issueable should be spam checked into IssuableActions#update, including preserving existing inconsistent behavior with regards to redirects. Comments added to explain what is happening.
  • Renames MarkAsSpamService to AkismetMarkAsSpamService to make it clear that it is specific to Akismet.
  • Refactors and DRYs up other related areas of logic

Screenshots or Screencasts (strongly suggested)

Even though the changes to IssuableActions#update are not directly unit tested in spec/controllers/concerns/issuable_actions_spec.rb, the following code coverage screenshot shows they are covered by issues_controller_spec.rb and epics_controller_spec.rb:

Screen_Shot_2021-07-29_at_12.01.13_PM

The only logic path lacking coverage is the non-Spammable format.html render of :edit. However, I'm not even sure if anything in the app executes this code path, and in any case it's currently only a single simple line.

How to setup and validate locally (strongly suggested)

See the Testing Notes section of the CAPTCHA epic for details on how to setup and test spam checking and CAPTCHA in a local dev environment.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Exploratory Testing Performed

CAPTCHA behavior was explored in all of the following, with both cancel and solve of the CAPTCHA dialog:

  • issue creation (uses HTML form support, all others use JSON Apollo/Axios support)
  • issue update
  • project snippet creation
  • project snippet update
  • personal snippet creation
  • personal snippet update

The Akismet "mark as spam" / "mark as ham" functionality (https://docs.gitlab.com/ee/integration/akismet.html) was also explored and working successfully.

Checklist

-->

Edited by Chad Woolley

Merge request reports