Clean up CAPTCHA controller logic and modules
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 intoIssuableActions#update
, including preserving existing inconsistent behavior with regards to redirects. Comments added to explain what is happening. - Renames
MarkAsSpamService
toAkismetMarkAsSpamService
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
:
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
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
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
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
-->