From 6f5b3ad6cba4da53f8d7d2450d2d848007d0c89c Mon Sep 17 00:00:00 2001
From: Marcel van Remmerden <mvanremmerden@gitlab.com>
Date: Mon, 9 May 2022 07:40:49 +0000
Subject: [PATCH] Remove directly addressed references

First step to removing directly addressed as concept

Changelog: changed
EE: true
---
 app/controllers/dashboard/todos_controller.rb | 10 +++++++-
 app/helpers/todos_helper.rb                   |  6 ++---
 doc/user/todos.md                             | 23 ++++++++-----------
 .../dashboard/todos_controller_spec.rb        | 13 +++++++++++
 spec/features/dashboard/todos/todos_spec.rb   |  4 ++--
 5 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb
index 2c5e68174279..d3b737a5038c 100644
--- a/app/controllers/dashboard/todos_controller.rb
+++ b/app/controllers/dashboard/todos_controller.rb
@@ -98,6 +98,14 @@ def todos_page_count(todos)
   end
 
   def todo_params
-    params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id)
+    aliased_action_id(
+      params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id)
+    )
+  end
+
+  def aliased_action_id(original_params)
+    return original_params unless original_params[:action_id].to_i == ::Todo::MENTIONED
+
+    original_params.merge(action_id: [::Todo::MENTIONED, ::Todo::DIRECTLY_ADDRESSED])
   end
 end
diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb
index 60bf79f31140..d3cc922423d4 100644
--- a/app/helpers/todos_helper.rb
+++ b/app/helpers/todos_helper.rb
@@ -17,12 +17,11 @@ def todo_action_name(todo)
     case todo.action
     when Todo::ASSIGNED then todo.self_added? ? 'assigned' : 'assigned you'
     when Todo::REVIEW_REQUESTED then 'requested a review of'
-    when Todo::MENTIONED then "mentioned #{todo_action_subject(todo)} on"
+    when Todo::MENTIONED, Todo::DIRECTLY_ADDRESSED then "mentioned #{todo_action_subject(todo)} on"
     when Todo::BUILD_FAILED then 'The pipeline failed in'
     when Todo::MARKED then 'added a todo for'
     when Todo::APPROVAL_REQUIRED then "set #{todo_action_subject(todo)} as an approver for"
     when Todo::UNMERGEABLE then 'Could not merge'
-    when Todo::DIRECTLY_ADDRESSED then "directly addressed #{todo_action_subject(todo)} on"
     when Todo::MERGE_TRAIN_REMOVED then "Removed from Merge Train:"
     when Todo::ATTENTION_REQUESTED then 'requested your attention on'
     end
@@ -151,8 +150,7 @@ def todo_actions_options
       { id: Todo::REVIEW_REQUESTED, text: 'Review requested' },
       { id: Todo::MENTIONED, text: 'Mentioned' },
       { id: Todo::MARKED, text: 'Added' },
-      { id: Todo::BUILD_FAILED, text: 'Pipelines' },
-      { id: Todo::DIRECTLY_ADDRESSED, text: 'Directly addressed' }
+      { id: Todo::BUILD_FAILED, text: 'Pipelines' }
     ]
   end
 
diff --git a/doc/user/todos.md b/doc/user/todos.md
index 5cea619c830b..c261d719da08 100644
--- a/doc/user/todos.md
+++ b/doc/user/todos.md
@@ -84,28 +84,25 @@ You can manually add an item to your To-Do List.
 
    ![Adding a to-do item from the issuable sidebar](img/todos_add_todo_sidebar_v14_1.png)
 
-## Create a to-do item by directly addressing someone
+## Create a to-do item by mentioning someone
 
-You can create a to-do item by directly addressing someone at the start of a line.
-For example, in the following comment:
+You can create a to-do item by mentioning someone anywhere except for a code block. Mentioning a user many times in one message only creates one to-do item.
 
-```markdown
+For example, from the following comment, everyone except `frank` gets a to-do item created for them:
+
+````markdown
 @alice What do you think? cc: @bob
 
 - @carol can you please have a look?
 
 > @dan what do you think?
 
-@erin @frank thank you!
-```
-
-The people who receive to-do items are `@alice`, `@erin`, and
-`@frank`.
+Hey @erin, this is what they said:
 
-To view to-do items where a user was directly addressed, go to the To-Do List and
-from the **Action** filter, select **Directly addressed**.
-
-Mentioning a user many times only creates one to-do item.
+```
+Hi, please message @frank :incoming_envelope:
+```
+````
 
 ## Actions that mark a to-do item as done
 
diff --git a/spec/controllers/dashboard/todos_controller_spec.rb b/spec/controllers/dashboard/todos_controller_spec.rb
index abada97fb108..efa008771426 100644
--- a/spec/controllers/dashboard/todos_controller_spec.rb
+++ b/spec/controllers/dashboard/todos_controller_spec.rb
@@ -113,6 +113,19 @@
 
           expect(response).to redirect_to(dashboard_todos_path(page: last_page, project_id: project.id))
         end
+
+        it 'returns directly addressed if filtering by mentioned action_id' do
+          allow(controller).to receive(:current_user).and_return(user)
+
+          mentioned_todos = [
+            create(:todo, :directly_addressed, project: project, user: user, target: issues.first),
+            create(:todo, :mentioned, project: project, user: user, target: issues.first)
+          ]
+
+          get :index, params: { action_id: ::Todo::MENTIONED, project_id: project.id }
+
+          expect(assigns(:todos)).to match_array(mentioned_todos)
+        end
       end
     end
 
diff --git a/spec/features/dashboard/todos/todos_spec.rb b/spec/features/dashboard/todos/todos_spec.rb
index 68d979bb1cf5..04e78b59ab44 100644
--- a/spec/features/dashboard/todos/todos_spec.rb
+++ b/spec/features/dashboard/todos/todos_spec.rb
@@ -211,9 +211,9 @@
         visit dashboard_todos_path
       end
 
-      it 'shows you directly addressed yourself message' do
+      it 'shows you directly addressed yourself message being displayed as mentioned yourself' do
         page.within('.js-todos-all') do
-          expect(page).to have_content("You directly addressed yourself on issue #{issue.to_reference} \"Fix bug\" at #{project.namespace.owner_name} / #{project.name}")
+          expect(page).to have_content("You mentioned yourself on issue #{issue.to_reference} \"Fix bug\" at #{project.namespace.owner_name} / #{project.name}")
           expect(page).not_to have_content('to yourself')
         end
       end
-- 
GitLab